Integration Guide
Everything you need to accept payments on your website in minutes.
1 Installation
Add the RR Pay SDK to your website by including this script just before the closing </body> tag:
<script src="https://pay.yourdomain.com/sdk/rrpay.js"></script>
2 Initialize SDK
Initialize the SDK with your merchant key:
RRPay.init('pk_live_YOUR_MERCHANT_KEY');
Use pk_test_... for development and pk_live_... for production.
3 Accept Payments
One-Time Payment
<div id="pay-button"></div>
<script>
RRPay.init('pk_live_YOUR_KEY');
RRPay.createButton('#pay-button', {
amount: 99.99,
description: 'Product Name',
onSuccess: function(result) {
console.log('Paid!', result.sessionId);
window.location.href = '/thank-you';
}
});
</script>
Subscription (Recurring)
<div id="subscribe-button"></div>
<script>
RRPay.init('pk_live_YOUR_KEY');
RRPay.createSubscriptionButton('#subscribe-button', {
amount: 29.99,
interval: 'month',
trialDays: 14,
onSuccess: function(result) {
console.log('Subscribed!', result.subscriptionId);
console.log('Status:', result.status); // 'trialing' or 'active'
}
});
</script>
Billing Intervals
Configure how often customers are billed with flexible interval options:
| Interval | Code | Example |
|---|---|---|
| Weekly | interval: 'week' |
$9.99/week |
| Monthly | interval: 'month' |
$29.99/month |
| Yearly | interval: 'year' |
$299/year |
| Bi-weekly | interval: 'week', intervalCount: 2 |
$19.99 every 2 weeks |
| Quarterly | interval: 'month', intervalCount: 3 |
$79.99 every 3 months |
Free Trials
Offer customers a free trial period before charging:
RRPay.createSubscriptionButton('#btn', {
amount: 49.99,
interval: 'month',
trialDays: 14 // 14-day free trial
});
- Customer enters card details (validated, not charged)
- Trial period begins immediately
- First charge happens automatically when trial ends
- Customer can cancel anytime during trial
Setup Fees
Charge a one-time setup fee along with the recurring subscription:
RRPay.createSubscriptionButton('#btn', {
amount: 49.99, // Monthly recurring amount
interval: 'month',
setupFee: 99.00 // One-time fee charged today
});
Managing Subscriptions
// Get subscription status
const sub = await RRPay.getSubscription('sub_abc123');
console.log(sub.status); // 'active', 'trialing', 'canceled', etc.
// Cancel subscription (at end of billing period)
await RRPay.cancelSubscription('sub_abc123');
// Cancel immediately
await RRPay.cancelSubscription('sub_abc123', { cancelAtPeriodEnd: false });
// Update payment method (opens modal)
await RRPay.updatePaymentMethod('sub_abc123');
API Options
One-Time Payment Options
| Option | Type | Description |
|---|---|---|
amount | number | Amount in dollars (e.g., 99.99) |
description | string | What the payment is for |
customerEmail | string | Pre-fill email field |
orderId | string | Your order/invoice ID |
metadata | object | Custom data returned in webhooks |
onSuccess | function | Called on successful payment |
onError | function | Called on failure/cancel |
Subscription Options
| Option | Type | Description |
|---|---|---|
amount | number | Amount per billing cycle |
interval | string | 'week', 'month', or 'year' |
intervalCount | number | For custom intervals (default: 1) |
trialDays | number | Free trial period in days |
setupFee | number | One-time setup fee |
planId | string | Your plan identifier |
customerEmail | string | Pre-fill email |
metadata | object | Custom data |
onSuccess | function | Called on success |
onError | function | Called on failure |
Webhooks Optional
Receive real-time notifications when payment events occur. Contact us to configure your webhook URL.
Event Types
// One-time payment completed
{
"type": "checkout.completed",
"data": {
"sessionId": "cs_abc123",
"orderId": "order_456",
"amount": 9999,
"status": "complete"
}
}
// Subscription created
{
"type": "subscription.created",
"data": {
"subscriptionId": "sub_xyz789",
"status": "trialing",
"currentPeriodEnd": "2024-02-15T00:00:00Z"
}
}
// Recurring payment successful
{
"type": "invoice.paid",
"data": {
"subscriptionId": "sub_xyz789",
"amount": 2999
}
}
// Payment failed
{
"type": "invoice.payment_failed",
"data": {
"subscriptionId": "sub_xyz789",
"error": "Card declined"
}
}
Testing
Use test credentials to verify your integration before going live:
Test Credentials
Complete Example
Here's a full working example you can copy and customize:
<!DOCTYPE html>
<html>
<head>
<title>Checkout</title>
</head>
<body>
<h1>Pro Plan - $29.99/month</h1>
<p>Start with a 14-day free trial</p>
<div id="subscribe-btn"></div>
<script src="https://pay.yourdomain.com/sdk/rrpay.js"></script>
<script>
RRPay.init('pk_live_YOUR_KEY');
RRPay.createSubscriptionButton('#subscribe-btn', {
amount: 29.99,
interval: 'month',
trialDays: 14,
customerEmail: 'customer@example.com',
onSuccess: function(result) {
// Subscription created!
console.log('ID:', result.subscriptionId);
console.log('Status:', result.status);
// Redirect to your app
window.location.href = '/welcome?sub=' + result.subscriptionId;
},
onError: function(error) {
console.log('Cancelled or failed');
}
});
</script>
</body>
</html>
Need Help?
We're here to help you get integrated quickly:
Common Questions
How much do I earn?
Estimated earnings:
- Traditional processing: ~$97 per $10,000 in volume
- "Fees Included" program: ~$140 per $10,000 in volume
Understanding the fees
When a customer pays with a card, the fee has three parts:
| Component | Who sets it | Negotiable? |
|---|---|---|
| Interchange | Card networks (Visa/MC) & issuing banks | No |
| Card brand fees | Visa/Mastercard | No |
| Processor markup | The processor | Yes |
Why rates vary
Your actual costs depend on card type:
- Basic credit cards: ~1.8% - 2.1%
- Rewards/premium cards: ~2.0% - 2.6%
- Corporate cards: Even higher
Plus a small per-transaction fee.
Recommended pricing
This is competitive and provides healthy margin. For "Fees Included" (fees passed to customer), you can charge slightly higher.
Bottom line: Sell on service quality, not price. Most of the fee goes to card networks - processor margins are thin.