question

Planet 316 avatar image
Planet 316 asked

Paypal and selling physical items

We are trying to use Paypal to sell physical items through our app. We have tried using UnityWebRequest to do the call which allows us to log in and get a token back from Paypal which would allow us to then make a purchase.

However, for some odd reason on iOS the response was returning an error and we couldn't get it to work. It worked fine on Android and in the Unity editor.

So then the thought was to use Playfab cloud scripting. I saw the Playfab example of an HTTP request and copied it, replacing information to match what is needed. The encodeString is a combination of id and secret.

Unfortunately, the response is empty and is not returning the json from Paypal (we can get this using UnityWebRequest, just iOS isn't working right).

Is there something that we're missing for why this script doesn't work the same?

Thank you for any help provided.

var headers = {
        "Accept": "application/json",
	"Accept-Language": "en_US",
	"Authorization": "Basic " + args.encodeString
    };


    var data = {
        "grant_type": "client_credentials"
    };
    
    var url = "https://api.sandbox.paypal.com/v1/oauth2/token";
    var content = JSON.stringify(data);
    var httpMethod = "post";
    var contentType = "application/json";


    // The pre-defined http object makes synchronous HTTP requests
    var response = http.request(url, httpMethod, content, contentType, headers);
    return { responseContent: response };
CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

According to their documentation (https://developer.paypal.com/docs/api/overview/), the call to oauth2/token requires the client_id and secret. Can you provide an example of this call that works in Postman?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Planet 316 avatar image Planet 316 commented ·

I have honestly never used Postman before, but I'll take a look into it.

The code posted above is duplicated from a working UnityWebRequest and converted to js. This is a prototype of selling products in app that we want to incorporate and my coworker is working on it in Unity, but I am a bit more familiar with the Playfabs cloud script.

I converted it over and pass in the following

clientID + ":" + secret

Which is what is assigned to args.encodeString.

I'll look at Postman and see how that works to see if I can get a working example.

Thank you for your help so far.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.