Adding and Updating a Stored Card (iOS SDK)

This guide shows you how to let users add and update stored cards in your iOS app using the myPOS SDK. Follow the steps below for easy integration and a smooth card management experience.

Add a New Card

To add a new card, you need to create an instance of StoreCardViewController with a verification amount and assign a delegate to handle the outcomes.

Swift

Swift
let controller = MPStoreCardViewController(verificationAmount: 1.00,
                                         delegate: self)

present(controller, animated: true, completion: nil)

Objective-C

Objective-C
MPStoreCardViewController *controller = [[MPStoreCardViewController alloc] initWithVerificationAmount:1.00
                                                                                         delegate:self];

[self presentViewController:controller animated:YES completion:nil];

Auto-Reverse Verification Amount (Optional)

If you want the SDK to automatically refund the verification amount after the card is tokenized, set autoReverse to true:

Swift

Swift
let controller = MPStoreCardViewController(verificationAmount: 0.00, autoReverse: true, delegate: self)

Objective-C

Objective-C
MPStoreCardViewController *controller = [[MPStoreCardViewController alloc] initWithVerificationAmount:1.00 autoReverse:YES
                                                                                         delegate:self];

Implement the StoreCardDelegate

Make sure your class implements the StoreCardDelegate methods:

Swift

Swift
func storeCardDidComplete(withData storedCard: StoredCard)
func storeCardDidFailWithError(_ error: MobilePaymentSDKError)

Objective-C

Objective-C
- (void)storeCardDidCompleteWithData:(StoredCard *)storedCard
- (void)storeCardDidFailWithError:(MobilePaymentSDKError *)error;

Update an Existing Stored Card

To update a stored card (e.g., expiration date or cardholder name), create an instance of UpdateStoredCardViewController:

Swift

Swift
let controller = MPUpdateStoredCardViewController(cardToken: selectedCard.token,
                                                verificationAmount: 1.00,
                                                delegate: self)

present(controller, animated: true, completion: nil)

Objective-C

Objective-C
MPUpdateStoredCardViewController *controller = [[MPUpdateStoredCardViewController alloc] initWithCardToken:_card.token
                                                                                    verificationAmount:1.00
                                                                                              delegate:self];
[self presentViewController:controller animated:YES completion:nil];

Implement the UpdateStoredCardDelegate

Your delegate should also implement these methods to handle update success or failure:

Swift

Swift
func updateStoredCardDidComplete(withData storedCard: StoredCard, forCardWithToken cardToken: String)
func updateStoredCardDidFailWithError(_ error: MobilePaymentSDKError)

Objective-C

Objective-C
- (void)updateStoredCardDidCompleteWithData:(StoredCard *)storedCard forCardWithToken:(NSString *)cardToken
- (void)updateStoredCardDidFailWithError:(MobilePaymentSDKError *)error