Add Payment Method
Add a new payment method using Stripe.
Endpoint
INFO
POST /api/v1/client/payment-methods
Headers
| Header | Value | Required |
|---|---|---|
Content-Type | application/json | Yes |
Accept | application/json | Yes |
Authorization | Bearer {token} | Yes |
X-Agency-Signature | {signature} | Yes |
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
payment_method_id | string | Yes | Stripe PaymentMethod ID |
set_default | boolean | No | Set as default method (default: false) |
Example Request
bash
curl -X POST https://api.daakey.com/api/v1/client/payment-methods \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer {token}" \
-H "X-Agency-Signature: {signature}" \
-d '{
"payment_method_id": "pm_1234567890abcdef",
"set_default": true
}'Response
Success (201)
json
{
"success": true,
"message": "Payment method added",
"data": {
"id": 3,
"type": "card",
"brand": "visa",
"last_four": "4242",
"exp_month": 12,
"exp_year": 2025,
"is_default": true,
"created_at": "2024-01-15T00:00:00Z"
},
"meta": {
"agency_id": 123,
"agency_code": "AGENCY123"
},
"request_id": "uuid",
"timestamp": "2024-01-01T00:00:00.000Z"
}Error (422)
json
{
"success": false,
"message": "Validation failed",
"errors": {
"payment_method_id": ["The payment method ID is invalid."]
},
"data": null,
"request_id": "uuid",
"timestamp": "2024-01-01T00:00:00.000Z"
}Stripe Integration
The payment_method_id is obtained from Stripe.js or Stripe Mobile SDKs:
JavaScript Example
javascript
const stripe = Stripe('pk_live_xxx');
const elements = stripe.elements();
const cardElement = elements.create('card');
const { paymentMethod, error } = await stripe.createPaymentMethod({
type: 'card',
card: cardElement,
});
if (paymentMethod) {
// Send paymentMethod.id to the API
await api.post('/payment-methods', {
payment_method_id: paymentMethod.id,
set_default: true
});
}Notes
- Payment methods are stored securely via Stripe
- The first payment method added is automatically set as default
- Card details are never stored on Daakey servers