Double customer entry in braintree vault issue - php

After completing transaction, there are two customer entry under vault.
Step I have followed:
1. Created customer.
//first customer vault entry is created at this point
$customerParams = Braintree_Customer::create(array(
'firstName' => $firstName,
'lastName' => $lastName,
));
2.Then generated clientToken
Braintree_ClientToken::generate(array(
"customerId" => $customerParams->customer->id
));
3.Then with help of api generated nonce in js successfully:
var client = new braintree.api.Client({clientToken: ctoken});
client.tokenizeCard({
...
...
});
4.Again at this point new customer is created
Braintree_Transaction::sale(array(
'amount' => $mapCidInvoiceID['amount'],
'orderId' => $redirectParams['invoiceID'],
'paymentMethodNonce' => $nonce,
'options' => array(
'storeInVaultOnSuccess' => true,
),
));
is there something wrong in my code? why for one transaction two customer record are created? For first record first and last name are recorded. But second case no such detail are stored.
First creation of customer is required for second and third step.

Full disclosure: I work at Braintree.
Your code is creating two separate customers because when you call Transaction::sale it does not have the customer from your Customer::create call tied to it, and you have the option set to store the payment method in the vault upon success. This creates a customer when saving the payment method from the transaction, because a payment method must be tied to a customer. To resolve your problem, pass the customer id returned from Customer::create as a customerId param when you call Transaction::sale.
Braintree_Transaction::sale(array(
'amount' => $mapCidInvoiceID['amount'],
'orderId' => $redirectParams['invoiceID'],
'customerId' => $customerParams->customer->id
'paymentMethodNonce' => $nonce,
'options' => array(
'storeInVaultOnSuccess' => true,
),
));

Related

Stripe Create Invoice and auto charge

I am creating an invoice and auto charging a customer via their PHP package. The issue is though the invoice is created but the card on file is not charged, it says fail. This is odd to me because if I go into the dashboard online, find the invoice the is listed as "failed" and manually click the "retry charge" it works. Why would this be? Its clearly creating the invoice correctly and trying to charge the card on file but the card seems to only clear on ALL of these invoices if I go in and manually retry the charge.
$stripe = new \Stripe\StripeClient(config('XXXXXXXXXXXXXXXXX'));
$item = $stripe->invoiceItems->create([
'customer' => $subscription->stripe_customer,
'amount' => $total,
'currency' => 'usd',
'description' => 'Erro Coffee Subscription ' . $subscription_type->bags
]);
$invoice = $stripe->invoices->create([
'customer' => $subscription->stripe_customer,
'collection_method' => 'charge_automatically',
'auto_advance' => true,
"metadata" => [
"order_type" => "subscription",
"subscription_refill" => "true",
"subscription_id" => $subscription->id
]
]);

Laravel Stripe MultiPlan Subscription

I want to add Add On to my subscription. Thus i follow this MultiPlan in Laravel doc. For every new subscription, new stripe product are create (means every plan have different product. including the addon). User need to subscribe to any subscription before subscript to the addon. There are no error, but the Subscription DB from stripe for the current subscription will return null quantity and null stripe_plan. Then create error from that database as i cant call the current subscription. Why does the stripe does that? or am I surpose to create new plans under the same product id in Stripe?
My code to create stripe product and plan
$stripe = new StripeClient(env('STRIPE_SECRET'));
$product_stripe = $stripe->products->create([
'name' => $request->service_name,
]);
$plan_stripe = $stripe->plans->create([
// 'id' => $stripe_plan,
'nickname' => $request->service_name,
'product' => $product_stripe['id'],
'amount' => $request->price*100,
'currency' => 'usd',
'interval' => $request->period,
'interval_count' => $request->period_num,
]);
This is my code to subscribe to addon
$user = auth()->user();
$user->subscription('default')->addPlanAndInvoice('plan_stripe_id', 'quantity');
Note that default is the user current subscription.

mindbody-php-api for stored credit card payment?

