i was trying to tests paypal disputes in a sandbox and was following this guide: https://developer.paypal.com/docs/integration/direct/customer-disputes/integration-guide/#sandbox-only-methods.
However, on the step 2(Get permission from the buyer) the code provided by paypal for connect button generation was throwing js syntax error, so I changed it to this:
<span id='cwppButton'></span>
<script src="https://www.paypalobjects.com/js/external/connect/api.js"></script>
<script>
paypal.use( ['login'], function (login) {
login.render ({
"appid": "MY_CLIENT_ID",
"authend": "sandbox",
"scopes": "openid",
"containerid": "cwppButton",
"locale": "en-us",
"buttonType": "CWP",
"buttonSize": "lg",
"returnurl": "https://a62add0d.ngrok.io/api/payments/paypal/get-token/"
});
});
</script>
How u can see i changed scopes to just "openid", cuz separating links provided by paypal in this example gave me "Invalid Scope" error However i got access token from the button in this step. The next problem i faced was on step 4 (Generate JSON web token for PayPal Authorization Assertion), the code paypal provided gave syntax error, so i replaced it to this:
<span id='cwppButton'></span>
<html>
<script>
function base64url(source) {
encodedSource = btoa(source);
encodedSource = encodedSource.replace(/=+$/, '"');
encodedSource = encodedSource.replace(/\+/g, '-');
encodedSource = encodedSource.replace(/\//g, '-');
return encodedSource;
}
function generateJWT() {
var header = {"alg": "none", "typ": "JWT"};
var data = {"iss" :"MY_CLIENT_ID",
"email" : "casino.player@gmail.com" };
document.write(base64url(JSON.stringify(header)) + "." +
base64url(JSON.stringify(data)) + ".");
}
</script>
<body onload="generateJWT()"/>
And as a result running create dispute request on step 6 i've got this error:
{
"error": "invalid_request",
"error_description": "No permissions to set target_client_id"
}
My question is how to setup and test correctly paypal disputes in sandbox? If somebody was facing the same problem with disputes testing?
From Step 1 https://developer.paypal.com/docs/integration/direct/customer-disputes/integration-guide/#sandbox-only-methods :
Set up your REST app with the following scope:
https://uri.paypal.com/services/disputes/create = DISPUTE_CREATE
Have you done this? This first step may need to be done for your sandbox account / sandbox client ID REST APP by PayPal, as you are integrating an API that requires approval.
Then, you will be able to complete Step 2 with the necessary scope.
Without that required scope and permission, you will get that error in Step 4.