Card
Collect a card payment with a hosted payment link, as a one-time charge or a saved card for recurring charges.
This page shows how to collect payments from customers with a credit or debit card. There are two ways to charge a card:
card_token from Get saved cards and use it to charge the customer again. The customer does not re-enter their card details.You can also refund a card payment after it completes.
Gravv always charges card collections in US dollars. The amount is a USD amount, whatever currency you send. The customer record must have a phone number and a date of birth. The customer's address country decides whether cards are available. The request has no country field.
One-time charge
Send an Initiate a collection request call with card in source.methods. Send amount as a string with at most 2 decimal places. Gravv returns a payment_link in the response. Redirect your customer to this link to complete the payment:
The response looks like this:
Redirect the customer to payment_link. They enter their card details on Gravv's checkout page and complete the payment there. Gravv abandons a checkout that has no activity for 24 hours.
Recurring charge
A recurring charge uses the payment intent endpoints:
save_card set to true and receives a payment_link.Create a payment intent
Call the Create payment intent endpoint from your backend. Gravv looks up saved cards by client_customer_id, so use the same value for a customer every time:
The response contains a payment_link. Redirect the customer to this link to complete the payment. The link contains a secret for this payment, so send it only to the customer:
A payment intent expires 24 hours after you create it, and it allows at most 5 charge attempts. Its status is one of created, tokenized, requires_payment_method, requires_confirmation, requires_action, confirmed, processing, succeeded, failed, cancelled or expired. Create a new intent after a hard decline, after 5 attempts, or when the intent expires.
Charge a saved card
To charge the customer without redirecting them again:
card_token.card_token, and with the new intent's intent_id as payment_intent_id, pi_ prefix included.Billing fields are optional. Any field you omit falls back to the saved card's billing record, then to the customer record:
A successful charge returns status succeeded. When the issuer asks for 3D Secure, status is requires_action and the response has next_action_url. Send the customer to that URL to finish the payment. A declined charge returns HTTP 400 with a sentence such as The card has insufficient funds: payment declined.
You can charge a saved card at most 5 times in 24 hours, and each charge can be at most 3 times the card's first payment.
You can also make a recurring charge without a separate call to the Charge card endpoint. Pass the card_token in the card_token field when you call Create payment intent. Gravv charges the card at once. The response is HTTP 200 whatever the outcome, so check data.status:
| data.status | Meaning |
|---|---|
processing | The charge went through |
requires_action | The issuer asks for 3D Secure |
charge_failed | The charge failed. message has the reason |
Manage saved cards
Gravv stores card tokens on the customer record. Use these endpoints to read or remove them.
Get saved cards
Call the Get saved cards endpoint to list a customer's saved cards and their card_token values. customer_id is required:
data is an array of saved cards. You can charge only a card with is_active true. A card is inactive until its first payment settles.
Get saved card
Call the Get saved card endpoint to retrieve a single card by the id from the list:
The response looks like this. Ignore is_active in this response. It always reads false, and the endpoint returns only active cards:
is_expiring_soon is true when the card expires within 30 days.
Delete a saved card
Call the Delete saved card endpoint to remove a saved card. Send a JSON body with the card owner's customer_id and the card_token. Gravv deletes the card that card_token names. A request without a body fails with EOF:
The response looks like this. A token that matches no active card returns card already deleted:
Refund a card payment
You can refund a card collection (card, apple_pay or google_pay) to the payer's card once its transaction_status is completed. Each collection takes one refund, either the whole payment or part of it. Bank transfer collections cannot be refunded.
Example. A customer paid 50.00 USD for two items and returns one that cost 25.00 USD. You refund 2500 cents. The collection moves to refund_pending, then to refunded when the refund finishes. You cannot refund the other 25.00 USD later, because the collection has used its one refund.
Start a refund
Call the Refund a collection endpoint with the collection's transaction_id. Leave out amount_cents to refund the whole payment. Send amount_cents in US cents for a partial refund:
The response looks like this:
Keep refund_id. You need it to retry a failed refund.
Track the refund
status succeeded means the refund is done and the collection is refunded. pending means the refund is in progress and the collection is refund_pending. Gravv sends a collection event at each step:
| Event type | onramp_status | Meaning |
|---|---|---|
collection.status.refund_pending | refund_initiated | The refund started |
collection.status.refunded | refunded | The money is on its way back to the card |
collection.status.failed | refund_failed | The refund was declined |
On these events, metadata holds refund_id and refund_status. To check a refund without waiting for an event, call the List refunds endpoint:
Retry a failed refund
When a refund fails, the collection's onramp_status is refund_failed. Call the Retry a refund endpoint with the collection's transaction_id and the refund_id. The response and events are the same as for a new refund:
If the refund was declined before it was created, List refunds returns no refund and there is nothing to retry. Contact Gravv support to refund the payment.
| Error | Cause | What to do |
|---|---|---|
cannot perform 'refund_collection' in state '<status>': … | The collection is not completed, or it already has a refund | Check transaction_status with GET /v1/collections/{id} |
transaction is already being processed by another request | Another request is refunding the same collection | Wait for it, then check the collection |
cannot perform 'retry_refund' in state '<status>': … | The collection is not refund_failed | Retry only after a refund fails |
refund not found for this transaction: resource not found | The refund_id is not on this collection | Get the refund_id from List refunds |