Paypal-checkout-components: Question on creating subscription and receiving payments

Created on 9 Jul 2019  路  13Comments  路  Source: paypal/paypal-checkout-components

I follow this guide to create plan and subscription: https://developer.paypal.com/docs/subscriptions/integrate/

How do I check when payments are made? For the old plan/agreement API, I can use webhook events to track payments. But the new subscription doesn't seen to generate payments, or at least not right away. Is the payment only coming at the end of the cycle now? I can see a payment event was sent when if an initial fee is set, but it's associated with an agreement, and not a subscription.

I'm very confused there's no resource on handling payments for subscription??

outdated

Most helpful comment

@ravishekhar Thanks for your reply.

First, how would I be able to reference a payment to a subscription? In the previous plan/agreement API, there's a field call billing_agreement_id for every recurring payment. What is it now with the new subscription?

Second, I'm testing using a sandbox account, made several daily subscription attempts but none of them has generated any payment except for the initial fee. And it's way past the next_billing_time time now. For example:

{
    "status": "ACTIVE",
    "status_update_time": "2019-07-09T11:41:49Z",
    "id": "I-L5RWXK2J51TG",
    "plan_id": "P-28N65069313032147LUSBK6Q",
    "start_time": "2019-07-09T04:00:00Z",
    "quantity": "1",
    "shipping_amount": {
        "currency_code": "CAD",
        "value": "0.0"
    },
    "subscriber": {
        "name": {
            "given_name": "xxx",
            "surname": "xxx"
        },
        "email_address": "[email protected]",
        "shipping_address": {
            "name": {
                "full_name": "xxx xxx"
            },
            "address": {
                "address_line_1": "1230-605 Robson Street",
                "address_line_2": "1230",
                "admin_area_2": "Vancouver",
                "admin_area_1": "BC",
                "postal_code": "V6G 1C3",
                "country_code": "CA"
            }
        }
    },
    "billing_info": {
        "outstanding_balance": {
            "currency_code": "CAD",
            "value": "0.0"
        },
        "cycle_executions": [
            {
                "tenure_type": "REGULAR",
                "sequence": 1,
                "cycles_completed": 0,
                "cycles_remaining": 24,
                "current_pricing_scheme_version": 1
            }
        ],
        "last_payment": {
            "amount": {
                "currency_code": "CAD",
                "value": "2.0"
            },
            "time": "2019-07-09T04:18:27Z"
        },
        "next_billing_time": "2019-07-09T10:00:00Z",
        "final_payment_time": "2042-07-09T10:00:00Z",
        "failed_payments_count": 0
    },
    "auto_renewal": false,
    "create_time": "2019-07-09T04:18:03Z",
    "update_time": "2019-07-09T11:41:49Z",
    "links": [
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG/cancel",
            "rel": "cancel",
            "method": "POST"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG",
            "rel": "edit",
            "method": "PATCH"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG",
            "rel": "self",
            "method": "GET"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG/suspend",
            "rel": "suspend",
            "method": "POST"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG/capture",
            "rel": "capture",
            "method": "POST"
        }
    ]
}

All 13 comments

Payment.Sale.Completed is sent for all(initial & Subsequent) payments.
Details: https://developer.paypal.com/docs/subscriptions/reference/#webhooks

@ravishekhar Thanks for your reply.

First, how would I be able to reference a payment to a subscription? In the previous plan/agreement API, there's a field call billing_agreement_id for every recurring payment. What is it now with the new subscription?

Second, I'm testing using a sandbox account, made several daily subscription attempts but none of them has generated any payment except for the initial fee. And it's way past the next_billing_time time now. For example:

{
    "status": "ACTIVE",
    "status_update_time": "2019-07-09T11:41:49Z",
    "id": "I-L5RWXK2J51TG",
    "plan_id": "P-28N65069313032147LUSBK6Q",
    "start_time": "2019-07-09T04:00:00Z",
    "quantity": "1",
    "shipping_amount": {
        "currency_code": "CAD",
        "value": "0.0"
    },
    "subscriber": {
        "name": {
            "given_name": "xxx",
            "surname": "xxx"
        },
        "email_address": "[email protected]",
        "shipping_address": {
            "name": {
                "full_name": "xxx xxx"
            },
            "address": {
                "address_line_1": "1230-605 Robson Street",
                "address_line_2": "1230",
                "admin_area_2": "Vancouver",
                "admin_area_1": "BC",
                "postal_code": "V6G 1C3",
                "country_code": "CA"
            }
        }
    },
    "billing_info": {
        "outstanding_balance": {
            "currency_code": "CAD",
            "value": "0.0"
        },
        "cycle_executions": [
            {
                "tenure_type": "REGULAR",
                "sequence": 1,
                "cycles_completed": 0,
                "cycles_remaining": 24,
                "current_pricing_scheme_version": 1
            }
        ],
        "last_payment": {
            "amount": {
                "currency_code": "CAD",
                "value": "2.0"
            },
            "time": "2019-07-09T04:18:27Z"
        },
        "next_billing_time": "2019-07-09T10:00:00Z",
        "final_payment_time": "2042-07-09T10:00:00Z",
        "failed_payments_count": 0
    },
    "auto_renewal": false,
    "create_time": "2019-07-09T04:18:03Z",
    "update_time": "2019-07-09T11:41:49Z",
    "links": [
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG/cancel",
            "rel": "cancel",
            "method": "POST"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG",
            "rel": "edit",
            "method": "PATCH"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG",
            "rel": "self",
            "method": "GET"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG/suspend",
            "rel": "suspend",
            "method": "POST"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-L5RWXK2J51TG/capture",
            "rel": "capture",
            "method": "POST"
        }
    ]
}

