How to handle a error inside webhook after checkout payment - laravel

I am using Stripe Checkout(Payment intent) method in my Laravel site to get the payment from the customers and then add order to the database using webhook. What if I have an error inside the webhook while inserting to a database or any error like soldout, in this case, the customer will pay but the order will not be added to the database, how to refund to the customer if the order not completed?
How to handle this situation?

Related

Facing issue with stripe failed payment webhook

I managing the failed payment webhook in my website but I am facing issue that invoice.payment_failed gets received before invoice.created which creating issue. Because on failed payment the system is updating the status of invoice but the invoice havnt been created becasue the invoice.created havent been called. I dont know what am I missing. I am using laravel ans spark for stripe management
Given the order of delivery for webhook events is not guaranteed, you have a couple options.
Create the record of the invoice in your system a soon as you receive a webhook notification for any new invoice ID.
When you receive a webhook notification, add it to a queue for processing, and process the queue in priority order where invoice.created events are processed first. You'll likely want to build in some sort of delay.

Laravel Cashier (Stripe) subscribing using the existing customer with token

I am developing a Laravel application that involves subscription payment. Now I am struggling with subscribing the user with token but using the existing customer. This is the scenario. In my application, user can update their payment/ billing information (basically card). When they update the payment info, they are just adding the card information. Then later, user can make payment or subscribe to whatever they want.
First user will add they payment method or card information. So I create the customer like this.
$user->createAsStripeCustomer($token, array_merge($options, [
'email' => 'email address',
]));
So the above method will create the stripe customer for the user along with the card. Then tomorrow, user might want to subscribe to a channel. Laravel Cashier provide the following method to subscribe.
$user->newSubscription('subscription-name', 'my-plan')->create($token);
Then issue with the above code is that, I have to pass the token again. If I have to pass the token, again, I will have to generate the token again in the Javascript. If I have to generate the token again in the javascript, I will have to ask the user to enter the card information again to get token. So what can I do to get user to subscribe using the existing customer info? How can I do that?
One method is whenever you create a stripe customer, add the user to a free subscription plan so that he doesn't have to pay anything until he subscribes. When the user starts subscription we can simply change the subscription plan to the desired plan using the following method:
$user->subscription('main')
->skipTrial()
->swap('provider-plan-id');
Another method is whenever we create a stripe customer, ask the user to select a subscription plan and put him on the trial period until he subscribes.

Validate whether payment was a success or failure

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.

Find braintree payment method token when failOnDup for paymentMethod.create is called

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.

magento create order after successful payment from ccavenue

I have implemented cc-avenue payment gateway in my magento store.
right now when i select ccavenue payment method while checkout it redirects to ccavenue but in backend magento create a order.
i want to create a order after successfull payment of ccavenue.
can anyone help me for this.
In magento you have to create a order before redirecting it to payment gateway. Because every payment gateway including ccavenue needs order id and few parameters related to order. What you can do is , You should stop the mail on order creation.
There is an event
sales_order_place_after
Override it and stop sending mail when you get response from your payment getway check what is coming success or failure according to that send a proper email.

Resources