If you are using ByBits' Stripe payment integration you can use the payments endpoint to carry out tasks.

Adding a new card

To add a new card you can now use the Stripe Elements card entry in your frontend with stripe.createPaymentMethod(). This is similar to taking a first time payment using confirmCardPayment() for new business.

stripe.createPaymentMethod({
    type: 'card',
    card: cardElement,
  })
  .then(function(result) {
    // Handle result.error or result.paymentMethod
  });

You should get a response with the payment method id at the top.

{
    "id": "pm_1JcSrJErCACt4akxh8NCtSfQ",
    "object": "payment_method",
    ...
}

Then make a request to the by bits api to the POST /payments endpoint using the following body:

{
   "type": "ADD_NEW_PAYMENT_METHOD",
   "product_reference": "by_bits_usage",
   "policy_reference": "latin-shadow-karma",
   "payment_method_id": "pm_1JcSrJErCACt4akxh8NCtSfQ"
}

If successful, you should receive a 200 response and confirmation of the payment_method_id.

{
    "payment_method_id": "pm_1JcSrJErCACt4akxh8NCtSfQ"
}

You can also check on the customer’s page on Stripe's dashboard. You should see the new payment method set as the customer’s default card.

Get Payment Method

If a customer has more than one card, you may wish to show them a particular card depending on whether a new payment is being made, or you are refunding a previous payment.

If the refund property is set as true  in your request body, it will return the details of the original card that will then be used for the refund.

{
   "type": "GET_PAYMENT_METHOD",
   "product_reference": "by_bits_usage",
   "policy_reference": "latin-shadow-karma",
   "refund": true
}

If the refund property is set to false, or omitted, the default payment card will be returned.

Retrying a Failed Payment

You can retry a failed payment programatically with the RETRY_PAYMENT type. In the request body, use the policy_reference and the policy_version_reference of the associated with the failed payment.

{
    "type": "RETRY_PAYMENT",
    "product_reference": "by_bits_usage",
    "policy_reference": "latin-shadow-karma",
    "policy_version_reference": "06b956a9-0000-41a1-a736-b647af013124"
}