Cart Credits Redemption API
A simplified API for applying store credits to orders in custom checkout flows or POS integrations. This endpoint handles credit reservation and provides transaction details for order attributes.
Endpoint
Property | Value |
URL |
|
Method |
|
Content-Type |
|
Parameters
Parameter | Type | Required | Description |
| integer | Yes | Shopify customer ID |
| integer | Yes | Same as customer_id (compatibility) |
| string | Yes | Customer email address |
| integer | Yes | Cart total in whole units (e.g., 140 for $140) |
| number | Yes | Store credits to redeem (e.g., 20 for $20) |
| integer | Yes | Fixed value: |
| integer | Yes | Fixed value: |
Request Example
curl -X POST "https://your-store.myshopify.com/apps/subscribfy-api/checkout/store-credits/use" \ -d "customer_id=6664481865927" \ -d "cid=6664481865927" \ -d "customer_email=customer@example.com" \ -d "cart_total=140" \ -d "st=20" \ -d "exm=5" \ -d "for_pass_stores=4633169"
Response
Success Response
{
"_exm_st_amount": -12,
"_exm_st_cid": 6664481865927,
"_exm_st_id": 2314674,
"_exm_st_key": "PVT",
"_exm_st_t": 1740412734
}
Response Fields
Field | Type | Description |
| integer | Validated credit amount (negative value) |
| integer | Shopify customer ID |
| integer | Store credit transaction ID |
| string | Transaction key (internal use) |
| integer | Unix timestamp of transaction |
Order Attributes
After a successful API response, add these attributes to the Shopify order for Subscribfy to process the redemption:
Attribute | Value |
|
|
| Absolute value of |
| Value of |
Example Order Attributes
{
"subscribfy_store_credits_code": "StoreCredits",
"subscribfy_store_credits": 12,
"subscribfy_store_credits_id": 2314674
}
Code Examples
JavaScript
async function redeemStoreCredits(customerId, email, cartTotal, creditAmount) {
const store = 'your-store.myshopify.com'; const response = await fetch(
`https://${store}/apps/subscribfy-api/checkout/store-credits/use`,
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
customer_id: customerId,
cid: customerId,
customer_email: email,
cart_total: cartTotal,
st: creditAmount,
exm: 5,
for_pass_stores: 4633169
})
}
); const data = await response.json(); if (data._exm_st_amount) {
// Store these for order attributes
return {
code: 'StoreCredits',
amount: Math.abs(data._exm_st_amount),
id: data._exm_st_id
};
} throw new Error('Failed to redeem credits');
}// Usage
const redemption = await redeemStoreCredits(
6664481865927,
'customer@example.com',
140,
20
);console.log(`Redeemed: $${redemption.amount}`);// Add to order attributes when creating order
const orderAttributes = {
subscribfy_store_credits_code: redemption.code,
subscribfy_store_credits: redemption.amount,
subscribfy_store_credits_id: redemption.id
};
PHP
function redeemStoreCredits($customerId, $email, $cartTotal, $creditAmount) {
$store = 'your-store.myshopify.com';
$url = "https://{$store}/apps/subscribfy-api/checkout/store-credits/use"; $ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query([
'customer_id' => $customerId,
'cid' => $customerId,
'customer_email' => $email,
'cart_total' => $cartTotal,
'st' => $creditAmount,
'exm' => 5,
'for_pass_stores' => 4633169
]),
CURLOPT_RETURNTRANSFER => true
]); $response = curl_exec($ch);
curl_close($ch); $data = json_decode($response, true); if (!empty($data['_exm_st_amount'])) {
return [
'code' => 'StoreCredits',
'amount' => abs($data['_exm_st_amount']),
'id' => $data['_exm_st_id']
];
} throw new Exception('Failed to redeem credits');
}// Usage
$redemption = redeemStoreCredits(
6664481865927,
'customer@example.com',
140,
20
);// Add to Shopify order attributes
$orderAttributes = [
'subscribfy_store_credits_code' => $redemption['code'],
'subscribfy_store_credits' => $redemption['amount'],
'subscribfy_store_credits_id' => $redemption['id']
];
Python
import requestsdef redeem_store_credits(customer_id, email, cart_total, credit_amount):
store = 'your-store.myshopify.com'
url = f'https://{store}/apps/subscribfy-api/checkout/store-credits/use' response = requests.post(url, data={
'customer_id': customer_id,
'cid': customer_id,
'customer_email': email,
'cart_total': cart_total,
'st': credit_amount,
'exm': 5,
'for_pass_stores': 4633169
}) data = response.json() if data.get('_exm_st_amount'):
return {
'code': 'StoreCredits',
'amount': abs(data['_exm_st_amount']),
'id': data['_exm_st_id']
} raise Exception('Failed to redeem credits')# Usage
redemption = redeem_store_credits(
6664481865927,
'customer@example.com',
140,
20
)# Add to order attributes
order_attributes = {
'subscribfy_store_credits_code': redemption['code'],
'subscribfy_store_credits': redemption['amount'],
'subscribfy_store_credits_id': redemption['id']
}
Customer Balance Metafield
You can display the customer's available balance using Liquid:
{% if customer.metafields.exison.exison_st %}
<p>Available Store Credits: $##{{ customer.metafields.exison.exison_st }}</p>
{% endif %}
Important Notes
stis positive - Request the amount to redeem as a positive number_exm_st_amountis negative - Response returns negative value; use absolute value for order attributesFixed parameters - Always include
exm=5andfor_pass_stores=4633169Amount validation - API validates and may return less than requested if balance is insufficient
Order completion required - Credits are reserved until order is completed or abandoned
Flow Diagram
Customer enters credit amount
↓
Call API with parameters
↓
API validates and reserves credits
↓
Store response values
↓
Add attributes to Shopify order
↓
Order completes → Credits deducted
OR
Order abandoned → Credits released
Error Handling
If the API returns an error or empty response:
Verify customer_id and email match
Check customer has sufficient balance
Ensure all required parameters are included
Verify the store domain is correct