Stripe webhook for laravel - laravel

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?

Related

PayPal REST API not returning recurring payment information in laraval

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

Laravel events no response body returnd to Stripe

After successful purchase is made on my website, stripe fires a webhook to finalize the transaction.
What is happening is I am firing 2 laravel events:
Send email confirmation of order to the customer
Send email notification to admin of site alerting them to the purchase.
If I just fire the event to send email confirmation to customer, the stripe webhook is successful.
When I add the notification to admin, Stripe advises that the HTTP Status Code has timed out that there was no response body and the web hook fails, even though all the emails were sent correctly. And what will happen is stripe will attempt to refire the webhook which is not what I want.
Has anyone experienced this issue?
#DelenaMalan is correct, once you receive a Stripe webhook event you should immediately acknowledge receipt by returning a 200 response and then handle your business logic like sending emails afterwards. See https://stripe.com/docs/webhooks/build#return-a-2xx-status-code-quickly

How to send laravel notification to a custom email

I have a laravel application,
I send notifications to a user when he registers. I use the notify() on the model. But I have an issue, How do i send a notification to a custom email address? the same notification.
Here's what i have:
`$admin = Admin::find(1);
$admin->email = 'admin#site.com';
$admin->notify((new NewUserRegistered($user))->delay($when));
$user->notify((new UserRegistered($user))->delay($when));`
i get a user model instance, and customize the email to input the custom email... However, the email sends to the original mail on the model and ignores the edit.
How do i do this please?
Here the code snippet you can use for sending the notification directly to an email address without creating the User or without having the User in the database.
Notification::route('mail', 'me#abdulrehman.pk')->notify(new InvoicePaid($invoice));
As a work around, you can save the model before sending the message
$admin->email = 'admin#site.com';
$admin->save();
after that you can retrieve the email as it was

Regarding uable to trigger Paypal REST API webhook events from developer sandbox

What is wrong with my Paypal sandbox account process
to receive webhook notifications? We are unable to receive webhook event on
my URL.
URL working with "Webhooks simulator". Please let me know what
should I do for receive webhook event on above URL.
Webhooks simulator sends sample payloads for the events you configured. It does not send a notification on triggering of an actual event.
If you are getting notification via Webhooks Simulator, it means the URL configured by you is able to intercept POST requests.
Now for the "Paypal sandbox account unable to process to receive Webhook notifications" part, please check if the transaction is actually created at https://developer.paypal.com/developer/dashboard/sandbox/ . If the transaction you are looking for is not present there, there won't be any notification generated. In case transaction is present there and still you are not getting any notifications, please share debug id.
Here is a silly thing that I overlooked in the documentation and only found out after contacting support.
After you've followed the approval url and gave your approval, dit you execute the payment with the REST API?
https://developer.paypal.com/docs/api/payments/#payment_execute
Webhooks are only called after you've executed the payment.
The confusing part is; there is no webhook being called, when a user approves or cancels a payment. There is only a redirect back to a return url or cancel url. So you either need to monitor the redirect back to your site and trigger the execute call then, or find another way (like polling the payment) to see the status change before calling the execute call.

Laravel Cashier - How to Check if Stripe Payment was Successful

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

Resources