Hello, I'm a developer working for a site looking to integrate paypal subscriptions into our services. I'm running into a problem where I can create subscriptions, but not access them after the fact. To demonstrate, I wrote the following script, intended to create, load information about, and then cancel a subscription. Only the first step seems to succeed. $header =
[
"Content-Type:application/json",
"Authorization:Bearer ".$accessToken
];
$post =
[
"plan_id" => $planId
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, "https://api-m.sandbox.paypal.com/v1/billing/subscriptions/");
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$paypalUsername:$paypalPassword");
$result = curl_exec($ch);
var_dump( $result);
echo "\n\n";
$res = json_decode($result,true);
$subscriptionId = $res["id"];
echo "Subscription id:".$subscriptionId."\n\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, "https://api-m.sandbox.paypal.com/v1/billing/subscriptions/".$subscriptionId."/");
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$paypalUsername:$paypalPassword");
$result = curl_exec($ch);
var_dump( $result);
echo "\n\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, "https://api-m.sandbox.paypal.com/v1/billing/subscriptions/".$subscriptionId."/cancel");
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$paypalUsername:$paypalPassword");
$result = curl_exec($ch);
var_dump ($result);
echo "\n\n"; This returns the following: string(457) "{"status":"APPROVAL_PENDING","id":"I-YUVAH3F0SG96","create_time":"2021-04-01T21:58:14Z","links":[{"href":"https://www.sandbox.paypal.com/webapps/billing/subscriptions?ba_token=BA-8CP59302DD939213F","rel":"approve","method":"GET"},{"href":"https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-YUVAH3F0SG96","rel":"edit","method":"PATCH"},{"href":"https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-YUVAH3F0SG96","rel":"self","method":"GET"}]}"
Subscription id:I-YUVAH3F0SG96
string(0) ""
string(347) "{"name":"RESOURCE_NOT_FOUND","message":"The specified resource does not exist.","debug_id":"5276bf36b7c2e","details":[{"issue":"INVALID_RESOURCE_ID","description":"Requested resource ID was not found."}],"links":[{"href":"https://developer.paypal.com/docs/api/v1/billing/subscriptions#RESOURCE_NOT_FOUND","rel":"information_link","method":"GET"}]}"
As you can see, the subscription does get created, but any attempt to do anything with it fails. Can anyone tell me what I'm doing wrong?
... View more