Migrated from Redmine #1396 | Author: JM Kuizon
Status: New | Priority: High, I’m very impatient | Created: 2025-03-06
Hi,
I’m experiencing an issue with the SB Pay payment API integration for our membership system. After a successful payment, we’re seeing duplicate payment records in the SB Pay dashboard.
h2. Current Implementation Flow
- First, I create a membership instance
await makeSimplyBookApiRequest(`/admin/memberships/make-membership-instance`, ApiMethods.POST, {
membership_id: membershipId,
period_start: new Date().toISOString().split('T')[0],
is_invoice_needed: 1,
payment_processor: 'delay',
amount,
clients: [clientId],
});
- Second, I create a payment link via SB Pay initialize payment API (SBPay.me - Single place for all payment processors) using the invoice created when I was creating a membership instance.
Here is the code for it:
async initializePayment(paymentData: InitializePaymentDto) {
try {
const result = await this.simplyBookPayService.initializePayment({
...paymentData,
paymentSystem: 'stripe',
currency: 'SGD',
timestamp: new Date().toISOString().replace('Z', '+00:00'),
algo: 'sha256',
autoMakeInvoiceOnReceivePayment: true,
});
return result;
} catch (error) {
throw new Error(`Failed to initialize payment: ${error.message}`);
}
}
And here is the sample paymentData for it:
{
"referenceId": "312",
"description": "Payment for membership of Reed Diaz",
"lines": [
{
"name": "Commercial Organization (03.06.2025 - 03.06.2026)",
"qty": 1,
"price": 8000,
"amount": 8000
},
{
"name": "Additional Seats",
"description": "Additional seats for the membership",
"qty": 6,
"price": 300,
"amount": 1
}
],
"amount": 9,
"customer": {
"referenceId": "329",
"name": "Reed Diaz",
"email": "jm.kuizon+test25@symph.co",
"phone": "+6512313121311"
},
"callbacks": {
"returnUrl": "http://localhost:4200/account/create?strapiId=timpb4wjivpuqy6e3yob087y&clientId=329&membershipType=organisation",
"cancelUrl": "http://localhost:4200?cancel=true",
"failureUrl": "http://localhost:4200?error=true",
"successUrl": "http://localhost:4200?success=true"
}
}
- Lastly, I sent the link to the client and after paying there will be a duplicate data in the Payments in SBPay (click this for reference: https://drive.google.com/file/d/1g5Rpi3hr4VSqkKIONVeJdWqwnN6I5dbZ/view?usp=sharing)
h2. Issue
After a successful payment, I’m seeing duplicate entries in the SB Pay dashboard (screenshot: https://drive.google.com/file/d/1g5Rpi3hr4VSqkKIONVeJdWqwnN6I5dbZ/view?usp=sharing).
h2. Question
How can I properly update our existing membership instance as “paid” rather than creating new payment data? Is there a specific webhook or callback I should be implementing to handle successful payments?
I appreciate your assistance.
Thank you.