-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What the best way to use webhook for subscription ? #24
Comments
Hello @lwillems, I'm also using this library with the Sylius plugin to provide subscriptions on our shop.
<?php
declare(strict_types=1);
namespace App\PayumStripe\Action\StripeCheckoutSession\Api\WebhookEvent;
use FluxSE\PayumStripe\Wrapper\EventWrapperInterface;
use Payum\Core\Exception\RequestNotSupportedException;
use FluxSE\PayumStripe\Action\Api\WebhookEvent\AbstractWebhookEventAction;
use Stripe\Event;
final class InvoicePaymentSucceededWebhookEventAction extends AbstractWebhookEventAction
{
private foo $handler;
public function __construct(foo $handler)
{
$this->handler = $handler;
}
protected function getSupportedEventTypes(): array
{
return [
Event::INVOICE_PAYMENT_SUCCEEDED,
];
}
public function execute($request): void
{
RequestNotSupportedException::assertSupports($this, $request);
/** @var EventWrapperInterface $eventWrapper */
$eventWrapper = $request->getModel();
$event = $eventWrapper->getEvent();
$this->handler->handle($event);
}
} The service
Hope it helps you 😉 |
Hi @Prometee It was so helpful for my understanding of payum architecture. Regards, |
@lwillems Yes those events are triggered, to test them I made a 2 days cycle sub. You can store some info into the # ConvertSubscriptionAction.php (#1 of my previous comment)
$details->offsetSet('subscription_data', [
// ... other attributes like items etc
'metadata' => [
'my_metadata_id' => $something,
// 'token_hash' will be set automatically by this library, so you don't have to worry about
// it and this token hash won't be consumed and deleted after the first use because the
// notify unsafe which will receive it is not aware of it, only a notify safe is using a token
// and delete it after use.
],
]);
// dont forget to `setResult` after adding what you needed to the `$details` array
$request->setResult($details); About the billing reason, I have several checks like this into my use Stripe\Invoice as StripeInvoice;
if (
// skip the first created invoice
$stripeInvoice->billing_reason === StripeInvoice::BILLING_REASON_SUBSCRIPTION_CREATE
) {
return null;
} |
@Prometee Regards |
Yes, because the first order is already created by Sylius in my case, then each new Stripe invoices are synced to Sylius Order for accounting reasons (we are not using Stripe invoices for our accounting).
If you are using doctrine then Payum is triggering the update of the |
@Prometee : What is the most effective method for tracking all payments associated with subscriptions? The initial payment entries are created when a user subscribes, but how can we generate additional payment entries when the subscription is renewed? Is there a more efficient approach to handle this process? |
@oulfr if you use Checkout Session with You can handle subscriptions with very different maners, you can ask for a Stripe On my side, since my company is only selling software licences, I let Stripe handle all the cycles and sync the invoices to orders, payments into my shop. And I also manage the subscription from within the shop to pause, cancel, change the default payment etc. |
Thank you for your response. Do you have an example of how you have synced invoices with orders and payments in your shop? or what do you have implemented ? In my side I use Checkout Session to handle the subscription |
@oulfr unfortunately this part is on closed sources, I simply make some transformer services which create an order and a payment when the webhook event
to be able to cover all the differents flow happening during a Subscription life cycle. |
@Prometee: It's exactly what i planned to do, Thank you for your support |
Hi
Currently using stripe and this package (symfony bundle) to build as subscription on stripe :
According stripe documentation
Webhooks should be used to provision and renewal (checkout.session.completed and invoice.paid), invoice.paid is not implement but i can register an extra action.
I have implemented webhook with dedicated (unsafe) route provided, i am new to payum and i am a bit confused on how to hook my own logical.
As far as i understand, when webhook is received, payment is retrieved and detail is updated (stored in doctrine in my case), but i need to perform extra steps on my customer account (another entity linked to payment), such as update subscription date.
Thanks for your help
Regards
The text was updated successfully, but these errors were encountered: