5

I live in Hong Kong and I always get this sandbox paypal transaction error after midnight from paypal.billingAgreement.execute(). The error goes away in the afternoon, probably because the place where paypal server is located finally gets past the midnight.

{    name: 'SUBSCRIPTION_UNMAPPED_ERROR',
     message: 'Subscription start date should be greater than current date',
     information_link: 'https://developer.paypal.com/docs/api/payments.billing-agreements#errors',
     debug_id: 'd2e618eef4162',
     httpStatusCode: 400
 },

I know this is a timezone problem with the sandbox environment but I can't figure out how to solve it.

My billing agreement is created as per the example in PayPal-node-SDK

process.env.TZ = 'utc';
var isoDate = new Date();
isoDate.setSeconds(isoDate.getSeconds() + 4);
isoDate.toISOString().slice(0, 19) + 'Z';

var billingAgreementAttributes = {
    "start_date": isoDate,
    /..../
}

I have set the TZ environment variable in nodes to utc;

The time zone setting of the sandbox account I use to log in and subscribe:

enter image description here

I've also tried different zones like Eastern Time but it has no effects.

RedGiant
  • 4,444
  • 11
  • 59
  • 146
  • 1
    You may explicitly set it to your country's timezone like that: `process.env.TZ = 'Hongkong';` Also would you please try to set`start_date` manually(hardcoded) to something like this `"start_date": "2018-02-19T00:37:04Z"`. I don't believe that `isoDate` trick works.. – gokcand Jan 12 '18 at 17:12
  • @gokcand okay, I'll try that. Do you think this `start_date` problem only occurs in the sandbox mode. Will it still happen when the app goes live? – RedGiant Jan 12 '18 at 17:44
  • 1
    I think that sandbox mode probably mimics the prod environment completely. So it may happen in live mode too. Btw, have you tried my solution? – gokcand Jan 13 '18 at 11:20
  • @gokcand Changing the environment timezone variable doesn't work. I have to set the start date a month ahead `let startDate = moment().add(1,'month').toISOString().slice(0, 19) + 'Z'` and use `setup_fee` in `merchant_preferences` if I want to charge the user right after the subscription is created. I couldn't find any other way. – RedGiant Jan 13 '18 at 17:44
  • What does this line: `isoDate.toISOString().slice(0, 19) + 'Z';` do? Maybe it should be `isoDate = isoDate.toISOString().....` – Heinrich Lee Yu Jan 17 '18 at 09:44

1 Answers1

2

As per PayPal Docs, StartDate should be UTC, looks Setting Process Time Zone

 process.env.TZ = 'utc';

has no effect in your code(some time it might be cashed), can you check the date variable value is in UTC?

I would suggest to change

var isoDate = new Date();

to

var isoDate = new Date().toISOString();

Hope it helps!

H. Mahida
  • 2,356
  • 1
  • 12
  • 23
  • I'm not able to try your suggestion now because it's not midnight in Hong Kong when the problem occurs, But my code already uses `toISOString()` in `var isoDate = new Date(); isoDate.setSeconds(isoDate.getSeconds() + 4); isoDate.toISOString().slice(0, 19) + 'Z';` ` – RedGiant Jan 19 '18 at 04:36