Get Subscription Transactions API Call after successful Subscription Checkout
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, everyone.
I have an issue with the GET Subscription Transactions request that I hope you guys can help me out with.
I have added a Smart Subscribe Button on my site using PayPal JS SDK. In the onApprove handler, I send the subscription ID and order ID to a backend script so I can create a DB record for the new PayPal user/subscriber and a transaction record for the Trial Fee Payment.
In the backend script (PHP), I am able to successfully do a GET Subscription Details call to the Subscriptions API which I need for the User and Subscriber DB records. But once the backend script tries to do GET Subscription Transactions request for the new Transaction DB record, the API returns an empty JSON {} response. 😓
For debugging, I've tried hard-coding an existing Subscription ID and Order ID into the backend script, and the process works as it should be and I am able to get the subscription transactions. But whenever, it starts using the Subscription ID and Order ID from a successful PayPal Checkout, the request for the subscription transactions becomes empty again. (Which makes me scratch my head every single time...)
For reference, here are my function definitions for these two PayPal API Calls:
GET Subscription
function getPaypalSubscription($subscriptionId, $paypalAccessToken)
{
$apiUrl = $_ENV['PAYPAL_API_URL'] . $_ENV['PAYPAL_API_VERSION'] . '/billing/subscriptions/' . $subscriptionId;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $apiUrl,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $paypalAccessToken,
),
));
$paypalSubscription = curl_exec($curl);
curl_close($curl);
return json_decode($paypalSubscription);
}
GET Subscription Transactions
function getPaypalSubscriptionTransactions($subscriptionId, $paypalAccessToken, $startTime, $endTime)
{
$apiUrl = $_ENV['PAYPAL_API_URL'] . $_ENV['PAYPAL_API_VERSION'] . '/billing/subscriptions/' . $subscriptionId . '/transactions';
$queryParams = array(
'start_time' => $startTime,
'end_time' => $endTime
);
$apiUrl .= '?' . http_build_query($queryParams);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $apiUrl,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $paypalAccessToken,
),
));
$paypalSubscriptionTxns = curl_exec($curl);
curl_close($curl);
return json_decode($paypalSubscriptionTxns);
}
- Labels:
-
API
-
Express Checkout
-
REST
-
SDK
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- can we assign a unique detail to every subscription creation? in NVP/SOAP APIs
- I want to implement subscription functionality. in REST APIs
- I need to integrate a recurring payment with a variable for a pay-as-you-go product in REST APIs
- Subscription notifications in PayPal Reporting
- Mandatory Account Creation Hindering Customer Experience in REST APIs