Our Card Component renders the available cards in your payment form, and securely collects sensitive card information, so it doesn't touch your server.
Before you begin
This page explains how to add cards to your existing iOS Components integration. The iOS Components integration works the same way for all payment methods. If you haven't done this integration yet, refer to our Components integration guide.
Before starting your integration:
- Make sure that you have set up your back end implementation for making API requests.
- Add the cards that you want to accept in your test Customer Area.
Show the available cards in your payment form
For information about the supported countries and currencies for each card, refer to Payment methods.
Include Card in the list of available payment methods.
-
Specify in your /paymentMethods request:
- countryCode: The country code. For example, NL.
- amount.currency: The currency. For example, EUR.
- channel: Specify iOS.
-
Decode the
/paymentMethods
response with thePaymentMethods
structure.
Findlet paymentMethods = try JSONDecoder().decode(PaymentMethods.self, from: paymentMethodsResponse)
paymentMethods.type
card and put it into an object. For example,cardPaymentMethod
. -
Create an instance of
APIContext
with the following parameters:Parameter name Required Description clientKey
Your client key. environment
Use test. When you're ready to accept live payments, change the value to one of our live environments. // When you're ready to go live, change environment to Environment.live // You can also use other environment values described in https://adyen.github.io/adyen-ios/Docs/Structs/Environment.html let apiContext = APIContext(environment: Environment.test, clientKey: clientKey)
- Initialize the Card Component:
let cardComponent = CardComponent(paymentMethod: cardPaymentMethod, apiContext: apiContext) cardComponent.delegate = self // In this example, the Pay button will display 10 EUR. // The value is in minor units. Change the currencyCode to the currency for the Card Component. cardComponent.payment = Payment(amount: Amount(value: 1000, currencyCode: "EUR")) present(cardComponent.viewController, animated: true)
When the shopper is entering their card details, the Component tries to recognize the card brand. When successful, the Component renders the brand icon.
Make a payment
When the shopper proceeds to pay, the Component invokes the didSubmit
method containing the data.paymentMethod
from the PaymentComponentDelegate
.
- Pass the
data.paymentMethod
to your server. - From your server, make a /payments request, specifying:
paymentMethod
: Thedata.paymentMethod
from thedidSubmit
event from your client app.
The /payments response contains:
- pspReference: Our unique identifier for the transaction.
resultCode
: Use this to present the payment result to your shopper.merchantReference
: Thereference
from the /payments request.additionalData
: Additional information about the transaction.
To specify the fields that you want to receive inadditionalData
, log in to your Customer Area, and go to Developers > API URLs > Additional data settings.
Present the payment result
Use the resultCode from the /payments response to present the payment result to your shopper. You will also receive the outcome of the payment asynchronously in a notification webhook.
For card payments, you can receive the following resultCode
values:
resultCode | Description | Action to take |
---|---|---|
Authorised | The payment was successful. | Inform the shopper that the payment has been successful. If you are using manual capture, you also need to capture the payment. |
Cancelled | The shopper cancelled the payment. | Ask the shopper whether they want to continue with the order, or ask them to select a different payment method. |
Error | There was an error when the payment was being processed. For more information, check the
refusalReason
field. |
Inform the shopper that there was an error processing their payment. |
Refused | The payment was refused. For more information, check the
refusalReason
field. |
Ask the shopper to try the payment again using a different payment method. |
resultCode
values are possible in case of the 3D Secure authentication flow. For more information, refer to Result codes.
Present debit and credit cards separately
In some scenarios, you may want to present your shoppers with separate payment forms for debit cards and credit cards. Some examples include:
- In Brazil, many shoppers use Combo cards, allowing for both debit and credit transactions. Having a separate form for Debit Card and Credit Card gives your shoppers a clear indication of whether they are making a debit or credit transaction.
- If you accept payments in Sweden, you need to present debit cards before credit cards in order to comply with local legislation.
For more details, see the corresponding sections about Brazil and Sweden.
Required versions
To present debit and credit cards separately in your iOS Card Component integration, you need to use:
- Checkout API v53 or later.
- iOS Components 3.7.0 or later.
Show the available debit and credit cards
-
When you make a POST /paymentMethods request from your server, include:
- splitCardFundingSources: Set to true.
curl https://checkout-test.adyen.com/v68/paymentMethods \ -H "x-API-key: YOUR_X-API-KEY" \ -H "content-type: application/json" \ -d '{ "merchantAccount": "YOUR_MERCHANT_ACCOUNT", "countryCode": "NL", "amount": { "currency": "EUR", "value": 4700 }, "splitCardFundingSources": true }'
-
To present credit and debit cards separately in your app, you need to instantiate a
CardPaymentMethod
object for each.let debitCard = CardPaymentMethod(type: "scheme", name: "Debit Card", fundingSource: .debit, brands: ["{SUPPORTED_CARD_BRANDs}"]) let creditCard = CardPaymentMethod(type: "scheme", name: "Credit Card", fundingSource: .credit, brands: ["{SUPPORTED_CARD_BRANDs}"])
-
Present a separate
CardComponent
for each funding source type.let component = CardComponent(paymentMethod: debitCard, apiContext: apiContext) component.delegate = self self.debitCardComponent = component present(component.viewController, animated: true)
let component = CardComponent(paymentMethod: creditCard, apiContext: apiContext) component.delegate = self self.creditCardComponent = component present(component.viewController, animated: true)
When the shopper selects to pay with a debit or credit card, the selected Component works like any other Component — it invokes the didSubmit
method containing the data.paymentMethod
from the PaymentComponentDelegate
. You can then use the data.paymentMethod
to make a payment.
Brazil
For debit transactions, we highly recommend using 3D Secure and Automatic Capture due to some issuers' restrictions.
Sweden
When accepting payments in Sweden, present debit cards before credit cards, and label the forms clearly in order to comply with Swedish legislations.
Recurring payments
Adyen's tokenization service allows you to securely store shopper's card details for recurring payments. To make recurring payments, you first need to create a shopper token, and then use the token to make future payments for the shopper.
Create a token
When a shopper chooses to pay with card, the Component renders a switch for saving the card details for future payments.
If the shopper chooses to save their card details when making a payment, the didSubmit
method from the Component will include data.storePaymentMethod
. Pass this to your server.
To create a token, include in your /payments request:
storePaymentMethod
: Thedata.storePaymentMethod
from your client app.- shopperReference: Your unique identifier for the shopper.
If you don't want to show the switch for saving card details, set
showsStorePaymentMethodField
to false when adding the Card Component:
let configuration = CardComponent.Configuration(showsStorePaymentMethodField: false)
let component = CardComponent(paymentMethod: paymentMethod,
apiContext: apiContext,
configuration: configuration)
component.delegate = self
self.cardComponent = component
present(component.viewController, animated: true)
Show a stored card in your payment form
To show a stored card payment in your payment form:
-
Include in your /paymentMethods request:
- shopperReference: The unique shopper identifier that you specified when creating the token.
storedPaymentMethods
array containing the stored payment methods for this shopper. - When you decode the paymentMethods response, find the
StoredCardPaymentMethod
object in the array namedstored
. -
When adding the Card Component, specify:
paymentMethod
: TheStoredCardPaymentMethod
object
let component = CardComponent(paymentMethod: storedCardPaymentMethod, apiContext: apiContext) component.delegate = self self.cardComponent = component present(component.viewController, animated: true)
This will render the stored card in your payment form.
Make a payment with a token
When the shopper proceeds to pay, the Component invokes the didSubmit
method containing the data.paymentMethod
from the PaymentComponentDelegate
.
- Pass the
data.paymentMethod
to your server. -
From your server, make a /payments request, specifying:
paymentMethod
: Thedata.paymentMethod
from thedidSubmit
event from your client app.
shopperReference
: The unique shopper identifier that you specified when creating the token.shopperInteraction
: ContAuth.recurringProcessingModel
: CardOnFile.
curl https://checkout-test.adyen.com/v68/payments \ -H "X-API-key: [Your API Key here]" \ -H "Content-Type: application/json" \ -d '{ "amount":{ "value":2000, "currency":"USD" }, "paymentMethod":{ "type":"scheme", "storedPaymentMethodId":"8415718415172204", "encryptedSecurityCode":"adyenjs_0_1_18$MT6ppy0FAMVMLH..." }, "reference":"YOUR_ORDER_NUMBER", "merchantAccount":"YOUR_MERCHANT_ACCOUNT", "returnUrl":"...", "shopperReference":"YOUR_UNIQUE_SHOPPER_ID_IOfW3k9G2PvXFu2j", "shopperInteraction":"ContAuth", "recurringProcessingModel":"CardOnFile" }'
The /payments response contains:
resultCode
: Use this to present the payment result to your shopper.
You can also use tokens to make shopper-not-present payments for subscriptions or contracts. For more information, refer to Making a payment for a subscription or contract.
Test and go live
Before making live card payments:
-
Test your integration using our test card numbers. You can check the status of test payments in your Customer Area > Transactions > Payments.
If you want to test API calls but your client-side integration is not yet ready, add a
test_
prefix to the test card credentials. Refer to test with encrypted card details. - Add the cards that you want to accept in your live Customer Area.
-
Configure Drop-in with the client key from your live Customer Area.
- Before you can start accepting card payments in the live environment, you need to assess your PCI DSS compliance and submit the required Self-Assessment Questionnaire A document. For more information, refer to PCI DSS compliance guide.