I am using mindbody api for payment, when I add my credit card detail then payment is successful but when I am using stored(existing) card for payment then it's given error :
Card Authorization Failed mb.Core.BLL.Transaction failed validation Could not determine the type of credit card.
my code is:
$shoppingCart = array(
'ClientID' => $client_id,
'Test' => false,
'InStore' => true, //add by NIK
'CartItems' => array(
'CartItem' => array(
'Quantity' => $product_qty,
'Item' => new SoapVar(
array('ID' => $product_id), SOAP_ENC_ARRAY, 'Service', 'http://clients.mindbodyonline.com/api/0_5'
),
'DiscountAmount' => 0
)
),
'Payments' => array(
'PaymentInfo' => new SoapVar(
array(
'LastFour'=>$clientCreditCard->LastFour,
'Amount'=>round($OnlinePrice, 2),
),
SOAP_ENC_ARRAY,
'StoredCardInfo',
'http://clients.mindbodyonline.com/api/0_5'
),
)
);
please give any solution for it, what should I do or send extra parameter.
thanks!
Shouldn't it look more like this?
'Payments' => array(
'PaymentInfo' => new SoapVar(
array(
'CreditCardNumber'=>'4111111111111111',
'ExpYear'=>'2015',
'ExpMonth'=>'06',
'Amount'=>'130',
'BillingAddress'=>'123 Happy Ln',
'BillingPostalCode'=>'93405'
),
SOAP_ENC_ARRAY,
'CreditCardInfo',
'http://clients.mindbodyonline.com/api/0_5'
)
Taken from this README.md https://github.com/devincrossman/mindbody-php-api
Your shopping cart array with saved card is correctly constructed.
I've been struggling with exactly the same problem for the last few days, and I found that the error in my case was that the front end account page was passing the credit card number with spaces in the string - the front end form was automatically adding the spaces for the usual format/usability reasons in the admin part of the application where the saved card details are entered.
I solved it by stripping out the spaces in PHP : str_replace(" ", "", $_POST['cardnumber']) in the card save function.
Once I did that the saved card payment process worked fine.

Assign metadata to invoice in Stripe subscriptions

here is my code to create a subscription:
$subscription = \Stripe\Subscription::create(array(
"customer" => $customer->id, //customer id from previous lines after creating customer
"plan" => 'premium-plan',
'metadata' => ['user_id' => $userId]
));
here is my code to update plans:
$subscriptionUpdate = \Stripe\Subscription::retrieve($subscriptionIdFromDatabase);
$subscriptionUpdate->plan = 'best-premium-plan';
$subscriptionUpdate->save();
How can I add metadata to an invoice if the user wants to update plans?
if the user wants to update their plan using the second block of code, it will generate an invoice. how can i assign metadata to that invoice when user changes plans?
Perform an update on the invoice.
Invoice::update($invoiceId, ['metadata' => [
'my_data' => $someVar
]]);
https://stripe.com/docs/api/metadata

How to set Currency Format in braintree transaction sale

I create a APP in which i use Braintree Payment Gateway. In my application i make options to set different currency, am just know that how to set currency when i set sale transaction param.
here is my code
$result = Braintree\Transaction::sale([
'amount' => '50.00',
'creditCard' => array(
'cardholderName' => 'Test Name',
'number' => '4000111111111511',
'expirationDate' => '12/2018',
'cvv' => '123',
),
'options' => [ 'submitForSettlement' => true]
]);
All of my transaction made in US Dollar, but i want to make transaction in different currencies.
Please someone give me the solution.
thanks
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
You will need to set up a different merchant account for each currency you would like to process. Then, when processing a transaction for a specific currency, you can pass in the merchant account id to the transaction sale method.
In addition, to keep your PCI compliance burden low, you will want to pass a nonce to your server in place of the credit card details.
$merchantAccountId = someFunctionToLookupCorrectMerchantIdBasedOnCurrency();
$result = Braintree\Transaction::sale([
'amount' => '100.00',
'paymentMethodNonce' => nonceFromTheClient,
'merchantAccountId' => $merchantAccountId,
'options' => [
'submitForSettlement' => True
]
]);

Categories