I am using Cashier in Laravel 5.1 for stripe payment. I want to check how to create a new database entry only when the stripe payment is successful. I am doing something like this:
if ($user->subscribed())
{
$subscribe = $user->subscription()->increment($totalQuantity);
}
else {
$subscribe = $user->subscription('monthly')->quantity($totalQuantity)->create($postData['token']);
}
if($subscribe) {
// Insert into Database
}
I thought the stripe subscription will return true or false so I can check if the last payment was successful and proceed. But the $subscribe is empty.
How can I check if the last stripe payment was successful before I proceed with the DB insert queries? I have read the docs and it only mentioned about checking the overall subscription like using
`if ($user->subscribed())`
but it doesn't mention about how to check if the last stripe subscription charge was successful. How will I do that?
You can refer to the Stripe Charge object's return values. If paid = "true" then the charge is successful.
See this link: https://stripe.com/docs/api#charge_object
You'll probably want to look at the "handling failed subscriptions" and "handling other webhooks" sections. http://laravel.com/docs/5.0/billing#handling-failed-subscriptions
Webhooks are where a 3rd party does a callback to a URL for your application. For example, with stripe someone has just subscribed and made the payment, stripe will then visit a URL of your application with various information about whether that payment was decline, successful, etc. See https://stripe.com/docs/webhooks
You can register the route to your application in your stripe dashboard under Your Account > Account Settings > Webhooks > Add New Endpoint
Related
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?
I am working on Paypal webhook (subscription) section to insert recurring payment information into the database. I have done coding based on the link "https://jslim.net/blog/2018/01/22/PayPal-Rest-API-with-Laravel-5-and-Angular/" but Paypal webhook always return “payment_status: Pending” on sandbox image and its not inserting recurring payment information into the database (insert option added in PayPalController - function webhooksPaymentSaleCompleted ).
I think the problems related with routes/api.php file but I can't figure out what exactly is going wrong.
Another URL that I have referred and tried was "https://github.com/supermavster/PayPal-PHP-SDK"
Laravel version 5.8
paypal/rest-api-sdk-php: "^1.14"
Please suggest a feasible solution to this problem.
Thanks in advance.
Verify that the sandbox account's email is confirmed, by logging into the sandbox business account receiving the payment and navigating to: https://www.sandbox.paypal.com/businessprofile/settings/email
Resend the confirmation message. Open the message via https://developer.paypal.com/developer/notifications/ , and confirm the sandbox email.
The v1 PayPal-PHP-SDK is deprecated and there is no reason to be using it for a new integration. Use the v2 Checkout-PHP-SDK for payments.
You'll need two routes on your server, one for 'Set Up Transaction' and one for 'Capture Transaction', documented here; https://developer.paypal.com/docs/checkout/reference/server-integration/
The best approval flow to pair it with is https://developer.paypal.com/demo/checkout/#/pattern/server
Please ask if you don't understand anything....I am creating stripe subscription payment. i need to handle stripe customer.subscription.deleted event. i have created a webhook for it in my laravel app. but the thing is whenever i send test data from stripe it shows webhook handled. but i am sending email whenever payment is unsuccessful and also logging this it is not showing in log or sending email. I am hosting my website for now using ngrok.. which is build in in laragon.
My controller method
use Laravel\Cashier\Http\Controllers\WebhookController;
class SubscriptionController extends WebhookController
{
public function handleCustomerSubscriptionDeleted($payload){
\Log::info("Webhook is working");
dd($payload);
}
}
my route file is like this
Route::get('/stripe/webhook','SubscriptionController#handleWebhook');
it is not showing in log file this neither it is sending email.
i am following this article please check if it is right way to do this??
Click here
I have added dd() here how does this webhook will be successful?
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.
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.