API Reference
Integration Example
End-to-end integration walkthrough.
Integration Example
A complete, end-to-end integration walkthrough in multiple languages.
Complete Integration
cURL
# 1. Fetch available plans
curl -X GET \
"https://cadence-api.pleasurebyplease.com/plans/list?page=1&pageSize=10" \
-H "X-Api-Key: {your-api-key}" \
-H "X-Api-Secret: {your-api-secret}"
# 2. Initialize checkout with a selected plan
curl -X POST \
"https://cadence-api.pleasurebyplease.com/checkout/initialize" \
-H "X-Api-Key: {your-api-key}" \
-H "X-Api-Secret: {your-api-secret}" \
-H "Content-Type: application/json" \
-d '{
"pricingPlanReferenceCode": "plan_abc123",
"callbackUrl": "https://yoursite.com/checkout/callback",
"name": "John",
"surname": "Doe",
"email": "john@example.com",
"gsmNumber": "+905551234567",
"identityNumber": "12345678901"
}'
# 3. The checkoutFormContent in response contains HTML/JS
# Render it in your page for customer to complete paymentTypeScript
import type {
Plan,
PlansListResponse,
CheckoutInitializeRequest,
CheckoutInitializeResponse
} from './types'; // See TypeScript Types tab
// Create API client
const createClient = (apiKey: string, apiSecret: string, baseUrl: string) => {
const headers = {
'X-Api-Key': apiKey,
'X-Api-Secret': apiSecret,
'Content-Type': 'application/json',
};
return {
async getPlans(page = 1, pageSize = 10): Promise<PlansListResponse> {
const res = await fetch(
`${baseUrl}/plans/list?page=${page}&pageSize=${pageSize}`,
{ headers }
);
return res.json();
},
async initializeCheckout(
data: CheckoutInitializeRequest
): Promise<CheckoutInitializeResponse> {
const res = await fetch(`${baseUrl}/checkout/initialize`, {
method: 'POST',
headers,
body: JSON.stringify(data),
});
return res.json();
},
};
};
// Usage
const client = createClient(
'{your-api-key}',
'{your-api-secret}',
'https://cadence-api.pleasurebyplease.com'
);
// 1. Fetch and display plans
const { data: plans } = await client.getPlans();
console.log('Available plans:', plans.map(p => p.name));
// 2. User selects a plan, initialize checkout
const selectedPlan = plans[0];
const checkout = await client.initializeCheckout({
pricingPlanReferenceCode: selectedPlan.referenceCode,
callbackUrl: 'https://yoursite.com/checkout/callback',
name: 'John',
surname: 'Doe',
email: 'john@example.com',
gsmNumber: '+905551234567',
identityNumber: '12345678901',
});
// 3. Render checkout form
if (checkout.status === 'success' && checkout.checkoutFormContent) {
document.getElementById('checkout-container')!.innerHTML =
checkout.checkoutFormContent;
}Node.js
// Node.js / Express integration example
const express = require('express');
const app = express();
const API_KEY = '{your-api-key}';
const API_SECRET = '{your-api-secret}';
const API_URL = 'https://cadence-api.pleasurebyplease.com';
// Helper to make API calls
async function cadenceApi(endpoint, options = {}) {
const res = await fetch(`${API_URL}${endpoint}`, {
...options,
headers: {
'X-Api-Key': API_KEY,
'X-Api-Secret': API_SECRET,
'Content-Type': 'application/json',
...options.headers,
},
});
return res.json();
}
// Route to display pricing page
app.get('/pricing', async (req, res) => {
const plans = await cadenceApi('/plans/list?page=1&pageSize=10');
res.render('pricing', { plans: plans.data });
});
// Route to start checkout
app.post('/subscribe', async (req, res) => {
const { planRef, ...customer } = req.body;
const checkout = await cadenceApi('/checkout/initialize', {
method: 'POST',
body: JSON.stringify({
pricingPlanReferenceCode: planRef,
callbackUrl: 'https://yoursite.com/checkout/callback',
...customer,
}),
});
if (checkout.status === 'success') {
res.render('checkout', {
formContent: checkout.checkoutFormContent
});
} else {
res.redirect('/error');
}
});
app.listen(3000);PHP
<?php
// Cadence API Client Class
class CadenceClient {
private $baseUrl;
private $apiKey;
private $apiSecret;
public function __construct($apiKey, $apiSecret, $baseUrl = 'https://cadence-api.pleasurebyplease.com') {
$this->apiKey = $apiKey;
$this->apiSecret = $apiSecret;
$this->baseUrl = $baseUrl;
}
private function request($endpoint, $method = 'GET', $data = null) {
$ch = curl_init();
$headers = [
'X-Api-Key: ' . $this->apiKey,
'X-Api-Secret: ' . $this->apiSecret,
'Content-Type: application/json'
];
curl_setopt_array($ch, [
CURLOPT_URL => $this->baseUrl . $endpoint,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers
]);
if ($method === 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
public function getPlans($page = 1, $pageSize = 10) {
return $this->request("/plans/list?page={$page}&pageSize={$pageSize}");
}
public function initializeCheckout($data) {
return $this->request('/checkout/initialize', 'POST', $data);
}
}
// Usage
$client = new CadenceClient('{your-api-key}', '{your-api-secret}');
// Get plans
$plans = $client->getPlans();
// Initialize checkout
$checkout = $client->initializeCheckout([
'pricingPlanReferenceCode' => $plans['data'][0]['referenceCode'],
'callbackUrl' => 'https://yoursite.com/checkout/callback',
'name' => 'John',
'surname' => 'Doe',
'email' => 'john@example.com',
'gsmNumber' => '+905551234567',
'identityNumber' => '12345678901'
]);
if ($checkout['status'] === 'success') {
echo $checkout['checkoutFormContent'];
}
?>Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
type CadenceClient struct {
BaseURL string
ApiKey string
ApiSecret string
Client *http.Client
}
type Plan struct {
ReferenceCode string `json:"referenceCode"`
Name string `json:"name"`
Price string `json:"price"`
CurrencyCode string `json:"currencyCode"`
PaymentInterval string `json:"paymentInterval"`
PaymentIntervalCount int `json:"paymentIntervalCount"`
}
type PlansResponse struct {
Data []Plan `json:"data"`
Total int `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
TotalPages int `json:"totalPages"`
}
func NewCadenceClient(apiKey, apiSecret string) *CadenceClient {
return &CadenceClient{
BaseURL: "https://cadence-api.pleasurebyplease.com",
ApiKey: apiKey,
ApiSecret: apiSecret,
Client: &http.Client{},
}
}
func (c *CadenceClient) GetPlans(page, pageSize int) (*PlansResponse, error) {
url := fmt.Sprintf("%s/plans/list?page=%d&pageSize=%d",
c.BaseURL, page, pageSize)
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("X-Api-Key", c.ApiKey)
req.Header.Set("X-Api-Secret", c.ApiSecret)
resp, err := c.Client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result PlansResponse
json.NewDecoder(resp.Body).Decode(&result)
return &result, nil
}
func main() {
client := NewCadenceClient("{your-api-key}", "{your-api-secret}")
plans, _ := client.GetPlans(1, 10)
for _, plan := range plans.Data {
fmt.Printf("Plan: %s - %s %s\n",
plan.Name, plan.Price, plan.CurrencyCode)
}
}Ruby
require 'net/http'
require 'json'
class CadenceClient
def initialize(api_key, api_secret, base_url: 'https://cadence-api.pleasurebyplease.com')
@api_key = api_key
@api_secret = api_secret
@base_url = base_url
end
def get_plans(page: 1, page_size: 10)
uri = URI("#{@base_url}/plans/list?page=#{page}&pageSize=#{page_size}")
request(:get, uri)
end
def initialize_checkout(data)
uri = URI("#{@base_url}/checkout/initialize")
request(:post, uri, data)
end
private
def request(method, uri, body = nil)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
request = case method
when :get then Net::HTTP::Get.new(uri)
when :post then Net::HTTP::Post.new(uri)
end
request['X-Api-Key'] = @api_key
request['X-Api-Secret'] = @api_secret
request['Content-Type'] = 'application/json'
request.body = body.to_json if body
response = http.request(request)
JSON.parse(response.body)
end
end
# Usage
client = CadenceClient.new('{your-api-key}', '{your-api-secret}')
# Get plans
plans = client.get_plans
puts "Available plans:"
plans['data'].each { |p| puts " - #{p['name']}: #{p['price']} #{p['currencyCode']}" }
# Initialize checkout
checkout = client.initialize_checkout(
pricingPlanReferenceCode: plans['data'][0]['referenceCode'],
callbackUrl: 'https://yoursite.com/checkout/callback',
name: 'John',
surname: 'Doe',
email: 'john@example.com',
gsmNumber: '+905551234567',
identityNumber: '12345678901'
)
puts checkout['checkoutFormContent'] if checkout['status'] == 'success'Python
import requests
from dataclasses import dataclass
from typing import List, Optional
@dataclass
class Plan:
referenceCode: str
name: str
price: str
currencyCode: str
paymentInterval: str
paymentIntervalCount: int
class CadenceClient:
def __init__(self, api_key: str, api_secret: str, base_url: str = 'https://cadence-api.pleasurebyplease.com'):
self.base_url = base_url
self.headers = {
'X-Api-Key': api_key,
'X-Api-Secret': api_secret,
'Content-Type': 'application/json'
}
def get_plans(self, page: int = 1, page_size: int = 10) -> dict:
response = requests.get(
f'{self.base_url}/plans/list',
params={'page': page, 'pageSize': page_size},
headers=self.headers
)
return response.json()
def initialize_checkout(self, data: dict) -> dict:
response = requests.post(
f'{self.base_url}/checkout/initialize',
headers=self.headers,
json=data
)
return response.json()
# Usage
client = CadenceClient('{your-api-key}', '{your-api-secret}')
# Get plans
plans_response = client.get_plans()
plans = plans_response['data']
print(f"Available plans: {[p['name'] for p in plans]}")
# Initialize checkout
checkout = client.initialize_checkout({
'pricingPlanReferenceCode': plans[0]['referenceCode'],
'callbackUrl': 'https://yoursite.com/checkout/callback',
'name': 'John',
'surname': 'Doe',
'email': 'john@example.com',
'gsmNumber': '+905551234567',
'identityNumber': '12345678901'
})
if checkout['status'] == 'success':
print(checkout['checkoutFormContent'])