Tokenizing a card in a mobile app
Once you have an invoice for a payment, the next step is usually to generate a payment source token to represent the customer’s payment details. The most common example of a payment source is a card token. (See the page about accepting card payments to learn more about card tokens and their place in the payment flow.)
We provide client-side SDKs for iOS and Android. These let you generate a card token directly from a customer’s details as described below. You can also use our SDKs to accept payment with Apple Pay and Google Pay, which are described separately.
Tokenizing a card
First, you should obtain and set up the SDK in your code using the instructions for iOS or Android, as appropriate.
The code sample below shows how to tokenize a set of card details that you have already received from the customer (you can use any suitable UI to do this). The token itself is just a string value that represents the card for this particular payment.
// First create a card object containing the card details
let card = ProcessOut.Card(cardNumber: "4242424242424242", expMonth: 11, expYear: 24, cvc: "123", name: "John Smith")
// And then send the card data to ProcessOut to tokenize
ProcessOut.Tokenize(card: card, metadata: [:], completion: {(token, error) -> Void in
if error != nil {
switch error! {
case .BadRequest(let message, let code):
print(message, code)
case .InternalError:
print("An internal error occured")
case .MissingProjectId:
print("Check your app delegate file")
case .NetworkError:
print("Request could not go through")
}
} else {
// Send token to your backend to charge the customer
}
})
// First create a card object containing the card details
Card card = new Card("John Smith", "4242424242424242", 11, 24, "123");
// And then send the card data to ProcessOut to tokenize
client.tokenize(card, new TokenCallback() {
@Override
public void onSuccess(String token) {
// Send the card token to your backend for charging
}
@Override
public void onError(Exception error) {
Log.e("ProcessOut", error.toString());
}
});
Next steps
Once you have generated the card token successfully, you can use it to process a payment. For Cardholder Initiated Transactions, you will first need to authorize the payment on the client before capturing it on the server. You may also be interested in saving the token to capture future payments.