Skip to content
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

Add custom id for invoice id #603

Merged
merged 4 commits into from
Feb 19, 2024
Merged

Add custom id for invoice id #603

merged 4 commits into from
Feb 19, 2024

Conversation

buzzclue
Copy link
Contributor

Allow to add custom id for invoice id.

@srmklive
Copy link
Owner

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

@buzzclue
Copy link
Contributor Author

buzzclue commented Dec 20, 2023

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');

Some webhook verification fails with $request->all();

You can test "PAYMENT.SALE.COMPLETED"

`request->all {"id":"WH-0UX959158W078642N-2MW5123584490731L","event_version":"1.0","create_time":"2023-12-22T21:32:24.574Z","resource_type":"sale","event_type":"PAYMENT.SALE.COMPLETED","summary":"Payment completed for $ 3.67 USD","resource":{"amount":{"total":"3.67","currency":"USD","details":{"subtotal":"3.67"}},"payment_mode":"INSTANT_TRANSFER","create_time":"2023-12-22T21:32:18Z","custom":"id=3QWVF5ZswM&user=1&plan=2&interval=monthly&renew=10.4895&amount=3.671325&currency=USD&taxes=3%2C1&coupon=1","transaction_fee":{"currency":"USD","value":"0.62"},"billing_agreement_id":"I-MKX0RAHUCACW","update_time":"2023-12-22T21:32:18Z","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","protection_eligibility":"ELIGIBLE","links":[{"method":"GET","rel":"self","href":"https://api.sandbox.paypal.com/v1/payments/sale/1SK68449YM493670F"},{"method":"POST","rel":"refund","href":"https://api.sandbox.paypal.com/v1/payments/sale/1SK68449YM493670F/refund"}],"id":"1SK68449YM493670F","state":"completed","invoice_number":null},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0UX959158W078642N-2MW5123584490731L","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0UX959158W078642N-2MW5123584490731L/resend","rel":"resend","method":"POST"}]}
payload {"stdClass":{"id":"WH-0UX959158W078642N-2MW5123584490731L","event_version":"1.0","create_time":"2023-12-22T21:32:24.574Z","resource_type":"sale","event_type":"PAYMENT.SALE.COMPLETED","summary":"Payment completed for $ 3.67 USD","resource":{"amount":{"total":"3.67","currency":"USD","details":{"subtotal":"3.67"}},"payment_mode":"INSTANT_TRANSFER","create_time":"2023-12-22T21:32:18Z","custom":"id=3QWVF5ZswM&user=1&plan=2&interval=monthly&renew=10.4895&amount=3.671325&currency=USD&taxes=3%2C1&coupon=1","transaction_fee":{"currency":"USD","value":"0.62"},"billing_agreement_id":"I-MKX0RAHUCACW","update_time":"2023-12-22T21:32:18Z","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","protection_eligibility":"ELIGIBLE","links":[{"method":"GET","rel":"self","href":"https://api.sandbox.paypal.com/v1/payments/sale/1SK68449YM493670F"},{"method":"POST","rel":"refund","href":"https://api.sandbox.paypal.com/v1/payments/sale/1SK68449YM493670F/refund"}],"id":"1SK68449YM493670F","state":"completed","invoice_number":""},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0UX959158W078642N-2MW5123584490731L","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0UX959158W078642N-2MW5123584490731L/resend","rel":"resend","method":"POST"}]}}
`
Variable assignment fixed.
@buzzclue
Copy link
Contributor Author

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

@srmklive srmklive merged commit dc680c6 into srmklive:v3.0 Feb 19, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants