Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
//Checks if user a Pro. If Pro send also his last/next payment info.
$checking_user_email = json_decode(file_get_contents('php://input'))->email;
$product_id = json_decode(file_get_contents('php://input'))->productID;
curl_init('https://vendors.paddle.com/api/2.0/subscription/users');
//https://paddle.com/docs/api-list-users/
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://vendors.paddle.com/api/2.0/subscription/users");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "vendor_id=11111&vendor_auth_code=11111111111111111111111111&plan=" . $product_id);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$users = json_decode($result)->response;
$is_pro = 'false';
$last_payment = null;
$next_payment = null;
$subscription_id = null;
foreach($users as $user) {
if($user->user_email === $checking_user_email && $user->state === 'active'){
// If the given email is in the subscribers list (means he paid), we tell it back.
// We also send billing info.
$is_pro = 'true';
$last_payment = $user->last_payment;
$next_payment = $user->next_payment;
$subscription_id = $user->subscription_id;
}
}
echo json_encode(array("isPro" => $is_pro, "lastPayment" => $last_payment, "nextPayment" => $next_payment, "subscriptionID" => $subscription_id));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.