Validate a promotion code
curl --request POST \
--url https://api.paybridgenp.com/v1/billing/promotion-codes/validate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "LAUNCH50",
"customerId": "<string>",
"planId": "<string>",
"amount": 123
}
'import requests
url = "https://api.paybridgenp.com/v1/billing/promotion-codes/validate"
payload = {
"code": "LAUNCH50",
"customerId": "<string>",
"planId": "<string>",
"amount": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({code: 'LAUNCH50', customerId: '<string>', planId: '<string>', amount: 123})
};
fetch('https://api.paybridgenp.com/v1/billing/promotion-codes/validate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.paybridgenp.com/v1/billing/promotion-codes/validate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => 'LAUNCH50',
'customerId' => '<string>',
'planId' => '<string>',
'amount' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.paybridgenp.com/v1/billing/promotion-codes/validate"
payload := strings.NewReader("{\n \"code\": \"LAUNCH50\",\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\",\n \"amount\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.paybridgenp.com/v1/billing/promotion-codes/validate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"LAUNCH50\",\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\",\n \"amount\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.paybridgenp.com/v1/billing/promotion-codes/validate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"LAUNCH50\",\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\",\n \"amount\": 123\n}"
response = http.request(request)
puts response.read_body{
"valid": true,
"coupon": {
"id": "cpn_01j9x2k3m4n5p6q7r8s9t0u1v2",
"object": "coupon",
"code": "WELCOME10",
"name": "Welcome 10%",
"percent_off": 10,
"amount_off": 123,
"currency": "NPR",
"duration_in_cycles": 123,
"max_redemptions": 123,
"redeemed_count": 0,
"redeem_by": "2023-11-07T05:31:56Z",
"applies_to_plan_ids": [
"<string>"
],
"active": true,
"metadata": {},
"livemode": true
},
"discount_preview": {
"amount_off": 123,
"amount_after_discount": 123
},
"promotion_code": {
"id": "promo_01j9x2k3m4n5p6q7r8s9t0u1v2",
"object": "promotion_code",
"code": "LAUNCH50",
"coupon_id": "cpn_01j9x2k3m4n5p6q7r8s9t0u1v2",
"active": true,
"max_redemptions": 123,
"redeemed_count": 0,
"expires_at": "2023-11-07T05:31:56Z",
"first_time_transaction": true,
"minimum_amount": 123,
"customer_ids": [
"<string>"
],
"metadata": {},
"livemode": true
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"request_id": "req_2Je91NlWKuXkdXUJOK9gaHNW",
"suspension": {
"suspended_at": "2023-11-07T05:31:56Z",
"reason": "<string>"
},
"pause": {
"paused_at": "2023-11-07T05:31:56Z",
"reason": "<string>"
}
}
}Promotion codes
Validate a promotion code
Checks whether a code is redeemable (active, not expired, redemption + customer + minimum-amount restrictions) and previews the discount. Does not consume a redemption.
POST
/
v1
/
billing
/
promotion-codes
/
validate
Validate a promotion code
curl --request POST \
--url https://api.paybridgenp.com/v1/billing/promotion-codes/validate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "LAUNCH50",
"customerId": "<string>",
"planId": "<string>",
"amount": 123
}
'import requests
url = "https://api.paybridgenp.com/v1/billing/promotion-codes/validate"
payload = {
"code": "LAUNCH50",
"customerId": "<string>",
"planId": "<string>",
"amount": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({code: 'LAUNCH50', customerId: '<string>', planId: '<string>', amount: 123})
};
fetch('https://api.paybridgenp.com/v1/billing/promotion-codes/validate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.paybridgenp.com/v1/billing/promotion-codes/validate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => 'LAUNCH50',
'customerId' => '<string>',
'planId' => '<string>',
'amount' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.paybridgenp.com/v1/billing/promotion-codes/validate"
payload := strings.NewReader("{\n \"code\": \"LAUNCH50\",\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\",\n \"amount\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.paybridgenp.com/v1/billing/promotion-codes/validate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"LAUNCH50\",\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\",\n \"amount\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.paybridgenp.com/v1/billing/promotion-codes/validate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"LAUNCH50\",\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\",\n \"amount\": 123\n}"
response = http.request(request)
puts response.read_body{
"valid": true,
"coupon": {
"id": "cpn_01j9x2k3m4n5p6q7r8s9t0u1v2",
"object": "coupon",
"code": "WELCOME10",
"name": "Welcome 10%",
"percent_off": 10,
"amount_off": 123,
"currency": "NPR",
"duration_in_cycles": 123,
"max_redemptions": 123,
"redeemed_count": 0,
"redeem_by": "2023-11-07T05:31:56Z",
"applies_to_plan_ids": [
"<string>"
],
"active": true,
"metadata": {},
"livemode": true
},
"discount_preview": {
"amount_off": 123,
"amount_after_discount": 123
},
"promotion_code": {
"id": "promo_01j9x2k3m4n5p6q7r8s9t0u1v2",
"object": "promotion_code",
"code": "LAUNCH50",
"coupon_id": "cpn_01j9x2k3m4n5p6q7r8s9t0u1v2",
"active": true,
"max_redemptions": 123,
"redeemed_count": 0,
"expires_at": "2023-11-07T05:31:56Z",
"first_time_transaction": true,
"minimum_amount": 123,
"customer_ids": [
"<string>"
],
"metadata": {},
"livemode": true
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"request_id": "req_2Je91NlWKuXkdXUJOK9gaHNW",
"suspension": {
"suspended_at": "2023-11-07T05:31:56Z",
"reason": "<string>"
},
"pause": {
"paused_at": "2023-11-07T05:31:56Z",
"reason": "<string>"
}
}
}Authorizations
Your PayBridgeNP API key. Obtain one from the dashboard under Settings → API Keys. Prefix: sk_test_ for testing, sk_live_ for production.
Body
application/json
Response
Validation result. On invalid codes the API still returns 200 with valid: false and a reason.
Was this page helpful?
⌘I