FatFractal customer forums



Author Topic: PayPal Integration  (Read 7091 times)

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: PayPal Integration
« Reply #15 on: February 21, 2014, 03:06:08 AM »
Thank you for your efforts.  I found the error in my code and am on my way.

Yet it was still VERY strange behavior from RingoJS.  If you are curious: in that last code you posted, the error just moves up one line.  If you want to reproduce my error, I was able to boil it down all the way to this.  Try it and scratch your head along with me at Ringo's behavior:

Code: [Select]
var ff = require('ffef/FatFractal');
var http = require('ringo/httpclient');
exports.strangeError = function() {
    var response = http.request(true);
    if (response) {
    ff.logger.info("Got response " + response.status) // <-- The error is from this line.  Yes, really.
    }
}

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: PayPal Integration
« Reply #16 on: March 20, 2014, 12:06:21 PM »
Starting sometimes recently (in the last 2-3 days?) my code has been unable to contact PayPal's servers.  If I deploy locally, it works.  If I deploy to FatFractal, it times out.  Was there some change recently that would affect this?

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: PayPal Integration
« Reply #17 on: March 20, 2014, 12:17:18 PM »
I just tried it with this code you provided before.  Again, it works when deployed locally, but times out when deployed to the FatFractal server.

Hi Eric,

To reproduce this example, you'll need to use the 'request' method of the Ringo httpclient, which gives the most flexibility (see docs at http://ringojs.org/api/v0.8/ringo/httpclient/#request). That method accepts a username and password, among other things. So, translating your curl example looks like this:

application.ffdl
Code: [Select]
CREATE EXTENSION /paypal UNSECURED AS javascript:require('scripts/test').paypal();

test.js
Code: [Select]
var ff = require('ffef/FatFractal');
var http = require('ringo/httpclient');

exports.paypal = function() {
    var request = {
        url: "https://api.sandbox.paypal.com/v1/oauth2/token",
        data: {
            grant_type: "client_credentials"
        },
        method: "POST",
        headers: {
            Accept: "application/json",
            "Accept-Language": "en_US"
        },
        username: "xxx",
        password: "xxx"
    };

    var response = http.request(request);
   
    var r = ff.response();
    if (response) {
        r.result = JSON.parse(response.content);
        r.responseCode = 200;
        r.statusMessage = "Success";
    }
};

Dave
« Last Edit: March 20, 2014, 12:18:29 PM by gkc »

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: PayPal Integration
« Reply #18 on: March 20, 2014, 12:19:52 PM »
Hi Eric,

FYI I've modified your post from just a moment ago and obfuscated username and password

Nothing's changed on the server-side in the past week. Let me take a look and see if I can find out what's happening

Cheers,

- Gary

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: PayPal Integration
« Reply #19 on: March 20, 2014, 12:21:22 PM »
Hmmm. Have you made this API call today? I don't see it in our nginx logs - maybe I'm not looking for the right thing (I'm searching for 'paypal')

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: PayPal Integration
« Reply #20 on: March 20, 2014, 12:22:55 PM »
Yes, I performed this test today.  I'm not sure what to tell you to search for, because I'm not sure what is logged ...

FYI - those were PayPal's generic, test uname/pw, but thanks for looking out for me!

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: PayPal Integration
« Reply #21 on: March 20, 2014, 12:27:36 PM »
OK found it. Investigating...

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: PayPal Integration
« Reply #22 on: March 20, 2014, 12:50:22 PM »
Very very weird. I've deployed the exact same code to a test harness on exactly the same virtual server and engine as where your app is running, and it works.

Investigations continue ...

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: PayPal Integration
« Reply #23 on: March 20, 2014, 01:12:18 PM »
Hi Eric,

OK - in the code you are testing, you have the
Code: [Select]
        var http = require('ringo/httpclient');
inside of your function. I've occasionally seen this cause problems in the past - can I suggest you put it *outside* of your function (as it is in the code you show above) please?

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: PayPal Integration
« Reply #24 on: March 20, 2014, 01:17:51 PM »
Well - it works now.  I hestitate to say that is what fixed it, though, because my *real* code also works now, and I did not touch it.  It was always calling require() outside its function.

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: PayPal Integration
« Reply #25 on: March 20, 2014, 01:23:09 PM »
There is weirdness going on somewhere. My gut tells me that it is related to that 'require' call; am going to have to figure out how to *prove* that now.

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: PayPal Integration
« Reply #26 on: March 20, 2014, 01:31:51 PM »
Thank you for looking into it.  I'm glad it's working at least for now, so that we can continue our testing at least for now.  :)

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: PayPal Integration
« Reply #27 on: March 20, 2014, 01:34:04 PM »
PS you should enhance your http response handling so you are checking the status code in the http response - something like this
Code: [Select]
    if (response) {
        // got a response - check if it is success or error
        if (response.status >= 200 && response.status < 300)
        {
            // success response handling
        } else {
            // error response handling
        }
    } else {
        // handle no response at all
    }

 

Copyright © FatFractal customer forums