Collecting Card Details on iOS

    Learn how to build a Stripe integration for iOS that uses Charges and tokenization.

    Accepting a card payment with Charges and the iOS SDK is a three-step process, with server-side and client-side actions.

    1. Securely collect payment information
    2. Tokenize the card information

    Step 1: Securely collect payment information

    Assemble an STPCardParams instance with your customer’s card information using the iOS SDK’s pre-built STPPaymentCardTextField or your own UI. If you’re using Apple Pay to collect payment information, skip to the next step.

    let cardParams = STPCardParams()
    cardParams.number = myPaymentCardTextField.cardNumber
    cardParams.expMonth = myPaymentCardTextField.expirationMonth
    cardParams.expYear = myPaymentCardTextField.expirationYear
    cardParams.cvc = myPaymentCardTextField.cvc
    STPCardParams *cardParams = [STPCardParams new];
    cardParams.number = myPaymentCardTextField.cardNumber;
    cardParams.expMonth = myPaymentCardTextField.expirationMonth;
    cardParams.expYear = myPaymentCardTextField.expirationYear;
    cardParams.cvc = myPaymentCardTextField.cvc;

    Step 2: Tokenize the card information

    The next step is sending the customer’s payment information to Stripe and exchanging it for a token, which you can send to your server and use to create a charge. Tokenization ensures that no sensitive card data ever needs to touch your server, so that your integration remains PCI-compliant. Use the STPAPIClient createTokenWithCard:completion: method to convert the STPCardParams instance into an STPToken instance which you can then pass to your server.

    STPAPIClient.shared().createToken(withCard: cardParams) { token, error in
        guard let token = token else {
            // Handle the error
        // Use the token in the next step
    [[STPAPIClient shared] createTokenWithCard:cardParams completion:^(STPToken * _Nullable token, NSError * _Nullable error) {
        if (token == nil) {
            // Handle the error
        // Use the token in the next step

    If you’re using Apple Pay, call the STPAPIClient createTokenWithPayment:completion: method with the PKPayment instead.

    Next steps

    Now that you have a payment form built for iOS, create a charge.

    Was this page helpful?

    Thank you for helping improve Stripe's documentation. If you need help or have any questions, please consider contacting support.

    On this page