Created
July 5, 2018 06:37
-
-
Save dirkeinecke/ca36f443251356bb4a95a6085074933b to your computer and use it in GitHub Desktop.
Paddle API - Create coupon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Documentation: https://paddle.com/docs/api-generate-coupon/ | |
$url = 'https://vendors.paddle.com/api/2.1/product/create_coupon'; | |
$post = (array) array( | |
'vendor_id' => (int) 12345, | |
'vendor_auth_code' => (string) 'abc1234...', | |
'coupon_prefix' => (string) 'TEST-', | |
'num_coupons' => (int) 5, | |
'description' => (string) 'Coupons created via the API.', | |
'coupon_type' => (string) 'product', | |
'product_ids' => (string) '510509,511520,508649', | |
'discount_type' => (string) 'percentage', | |
'discount_amount' => (int) 25, | |
'allowed_uses' => (int) 1, | |
'group' => (string) 'My-Test-Group', | |
); | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl, CURLOPT_POST, 1); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $post); | |
curl_setopt($curl, CURLOPT_FAILONERROR, true); | |
$json = curl_exec($curl); | |
// Error handling | |
if (curl_error($curl) !== '') { | |
echo 'Curl error: '.curl_error($curl); | |
} | |
curl_close ($curl); | |
$data = json_decode($json, true); | |
// Error handling | |
if (json_last_error() !== 0) { | |
echo json_last_error_msg(); | |
} | |
print_r($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment