laravel-paypal icon indicating copy to clipboard operation
laravel-paypal copied to clipboard

Add custom id for invoice id

Open buzzclue opened this issue 1 year ago • 3 comments

Allow to add custom id for invoice id.

buzzclue avatar Dec 19 '23 22:12 buzzclue

Can you specify why we need to add it? Any example you can share?

srmklive avatar Dec 20 '23 18:12 srmklive

You can set any custom data like Invoice ID, Transaction ID so you can tract the resource on webhook.

For example:

$invoice = Invoice::create([...]);
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
            ->addPlanTrialPricing('DAY', 7)
            ->addWeeklyPlan('Demo Plan', 'Demo Plan', 30)
            ->addCustomId($invoice->id)
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
            ->setupSubscription('John Doe', '[email protected]', '2021-12-10');

Now on webhook i can track this custom_id and process the invoice.

One can even pass the http_build_query query data in custom_id. This way you don't even have to add temporary records in database and process everything on webhooks

$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
            ->addPlanTrialPricing('DAY', 7)
            ->addWeeklyPlan('Demo Plan', 'Demo Plan', 30)
            ->addCustomId(http_build_query(['user' => $user->id, 'plan' => $plan->id, ... 'something_else' => 'other data']))
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
            ->setupSubscription('John Doe', '[email protected]', '2021-12-10');

buzzclue avatar Dec 20 '23 22:12 buzzclue

For some reasons the WH verification fails when $request->all() is sent in webhook_event. I have tested the verification successfully with json_decode($request->getContent())

If you want to test you can try the webhook PAYMENT.SALE.COMPLETED

buzzclue avatar Dec 22 '23 22:12 buzzclue