How do I know when a debit card is used for payment with Square Connect API? - square-connect

The Square Connect API has the following payment types:
public enum TypeEnum
{
CREDITCARD = 0,
CASH = 1,
THIRDPARTYCARD = 2,
NOSALE = 3,
SQUAREWALLET = 4,
SQUAREGIFTCARD = 5,
UNKNOWN = 6,
OTHER = 7
}
According to their website they now support debit cards (at least in Canada). So I am wondering what payment type is returned if a debug card (Interac) is used for payment?

At this time, there is no way to know whether or not a card is a Debit or Credit card via Square's APIs.

As of now, in the V1 api, it shows up as type Credit Card, with a CardBrand of INTERAC. Unfortunately the .Net api is broken, as it does not include INTERAC in the CardBrand enum, so you won't be able to use it. I submitted a patch to Square over a month ago, but they haven't accepted it.

Related

How to find the user with priority in laravel

I have a user table in laravel app.
I want to find a random user with the lowest number of loan_limit.
Right now I have this.
$random_user = User::inRandomOrder()
->where('loan_limit', '<=', 5)
->first();
But I want to find a random user with the minimum no. Of loan_limit like if a user has a loan_limit of 0, that user will get picked first, and if a user has 1, that user will be selected next, and finally if a user has a limit of 5, then that user will have less probability of getting picked.
you can get all the users with min loan_limit value, then take random one:
$random_user = User::whereRaw('loan_limit= (select min(`loan_limit`) from users)')
->get()->random();

Fetch first charge of a customer in stripe

I am reading stripe documentation and I want to fetch the first charge of the a customer. Currently I am doing
charge_list = Stripe::Charge.list(
{
customer: "cus_xxx"
},
"sk_test_xxxxxx"
)
first_charge = charge_list.data.last
Since stripe api returns the charges list in sorted order with the most recent charges appearing first. But I don't think it is a good approach. Can anyone help me with how can I fetch the first charge by a customer or how can I sort the list with descending order of created date so that I could get the first object from the array.
It seems there is no reverse order sorting feature in stripe API.
Also remember the first charge may not be on the first page result set, so you have to iterate using #auto_paging_each.
A quick possible solution:
charge_list = Stripe::Charge.list(
{customer: "cus_xxx", limit: 100 }, # limit 100 to reduce request
"sk_test_xxxxxx")
first_charge = nil
charge_list.auto_paging_each {|c| first_charge = c }
You may want to persist the result somewhere since it is a heavy operation.
But the cleanest solution IMO would be to store all charge records into your DB and make subsequent queries against it.

Laravel cashier + Stripe : creating a plan with quantity and decreasing prices

I'm whiling for one of my project to create a subscription system with Laravel Cashier and Stripe.
We will offer one plan to our users : 10€ / month for one location (they can add locations in the system) and for 75 followers.
What I want to do, is to make them pay more for locations : 2.5€ / locations / month for example, so this can be achieve with quantities ? But still, if the basic plan is at 10€ and I put 2 as a quantity, total price will be 20€ ?
Then price will be also based on their followers. 75 are included in the basic price. But then if they want more, they will also have to pay.
Example :
76-150 : + 4.95€ a month
151-250 : + 4.80€ a month etc ...
How can I handle that and make sure the customer will have to pay everything in one shot ?
Thanks in advance !
My advice would be to;
Calculate the total charge in your own logic,
Initiate a 'once-off' payment by first creating a customer object,
Then creating a charge!
Easy as 1,2,3 :D
Here's a tutorial from Stripes documentation on creating payments.
https://stripe.com/docs/charges
If you would like to add the user to a plan (subscription), see the below example (in PHP).
$customer = \Stripe\Customer::create(array(
"source" => $tokenID,
"plan" => $plan,
"email" => $email,
"coupon" => $coupon
));
I would use my front or back end to calculate:
price
discount rate
When the calculation is done, you can create your subscription with the right quantity and price, and discount rate (discount coupon).
$user->newSubscription('main', 'main')
->quantity($quantity)
->withCoupon($coupon)
->create($token, ['email' => $user->email]);

Union grouping in bipartite graphs?

I'm trying to figure out a good (and fast) solution to the following problem:
I have two models I'm working with, let's call them players and teams. A player can be on multiple teams and a team can have multiple players). I'm working on creating a UI element on a form that allows a user to select multiple teams (checkboxes). As the user is selecting (or deselecting) teams, I'd like to display the teams grouped by the players.
So for examples:
If the selected teams have no players that intersect, each team would have its own section.
If the user selects two teams and they have the same players, there would be one section containing the names of the two teams and all the players.
If TEAM_A has players [1, 2, 4, 5] and TEAM_B has players [1, 3, 5, 6]. There would be the following sections: SECTION_X = [TEAM_A, TEAM_B, 1, 5], SECTION_Y = [TEAM_A, 2, 3], SECTION _Z = [TEAM_B, 3, 5]
I hope that's clear. Essentially, I want to find the teams that players have in common and group by that. I was thinking maybe there is a way to do this by navigating a bipartite graph? Not exactly sure how though and I might be overthinking it. I was hoping to do this by creating some type of data structure on the server and using it on the client. I would love to hear your suggestions and I appreciate any help you can give!
One solution is to have each player wrapper track the selected teams that it is on
class PlayerWrapper {
Player player;
TeamList teamList;
}
class TeamList {
private List<Team> teams;
int hashValue = // hash value derived from teams list
void add(Team team) {
teams.add(team);
hashValue = // update hash value
}
}
Then maintain a hash table of player sets, and a hash table of player wrappers
HashTable<TeamList, Set<Player>> playerSets
HashTable<Player, PlayerWrapper> playerWrappers
When the user selects a new team, iterate through the team's players and retrieve the player wrappers from playerWrappers. For each player wrapper, retrieve the Set<Player> from playerSets and remove the player from the set, then add the new team to the wrappers TeamList, retrieve the Set<Player> from playerSets and add the player to the set.
void updatePlayer(Team team, Player player) {
PlayerWrapper wrapper = playerWrappers.get(player);
Set<Player> set = playerSets.get(wrapper.teamList);
set.remove(player);
wrapper.teamList.add(team);
set = playerSets.get(wrapper.teamList);
set.add(player);
}
Assuming you're using hash sets for Set<Player> this should on average require constant time to process a team's player. Deselecting a team will function the same way, except that you'll remove the team from wrapper.teamList instead of adding it, and you'll have a linear time search through the TeamList to locate and remove the team. The use of a List in TeamList assumes that the UI will prevent duplicate teams; be careful using a Set instead, because it may be more difficult to ensure that two wrappers' TeamLists will have the same hashValue (i.e. you may need to take steps to ensure that both wrappers' TeamLists return their teams in the same order - something like a java LinkedHashSet would do the trick)

Best way to integrate values into enum (dictionary), then calculating based on user selection in form

Any guidance or pointing me to an example would be much appreciated (I can't formulate a good search term on the Googleplex).
I have a model using enums that i define in a dictionary and then render on the view with #Html.RadioButtonFor, etc.
Here is an example of my model:
public PaymentPlanList PaymentPlan { get; set; }
public enum PaymentPlanList
{
PaymentPlan_One,
PaymentPlan_Two,
}
public class PaymentPlanDictionary
{
public static readonly Dictionary<PaymentPlanList, string> paymentplanDictionary = new Dictionary<PaymentPlanList, string>
{
{ PaymentPlanList.PaymentPlan_One, "One full payment in advance (receive the lowest price)." },
{ PaymentPlanList.PaymentPlan_Two, "Two payments: first payment of 50% due up front, the balance of 50% due within 30 days (increases fee by $100)." },
};
static string ConvertPaymentPlan(PaymentPlanList paymentplanlist)
{
string name;
return (paymentplanDictionary.TryGetValue(paymentplanlist, out name))
? name : paymentplanlist.ToString();
}
static void Main()
{
Console.WriteLine(ConvertPaymentPlan(PaymentPlanList.PaymentPlan_One));
Console.WriteLine(ConvertPaymentPlan(PaymentPlanList.PaymentPlan_Two));
}
}
And, for completeness, this is my view related to the above:
<p>
#Html.RadioButtonFor(m => m.PaymentPlan, "PaymentPlan_One")
One full payment in advance (receive the lowest price).
</p>
<p>
#Html.RadioButtonFor(m => m.PaymentPlan, "PaymentPlan_Two")
Two payments: first payment 50% due up front, the balance of 50% due within 30 days (increases fee by $100).
</p>
This is a quote system I have users fill out. For this particular service, say I charge $1,000.00. This is the base price. Based on user input, this price will be changed, and I want to show that to the user. So, if the user selects the first option, the price remains unchanged. If the user selects the second option, the fee is increased by $100.00.
This changes exponentially, since there are more inputs that affect the price (if selected).
Ultimately, based on the user inputs, I need to calculate the total. I am rendering a view which will display the total. I was thinking of using some #{} blocks and if/else if statements to either a) show nothing if what was selected does not increase the total, or b) showing the additional amount (e.g., $100.00), and then later showing a total.
Something like (EDITING here for clarity):
Base service: $1,000.00
Addon service1: $100.00 (only if user selects "PaymentPlan_Two" for two payments of 50% each (from the PaymentPlanList enum), otherwise hidden (and no addition of the $100.00) if user selects "PaymentPan_One" and pays in full)
Addon service2: $0.00 (this is hidden and a $0.00 or no value since the user did not select anything from a separate enum, but the value of $100.00 would be added if selected, which would make the Total $1,200.00 if it were selected; ALTERNATIVELY, how could I handle if there were 3 or more items in the list? E.g., Choice_One is $0.00, Choice_Two is $100.00 and Choice_Three is $200.00)
TOTAL: $1,100.00
Thanks for any help.
let's see if I understand your requirements correctly:
The application needs to add prices to a base price, depending on
selection of Addon services.
These selections are from a Dictionary, which is based on an Enum
Therefore we're looking to store the price against the Enum to keep the data associations in one place.
It is possible to store a single value against an Enum:
public enum PaymentPlanList
{
PaymentPlan_One = 100,
PaymentPlan_Two = 200,
}
However, I don't think this would be flexible enough for our needs - Enums only allow integers, and are commonly used this way in bitwise operations (where the values are multiples of 2).
I think a better solution here might be to use a Model-View-View-Model (MVVM) which can contain the logic about which services are available, how much they cost, and which services are valid in combination with other services.
There's an ticket pricing example (which sounds similar in concept to the domain here) on the Knockout.js home page that re-calculates a travel ticket price on the client web-page based on a user selection.

Resources