|
| 1 | +--- |
| 2 | +title: Vault a card during a checkout authorization |
| 3 | +description: Learn how to vault a credit card during a typical checkout authorization. |
| 4 | +keywords: |
| 5 | + - GraphQL |
| 6 | + - Payments |
| 7 | +--- |
| 8 | + |
| 9 | +# Vault a card during a checkout authorization |
| 10 | + |
| 11 | +These steps describe the flow of requests and responses required to [vault a credit card](https://experienceleague.adobe.com/en/docs/commerce-merchant-services/payment-services/payments-checkout/vaulting#vaulting-a-payment-method-during-checkout) during a typical checkout authorization with Payment Services enabled. |
| 12 | + |
| 13 | +The following conditions must be true to vault a card during checkout: |
| 14 | + |
| 15 | +* You must have installed [Payment Services for Adobe Commerce](https://commercemarketplace.adobe.com/magento-payment-services.html) 2.10.0 or higher. |
| 16 | +* The customer must be logged in. |
| 17 | + |
| 18 | +## Workflow |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +1. Run the [`getPaymentConfig`](../../payment-services-extension/queries/get-payment-config.md) query to fetch the payment configuration needed to render details of hosted fields. |
| 23 | + |
| 24 | +1. Commerce returns the payment configuration information. |
| 25 | + |
| 26 | +1. Run the [`setPaymentMethodOnCart`](../../schema/cart/mutations/set-payment-method.md) mutation to [set the payment method](../../tutorials/checkout/set-payment-method.md). |
| 27 | + |
| 28 | +1. Adobe Commerce returns a `Cart` object. |
| 29 | + |
| 30 | +1. Run the [`createPaymentOrder`](../../payment-services-extension/mutations/create-payment-order.md) mutation with `vaultIntent` set to `true` to begin the authorization process. |
| 31 | + |
| 32 | +1. Commerce forwards the request to PayPal. |
| 33 | + |
| 34 | +1. PayPal returns an `id` value. |
| 35 | + |
| 36 | +1. Adobe Commerce generates a `order_id` and forwards the value in the `mp_order_id` field and the PayPal response in the `id` field. |
| 37 | + |
| 38 | +1. Run [`setPaymentMethodOnCart`](../../schema/cart/mutations/set-payment-method.md) again with [`is_active_payment_token_enabler`](https://developer.adobe.com/commerce/webapi/graphql/payment-services-extension/workflows/checkout/#setpaymentmethodoncartinput-object) set to `true`. This indicates whether a customer-entered credit/debit card should be tokenized for later usage. |
| 39 | + |
| 40 | +1. Adobe Commerce returns a token. |
| 41 | + |
| 42 | +1. (Optional) If hosted fields and the Signifyd integration are enabled, run the [`getPaymentOrder`](../../payment-services-extension/queries/get-payment-order.md) query. |
| 43 | + |
| 44 | +1. (Optional) Adobe Commerce returns details about the payment order. |
| 45 | + |
| 46 | +1. Run the [`placeOrder`](../../schema/cart/mutations/place-order.md) mutation. |
| 47 | + |
| 48 | +1. Commerce sends an authorization request to PayPal. |
| 49 | + |
| 50 | +1. PayPal returns the result to Commerce. |
| 51 | + |
| 52 | +1. Commerce creates an order. |
| 53 | + |
| 54 | +1. Paypal returns a vault token. |
| 55 | + |
| 56 | +1. Commerce stores the vault token for the vaulted card. |
| 57 | + |
| 58 | +## Additional information |
| 59 | + |
| 60 | +It is only possible to vault configuration details for hosted fields. See [`getPaymentConfig`](../../payment-services-extension/queries/get-payment-config.md) query for more information. |
| 61 | + |
| 62 | +### `setPaymentMethodOnCart` mutation example |
| 63 | + |
| 64 | +The following example shows the `setPaymentMethodOnCart` mutation with the attribute `is_active_payment_token_enabler` set to `true`. |
| 65 | + |
| 66 | +**Request:** |
| 67 | + |
| 68 | +```graphql |
| 69 | +mutation { |
| 70 | + setPaymentMethodOnCart ( input: { |
| 71 | + cart_id: "uocGxUi5H97XFAMhY3s66q4aFYG3Bmdr", |
| 72 | + payment_method: { |
| 73 | + code: "payment_services_paypal_hosted_fields", |
| 74 | + payment_services_paypal_hosted_fields: { |
| 75 | + payment_source: "cc", |
| 76 | + payments_order_id: "mp-order-a4babd34-13d3-4ac0-b1b0-109bb7be1574", |
| 77 | + paypal_order_id: "9R90936863877801D", |
| 78 | + is_active_payment_token_enabler: true |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + ) { |
| 83 | + cart { |
| 84 | + id |
| 85 | + selected_payment_method { |
| 86 | + code |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +``` |
| 92 | + |
| 93 | +**Response:** |
| 94 | + |
| 95 | +```json |
| 96 | +{ |
| 97 | + "data": { |
| 98 | + "setPaymentMethodOnCart": { |
| 99 | + "cart": { |
| 100 | + "id": "uocGxUi5H97XFAMhY3s66q4aFYG3Bmdr", |
| 101 | + "selected_payment_method": { |
| 102 | + "code": "payment_services_paypal_hosted_fields" |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | +} |
| 108 | +``` |
0 commit comments