PayPal billing agreements REST API - how to start immediately

青春壹個敷衍的年華 提交于 2020-01-12 04:53:11

问题


How can I start charging a user the user immediately for a PayPal billing agreement?

Here's what I've got so far.

  1. Create a Billing Plan (POST .../payments/billing-plans/)
  2. Make it active (PATCH .../payments/billing-plans/)
  3. Create a Billing Aggreement (POST .../payments/billing-agreements/)
  4. Send user to approval_url, user approves, redirected to return url
  5. Execute agreement (POST .../payments/billing-agreements//agreement-execute)

This all seems to work, but I want to charge the user right now and every month in the future. If I set start_date to now in step 3 I get an error, it must be in the future. If I set it in the future the user is not charged.

Do I need to 'Set outstanding agreement amounts' then 'Bill outstanding agreement amounts' for the initial payment?

Also, what about monthly payments, do they require some action or do they just happen as specified in the Billing Plan?


Update

I'm testing this around 2014-09-16T20:06:30+0000

If I send start_date as the current UTC time it get an error at step 2 telling me it must be in the future.

If I send the current date +30 secs or +2 hours I get through to step 5 which returns a 400 response: UNKNOWN_ERROR "An unknown error has occurred"

If I send the current date +4 hours it all works. The current UTC time is 8pm so adding 4 hours means the start_date is tomorrow.

Does this mean I can't charge the user today? Does the start_date have to be in next day or even the next business day?


回答1:


I've talked to a PayPal rep and found that start_date must be tomorrow or later. They are going to add this to the docs.

If you want to start monthly billing immediately you might be able to do it by setting the start date to be in one months time and charging a setup fee to cover the first month. I haven't tested this as it's not what I want.




回答2:


First payment for agreements will be billed right on specified start_date. The subsequent amounts are also taken automatically by PP. You need to work with the BillOutstandingAmount calls only if PP failed to pick the payment on the renewal date.

The problem I faced when developing with their RestAPI was specifying a wrong timezone. Maybe this is the same for you. Make sure the proper timezone is specified in your start_date (with all dates given to PP in fact)

Dates should be in this format: yyyy-MM-ddTHH:mm:ssZ

ex. start_date = 2014-09-16T09:20:00-0400

IF you want to make sure Paypal accepts the date as being valid, just add a few seconds to it.

Let's say you are in Java, you can do something like:

private String getPaypalDate()
{
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

    // Add 30 seconds to make sure Paypal accept the agreement date
    Date rightNow = new Date(new Date().getTime() + 30000);

    return df.format(rightNow);
}



回答3:


I used this date format working.

  $time = time();
  $startDate = date('Y-m-d\\TH:i:s\\Z', $time);



回答4:


I can't replicate, actually. I stumbled on this thread when getting the error due to setting it to moment.now(). But setting it to even 5 seconds in the future works a-ok. I'm using JavaScript, "start_date": moment().add({seconds:5}).format() and that checks out fine. Moment.js will set TZ to UTC when formatting as such, so it's gotta be a timezone thing on your end?




回答5:


It looks like the payments just process based on the date being before or after 07:00 UTC of the current date.

For example. The current date time is 2017-05-04T04:50:00.00Z I set my start date to be the current UTC date time plus 30 seconds. Because the agreement date is set to a value greater then the current date time the API doesn't throw an error, but it DOESN'T set your time to be what you specified. Instead it sets it to 2017-05-04T07:00:00Z.

Now, if you have the same date time of 2017-05-04T04:50:00.00Z and instead of adding 30 seconds you add 24hrs you'd think that your time would then be set to be 2017-05-05T04:50:00.00Z. But no, the time will be set to 2017-05-05T07:00:00Z.

So it seems like these just process everyday at 07:00 UTC and you can't specify anything but the date.



来源:https://stackoverflow.com/questions/25858816/paypal-billing-agreements-rest-api-how-to-start-immediately

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!