Product request payload:

{
    name: 'Product Name',
    type: 'SERVICE'
}

Plan request payload:

{
   product_id: product.id,
   name: 'Plan Name',
   billing_cycles: [ {
       frequency: {
           interval_unit: 'DAY',
           interval_count: 1
       },
       tenure_type: 'REGULAR',
       sequence: 1,
       total_cycles: 24,
       pricing_scheme: {
           fixed_price: {
               value: 10,
               currency_code: 'USD'
           }
       }
   } ],
   payment_preferences: {}
}

We then use the smart button to create and approve a subscription:

window.paypal.Buttons({
   createSubscription: (data, actions) => {
       return actions.subscription.create({
           plan_id: plan.id
       });
   },

   onApprove: (data) => {
       console.log(data);
   }

}).render('#paypal-checkout');

Thanks for bringing up the payment not happening on sandbox. Let me check. I will get back to you.
Also billing_agreement_id should be there in PAYMENT.SALE.COMPLETED webhook. In the BILLING.SUBSCRIPTION.CREATED webhook there will be an id field in resource.

The Sandbox environment was experiencing some trouble sending webhooks. It's fixed now. You should be able to get webhooks.

there is still a problem with the next_billing_date and cycle processing on the IPN and on the JS SDK callback. basically, the date is not refreshed properly and it is showing in the past.

@thanatos11 Can you please elaborate on the issue.
Also please share the Subscription Id if you are facing trouble in Sandbox environment, else please contact Support via Chat or email.

so, i am trying to use the buttons to create a subscription:

the response is the same as the above isues:

{
"resource": {
"status": "ACTIVE",
"update_time": "2020-02-16T11:56:17Z",
"billing_info": {
"cycle_executions": [
{
"total_cycles": 12,
"sequence": 1,
"cycles_remaining": 12,
"current_pricing_scheme_version": 1,
"tenure_type": "REGULAR",
"cycles_completed": 0
}
],
"failed_payments_count": 0,
"final_payment_time": "2021-01-16T10:00:00Z",
"next_billing_time": "2020-02-16T11:56:14Z",
"outstanding_balance": {
"value": "0.0",
"currency_code": "USD"
}
},
"links": [
{
"href": "https://node-sb-subscriptionmgmtserv-vip.slc.paypal.com:19472/v1/billing/subscriptions/I-RBDWH01TL7UG/cancel",
"method": "POST",
"rel": "cancel",
"encType": "application/json"
},
{
"href": "https://node-sb-subscriptionmgmtserv-vip.slc.paypal.com:19472/v1/billing/subscriptions/I-RBDWH01TL7UG",
"method": "PATCH",
"rel": "edit",
"encType": "application/json"
},
{
"href": "https://node-sb-subscriptionmgmtserv-vip.slc.paypal.com:19472/v1/billing/subscriptions/I-RBDWH01TL7UG",
"method": "GET",
"rel": "self",
"encType": "application/json"
},
{
"href": "https://node-sb-subscriptionmgmtserv-vip.slc.paypal.com:19472/v1/billing/subscriptions/I-RBDWH01TL7UG/suspend",
"method": "POST",
"rel": "suspend",
"encType": "application/json"
},
{
"href": "https://node-sb-subscriptionmgmtserv-vip.slc.paypal.com:19472/v1/billing/subscriptions/I-RBDWH01TL7UG/capture",
"method": "POST",
"rel": "capture",
"encType": "application/json"
}
],
"start_time": "2020-02-16T08:00:00Z",
"shipping_amount": {
"value": "0.0",
"currency_code": "USD"
},
"subscriber": {
"email_address": "[email protected]",
"name": {
"surname": "Doe",
"given_name": "John"
},
"shipping_address": {
"address": {
"postal_code": "95131",
"admin_area_1": "CA",
"admin_area_2": "San Jose",
"country_code": "US",
"address_line_1": "1 Main St"
}
}
},
"create_time": "2020-02-16T11:55:48Z",
"status_update_time": "2020-02-16T11:56:17Z",
"plan_id": "P-1M9333599L948153DLY4D5MY",
"id": "I-RBDWH01TL7UG",
"quantity": "1"
},
"event_type": "BILLING.SUBSCRIPTION.CREATED",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-4SY344774S9367140-9CP94841H29489051",
"method": "GET",
"rel": "self"
},
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-4SY344774S9367140-9CP94841H29489051/resend",
"method": "POST",
"rel": "resend"
}
],
"summary": "Subscription created",
"event_version": "1.0",
"create_time": "2020-02-16T19:55:48.000Z",
"resource_version": "2.0",
"id": "WH-4SY344774S9367140-9CP94841H29489051",
"resource_type": "subscription"
}

