I am using Braintree to charge customers for their subscriptions (annually). The customer enters his payment method using the Braintree dropin. The payment method is saved and used to pay for the service on a specific date.
Everything works fine until the customer enters another payment method. My backend uses the default payment method to pay for customers services. The problem is that you cannot change the default payment method using the Braintree dropin (setDefault parameter or similar does not exist, although it would be handy).
It has to be done using the backend SDK, where I can call "update" function on PaymentMethod object, like explained here. But that is not possible, because to update a payment method you need payment method token which is not available when changing the payment method using the dropin. With dropin only PaymentMethodNonce object is available, which according to documentation does not include payment method token. So it's basically impossible to set some payment method as default using the nonce information.
I'm looking for a way to enable the customer to change his default payment method using the Braintree dropin.
Related
I'm trying to update the payment method of a subscription. I collect the card information using Stripe's js (using a provided setup intent). Then I send the payment method id, provided by Stripe's js, to Laravel to actually update the User's default payment method.
Now, the problem is I want to prevent the User to insert duplicated cards, and the only way to prevent that would be to retrieve all the user current payment methods ($user->paymentMethods();), and check if any of those has the same fingerprint of the one I'm adding as default.
To get the fingerprint of the new payment method I'd need to get the Stripe PaymentMethod object for the id provided by the Stripe's js. The Cashier method to do that would be $user->findPaymentMethod(id).
The problem is that the payment id is not yet added to the User payments methods, so $user->findPaymentMethod($request->payment_method); fails because that payment method does not belong to $user.
The only solution I can think of would be to first add the new payment method, then check for duplicates and remove them ?
It seems like you’ve already found the best approach of adding the method to the user and then looking to see if there are any duplicated fingerprints, even if it is a little inconvenient.
Reviewing the Cashier documentation doesn’t show any obvious way to access the PaymentMethod before it’s attached to the user. It may be worth reaching out to the Laravel devs to see if there is functionality that would make this flow easier to accomplish.
I'm trying to figure out how to update the Stripe payment method associated with a subscription.
Is it fine if I simply update the default payment method of the user ?
I would use Stripe's JS to get the card information and make a payment method token with it, then update the default payment method server side. Would that be ok ?
Yep, that's correct - follow https://stripe.com/docs/payments/save-and-reuse to create and save a Payment Method to a Customer for future use. After which, pass the newly created Payment Method in invoice_settings.default_payment_method[0].
[0] https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method
I am looking to use PayPal to accept a payment through my website. I am looking at the Smart Payment button option. If the payment is successful I need to update something in my website DB. How can I determine whether the payment was successful or not? I cant see anything the API docs.
I also need to retain user context with a PHP session ID. How can I pass that to the paypal site and ensure it is returned with the success / fail indicator?
Use Paypal IPN to receive payment notifications. Setup a server endpoint to respond to IPN requests and update your DB etc...
To maintain state, you will need to include a hidden input filed in your Smart Payment Button with a name of custom and a value of your choice (session id).
Setup a IPN endpoint ie: /checkout/ipn, to receive Paypal notifications. Capture the session ID with $_POST['custom'];
I ended up using the Braintree API for this use case. Ther Brantree API returns a unique payment identifier (payment Nonce) which you can then validate by submitting a call back to the Braintree API to ensure the payment was actually received properly.
I'm trying to create a customer and subscription in the same workflow.
My logic requires that the email be unique so no two vaulted customers will have the same email.
My workflow is to only create a customer if the customer isn't found in the vault. The customer creation process includes the payment method. I need the paymentMethod token in order to create the subscription.
My hope was to not add duplicate paymentMethods so I'm using {failOnDuplicatePaymentMethod: true}. However, given a nonce and a customer, I can check if the customer is a dup, and I can check if the paymentMethod is a dup - but how do I get that exact paymentMethod token if the customer has N payment methods?
I assumed that the failOnDup would return the token of the dup Payment method - but that isn't the case.
What I'm trying to do is have a single subscription signup with email and payment but a customer can enter a different credit card for each subscription. I want the customer to have a single vaulted account, with N payment methods but I need the paymentMethod token of the last paymentMethod in order to create the subscription.
Full disclosure: I work as a developer for Braintree
Braintree does not support a way to retrieve the duplicate payment method after a payment method fails to create because a duplicate payment method exists.
You can retrieve the payment methods from an existing customer and present them via our Drop-in or your own custom integration. I recommend reaching out to Braintree support to help you with your integration and figure out all of your options.
I am trying to use braintree for payments in a web application. The flow i'm after is :
user registration : create a Braintree customer, associate its id with the user
first payment : show a custom UI for the credit card information, use the Braintree tutorial for adding a credit card and make the payment.
second payment : show a list of payment methods for the customer. When he/she selects one, make a payment using the selected payment method.
I am stumped at how i'm supposed to implement the second payment part. Assuming i keep payment methods info and show the client a list of payment methods, how do i obtain a payment method nonce i need to be able to execute a sale Transaction?
To clarify, i'm not using the Dropin UI because :
i need more information than it can show when entering a credit card (like cardholder)
i need to have a custom look-and-feel ui in different languages
I've read the Braintree guides and reference and i couldn't find and resource for a custom ui where i can reuse the payment method information.
Any input is highly appreciated.
I work at Braintree. If you need more help, I suggest you email our support team.
When you store a credit card (by passing a nonce to credit card or payment method create) the response you get back contains a token. You can store this token permanently and use it in the future to make payments on the same card.
You can charge the user with his payment token or customer id: https://developers.braintreepayments.com/guides/transactions/ruby#sale-with-vaulted-payment-methods
result = Braintree::Transaction.sale(
:payment_method_token => "the_token",
:amount => "10.00"
)
# or
result = Braintree::Transaction.sale(
:customer_id => "the_customer_id",
:amount => "10.00"
)