Skip to content

Add Payment Method

Add a new payment method using Stripe.

Endpoint

INFO

POST /api/v1/client/payment-methods

Headers

HeaderValueRequired
Content-Typeapplication/jsonYes
Acceptapplication/jsonYes
AuthorizationBearer {token}Yes
X-Agency-Signature{signature}Yes

Request Body

ParameterTypeRequiredDescription
payment_method_idstringYesStripe PaymentMethod ID
set_defaultbooleanNoSet 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

Daakey Car Sharing Platform