and this answer is provided on the following web-hooks as well as the return from the popup callback:

'created_sub': 'BILLING.SUBSCRIPTION.CREATED',
'activated_sub': 'BILLING.SUBSCRIPTION.ACTIVATED',
'updated_sub': 'BILLING.SUBSCRIPTION.UPDATED',
'expired_sub': 'BILLING.SUBSCRIPTION.EXPIRED',
'canceled_sub': 'BILLING.SUBSCRIPTION.CANCELLED',
'suspended_sub': 'BILLING.SUBSCRIPTION.SUSPENDED',

i require the next_billing date as an expire method for the subscription validations. and whitout getting it, on sandbox, i cannot simulate how it will work in production. Also i am afraid of the production environemnt as well to not ahve the same issues

also, it seems on the webhook for the payment.compelted behaves the same:
{
"status": "ACTIVE",
"update_time": "2020-02-16T12:26:24Z",
"plan_id": "P-1M9333599L948153DLY4D5MY",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP/cancel",
"method": "POST",
"rel": "cancel"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP",
"method": "PATCH",
"rel": "edit"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP",
"method": "GET",
"rel": "self"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP/suspend",
"method": "POST",
"rel": "suspend"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP/capture",
"method": "POST",
"rel": "capture"
}
],
"start_time": "2020-02-16T08:00:00Z",
"shipping_amount": {
"value": "0.0",
"currency_code": "USD"
},
"subscriber": {
"email_address": "[email protected]",
"name": {
"surname": "Doe",
"given_name": "John"
},
"shipping_address": {
"address": {
"postal_code": "95131",
"admin_area_1": "CA",
"admin_area_2": "San Jose",
"country_code": "US",
"address_line_1": "1 Main St"
}
}
},
"create_time": "2020-02-16T12:25:50Z",
"status_update_time": "2020-02-16T12:26:24Z",
"billing_info": {
"cycle_executions": [
{
"total_cycles": 12,
"sequence": 1,
"cycles_remaining": 12,
"current_pricing_scheme_version": 1,
"tenure_type": "REGULAR",
"cycles_completed": 0
}
],
"failed_payments_count": 0,
"final_payment_time": "2021-01-16T10:00:00Z",
"next_billing_time": "2020-02-16T12:26:22Z",
"outstanding_balance": {
"value": "0.0",
"currency_code": "USD"
}
},
"id": "I-75SA1TSWUVJP",
"quantity": "1"
}

after 30-40 minutes if i manually query the API, i get the correct answer. the thing is the delay, which is very cvolatile and cannot controll it. even if i implement cronjobs, i am not sure it will process corectly:

{
"status": "ACTIVE",
"status_update_time": "2020-02-16T12:31:09Z",
"id": "I-75SA1TSWUVJP",
"plan_id": "P-1M9333599L948153DLY4D5MY",
"start_time": "2020-02-16T08:00:00Z",
"quantity": "1",
"shipping_amount": {
"currency_code": "USD",
"value": "0.0"
},
"subscriber": {
"name": {
"given_name": "John",
"surname": "Doe"
},
"email_address": "[email protected]",
"shipping_address": {
"address": {
"address_line_1": "1 Main St",
"admin_area_2": "San Jose",
"admin_area_1": "CA",
"postal_code": "95131",
"country_code": "US"
}
}
},
"billing_info": {
"outstanding_balance": {
"currency_code": "USD",
"value": "0.0"
},
"cycle_executions": [
{
"tenure_type": "REGULAR",
"sequence": 1,
"cycles_completed": 1,
"cycles_remaining": 11,
"current_pricing_scheme_version": 1,
"total_cycles": 12
}
],
"last_payment": {
"amount": {
"currency_code": "USD",
"value": "19.95"
},
"time": "2020-02-16T12:26:23Z"
},
"next_billing_time": "2020-03-16T10:00:00Z",
"final_payment_time": "2021-01-16T10:00:00Z",
"failed_payments_count": 0
},
"create_time": "2020-02-16T12:25:50Z",
"update_time": "2020-02-16T12:31:09Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP/cancel",
"rel": "cancel",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP",
"rel": "edit",
"method": "PATCH"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP/suspend",
"rel": "suspend",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-75SA1TSWUVJP/capture",
"rel": "capture",
"method": "POST"
}
]
}

@thanatos11 are you using a sandbox API or this happening also in live env?

im experiencing this with paypal subscription api aswell

I don't know if this is relevant, but I was told that if you use their buttons the webhooks will not work. You have to create subscriptions using the api.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings