jockster / paypal-recurring

node.js package that makes recurring payments with PayPal easier to manage
MIT License
38 stars 15 forks source link

Error = true #5

Closed TiagoPortfolio closed 10 years ago

TiagoPortfolio commented 10 years ago

Hey, Here it is the piece of code where I am having trouble:

app.get("/purchase/success", function(req, res){
   // # Extract the Token and PayerID which PayPal has appended to the URL as
  //  # query strings:
  var tokenid, payerid;

  if(req.query.token != null)
    tokenid = req.query.token;
  else
    tokenid = false;

  if(req.query['PayerID'] != null)
    payerid = req.query['PayerID'];
  else
    payerid = null;

  //  # Show an error if we don't have both token & payerid
  if(!tokenid || !payerid)
    res.send(500, "Invalid request.");

 // # We want to create a demo subscription with one month of free trial period
 // # with no initial charging of the user.

 // # Therefore we set the PROFILESTARTDATE to one month ahead from now
 var startdate = new Date();
 startdate.setMonth(startdate.getMonth()+1);

 var params = {
  AMT:              10,
  DESC:             "Demo subscription",
  BILLINGPERIOD:    "Month",
  BILLINGFREQUENCY: 1,
  PROFILESTARTDATE: "2013-02-11T18:25:25.000Z"
};

  paypal.createSubscription('tokenid', 'payerid', params, function(error, data){
    if(!error)
       // # We've just turned our user into a subscribing customer. Chapeau!
       // # Show some links so that we can fetch some data about the subscription
       // # or to cancel the subscription.
       res.render('createSubscription');

    else{
       // # PayPal's API can be down or more probably, you provided an invalid token. 

     res.send("Temporary error or invalid token, please come back later");
   }
  });
});

When I call paypal.createSubscription , error is always = true. Can you help me solve this problem?

Kudos, Tiago Sousa

jaybryant commented 10 years ago

Hi!

Unfortunately I have very little time to look into this right now, but from taking a quick look at your code, the PROFILESTARTDATE looks suspicious as its a date from the past which could cause the error. Take a look at the error message and let me know what you find out.

Also, make sure that the unit tests pass in your environment to make sure that PayPal hasnt changed anything on their side.

Thank you!

TiagoPortfolio commented 10 years ago

I assigned startdate to PROFILESTARTDATE and everything is fine. I'm using node-inspector to debug my code to try to figure out what error is catched but the only information i can get about the error is error ="true" ...

Dont know if it helps but data = null

jaybryant commented 10 years ago

Open the lib/Paypal.coffee file and edit line 153 from:

  return callback err ? true, null if response["ACK"] isnt "Success"

To:

  return callback err ? true, response if response["ACK"] isnt "Success"

And let me know what is returned back to you when invoking the createSubscription method.

TiagoPortfolio commented 10 years ago

First of all let me say that I am using nodejs and I took your example.coffee and converted it to example.js and I run it with node example.js. Hope there's no problem with that.

I edited Paypal.coffee but im not sure I did what you wanted but here it is a screenshot with local variables: recurrence

Again: data = null, err=true

Thanks for your help.

TiagoPortfolio commented 10 years ago

I just figured out what was wrong. I was doing bad ternary conditions because I translated all the Coffee-Script code into Javascript and that wasn't easy.

I have the source in Javascript, I think you should share the Javascript with Node.js version because, in my opinion, it is more popular than Coffee-Script. I can give you the code if you want! Anyway thanks for the support and good work!

jaybryant commented 10 years ago

Hi again,

Glad you got it working. It should be working out of the box without having to convert the source to pure javascript. Doesnt it?

In the meantime, please do share your working example file in pure Javascript and I'll include it as I am sure it will be helpful to more people out there.

Thanks!

hatzipanis commented 9 years ago

Hi @jaybryant - firstly thanks for such a helpful package and even better docs! Saved me countless hours and I really do appreciate it.

I was just wondering why you wouldn't return the response by default instead of null? Wouldn't that be more intuitive? I'm quite new to all of this so this is more of a question to help me grasp the subject rather than telling you how you should be doing things :) Thanks in advance.