Skip to main content
Card payments run through the processor’s hosted fields, either CyberSource Flex or Mastercard MPGS. The customer types the card number and security code into fields served by the processor, inside your page. Vestrapay never receives the card number or CVV, and neither do your servers, which keeps card data off your systems and reduces your PCI burden. Hosted checkout does all of this for you. This page is for teams building a custom pay screen with the access code.
If you use hosted checkout, you do not need anything on this page. Redirect to the checkout URL and verify the result. Read on only if you are building your own card form.

How a card payment flows

A card payment is a short state machine. You call one endpoint, read data.status from the response, and the status tells you what to do next.

Step by step

1

Initialise

Create the payment on your server. Keep data.accessCode and data.reference. Hand the access code, and only the access code, to your browser code.
2

Create a card session

From the browser, or from a checkout backend that holds the access code, ask Vestrapay to prepare the hosted fields.
The response says which processor is active in hostedCard.provider, which is cybersource or mpgs, and gives the configuration for it:
The values shown are illustrative. Always use the script URL and capture context the response gives you. Do not hard-code them.
3

Mount the hosted fields

CyberSource. Load hostedCard.scriptUrl, create the microform with new Flex(hostedCard.captureContext).microform(), and mount the number and security code fields only. Keep the expiry month and year as your own inputs. When the customer submits, call createToken({ expirationMonth, expirationYear }). The token it returns is a JWT, and it is what you send as sessionId on charge.MPGS. Load hostedCard.scriptUrl and mount Mastercard’s hosted fields against the session ID from the response.Whichever processor is active, only the processor sees the card number and CVV.
4

Charge

Send the session value and the browser details the issuer needs for 3-D Secure.
transientToken is accepted as an alias of sessionId for CyberSource. If you send neither, Vestrapay uses the token stored when the session was created.Fill browserDetails from the real browser: screen height and width, colour depth, whether Java is enabled, the language tag, and the time zone offset in minutes from new Date().getTimezoneOffset(). Send accurate values, because the issuer uses them when it assesses the risk of the payment.
5

Branch on data.status

The call returns HTTP 201 with an outer status of success even when the card is declined, because the call worked. The outcome is data.status.
A typical success response:
A failed attempt has the same shape with data.status set to failed and a data.message you can show to the customer.

3-D Secure after fingerprinting

Call authenticate only when charge returned data.status of fingerprint_required. No session ID is needed because it is already stored against the payment.
The response has the same shape as a charge. data.status is success, failed, or 3ds_required with data.threeDsHtml for the challenge. When the issuer challenges the customer, the challenge iframe posts back to Vestrapay’s 3-D Secure callback. That is not your callbackUrl. The callback page then notifies your page, which is the parent window, with a message:
Listen for that message on the window, check type, and then call verify through your server. As a fallback, also watch the checkout event checkout.completed on GET /v1/payment/checkout/events, in case the message is lost.

Constraints that matter

  • Card number and CVV go to the hosted fields only. Never build your own input for them.
  • Run the 3-D Secure challenge in an on-page iframe. Do not use window.open, because pop-up blockers and the loss of the message channel break the flow.
  • Keep the top-level window on your own checkout origin throughout 3-D Secure. Navigating away abandons the callback.
  • Call authenticate only after fingerprint_required. Calling it at any other time fails.
  • Processor sessions are single use. After a failed charge, create a new card session before the customer retries. Reusing the old one returns card.retry_session_required.
  • Each payment allows a limited number of charge attempts. When they run out, charge returns payment.max_attempts_exceeded and you must initialise a new payment.
  • Fulfil only after verify says success. The charge response is the processor’s word, and your server’s verify call is the confirmation.

Failure modes

See Errors for the full catalogue.

Test cards

On the sandbox mock card processor, 4111111111111111 and 4242424242424242 succeed. Any other number is rejected. Use a future expiry and any security code. When CyberSource or MPGS is the active test processor, use that processor’s own test card numbers instead. More on Test payments.