Documentation
HOMEAPI ReferencePayment Demo
English
English
  • đź“–Home
  • API Reference
  • Wallet
    • Activate Account
    • Multi-currency Balance
    • Global Collection Account
    • Payout
    • Account settings
  • Payment
    • Get started
    • Accept a payment
      • Hosted payment page
      • In-page checkout
      • iOS
      • Android
      • API-Direct
    • Save a card during payment
      • iOS
      • Android
    • Pre-authorize a payment
    • 3D secure authentication
      • iOS
      • Android
    • Subscriptions
      • Recurring
    • Add payment methods
      • Supported APM codes and attributes list
      • APM Integration Guide
    • After the payment
      • Webhook
      • Refunds
      • Response handling
    • About the APIs
      • Currencies
      • Payments
        • How payments work
  • Business Operation
    • MoneyCollect dashboard
      • Home
      • Mobile apps
    • Account
      • Your account
      • Multiple Accounts
      • Account security
    • Alternative payment methods
      • Apply for APMs from your dashboard
        • Google pay
    • Customers
      • Customer portal
    • Products & Prices
      • Pricing table
    • Invoicing
      • How invoicing works
      • Use the dashboard
        • Customers
        • Products and prices
        • Invoice page
      • Hosted Invoice Page
      • No-code quickstart guide
    • Subscriptions
      • Subscription status
      • Subscription settings
      • Create a subscription
    • Pricing
      • Reserves
      • Fees for APMs
    • Payouts
    • Financial reports
      • Select preferred report
      • Balance summary
      • Payout reconciliation
    • Partners
      • Partner pricing
    • Risk management
      • Disputes
        • How disputes work
        • Respond to disputes
          • Dispute reasons
        • Measuring disputes
      • Fraud
        • Monitoring programs
        • High risk merchant lists
        • Tools
        • Fraud prevention
    • Start a team
      • Teams
      • User roles
    • Startup incorporation
  • Developer tools
    • API-Keys
    • Libraries
    • Plugins
      • WooCommerce
      • Magento
        • Using Magento 2 Admin Panel
      • Shopify
        • MoneyCollect Payments App
        • Legacy Version
          • Credit Card Direct Payments App
          • Credit Card Redirected Payments App
          • Alternative Payment Methods App
      • Wix
      • SHOPLINE
      • SHOPLAZZA
      • Xshoppy
      • ShopBase
      • PrestaShop
      • OpenCart
      • AllValue
        • Using Allvalue Panel
Powered by GitBook
On this page
  1. Payment
  2. Save a card during payment

iOS

1.Create a Customer

Pass a customerId to MoneyCollect to attach to the customer.

   // Use your customerId 
   var customerId = "cus_1452880617225281538"

2.Construct data, and pay in PaymentSheet model

When creating a payment method, you can specify customer parameters and automatically attach the payment method to an existing customer.

  /** Merchant ID */
   @property (nonatomic,copy) NSString *customerID;
   /** Billing details */
   @property (nonatomic,strong) MCBillingDetails *billingDetails;
   /** Create payment parameter object */
   @property (nonatomic,strong) MCCreatePaymentParams *createPaymentParams;


    // Initiate controller
    MCSelectPaymentCardVC *selectPaymentCardVC = [[MCSelectPaymentCardVC alloc] init];
    selectPaymentCardVC.delegate = self;

    // Build request parameters
    selectPaymentCardVC.customerID = [MCConfigurationFile getCustomerID];
    selectPaymentCardVC.billingDetails = [MCConfigurationFile getBillingDetailsModel];
    selectPaymentCardVC.createPaymentParams = [self constructMCCreatePaymentParams];
    
    // Display view
    [selectPaymentCardVC present:self];

The details of using constructMCCreatePaymentParams method to construct data, please refer to MCPaymentSheetCheckoutVC class under Example.

3.Start Hosted Payment Page mode

  • Tap “Checkout” button to pay in Hosted Payment Page mode.

  • In Hosted payment page,select the previously saved card or add a new card.

  • Finally, tap the PayNow button to complete the payment.

4.Customer selects "save this card" during payment

  • 4.1 Select "Save this card for your future use" on the Add a card page.

NSString *setupFutureUsage = isSelected ? @"on" : @"off";
_createPaymentParams.setupFutureUsage = setupFutureUsage;

Select the payment card in the future, when using setupFutureUsage set to "on", otherwise to "off"

  • 4.2 Click "Add a card.

  • 4.3 After create a payment method and attach the payment method to customer will save the card details to customer.

5.Return the payment result

@protocol MCSelectPaymentCardVCDelegate <NSObject>
/** Agent method for successful transaction */
- (void)successfulTransactionWithResponseObject:(NSDictionary *_Nullable)responseObject;
@end;

#pragma mark - MCSelectPaymentCardVCDelegate
- (void)successfulTransactionWithResponseObject:(NSDictionary *)responseObject
{
    // Transaction status
    NSString *status = [[responseObject objectForKey:@"data"] objectForKey:@"status"];
    
    if ([status isEqualToString:@"succeeded"]) {
        
        NSLog(@"success");
        
    }else if ([status isEqualToString:@"failed"]) {
        
        NSLog(@"%@",[[responseObject objectForKey:@"data"] objectForKey:@"errorMessage"]);
        
    }else if ([status isEqualToString:@"pending"]) {
        
        NSLog(@"pending");
        
    }else if ([status isEqualToString:@"uncaptured"]) {
        
        NSLog(@"uncaptured");
        
    }else if ([status isEqualToString:@"canceled"]) {
        
        NSLog(@"canceled");
        
    }else {
        
        NSLog(@"pending");
        
    }
}

1.Create a Customer

Pass a customerId to MoneyCollect to attach to the customer.

   // Use your customerId 
   var customerId = "cus_1452880617225281538"

2.Construct data, and add payment methods with PaymentSheet customizable models

When creating a payment method, you can specify customer parameters to automatically attach the payment method to an existing customer.

#pragma mark - Button Click Event
- (void)selectCardButtonClick:(UIButton *)sender
{
    // Initiate objective
    MCAddCardViewController *addCardVC = [[MCAddCardViewController alloc] init];
    addCardVC.delegate = self;
    
    // Construct parameter
    addCardVC.customerID = [MCConfigurationFile getCustomerID];
    
    //Display view
    [addCardVC present:self];
    
}

3.Customer selects save this card during payment

  • 3.1 Select Save this card for your future use on the Add a card page.

   if (isSelected) { // Save card details
    [[MCAPIClient shared] attachPaymentMethodToCustomer:[MCConfigurationFile getCustomerID] paymentMethod:ID completionBlock:^(NSDictionary * _Nullable responseObject, NSError * _Nullable error) {
       if (!error) { // Request succeeded
          NSLog(@"Save card(Add a card,Add payment methods):%@",responseObject);
       }else {
          NSLog(@"failed to save this card,code = %ld error message = %@",error.code,error.localizedDescription);
       }
      }];
     }

Select the payment card in the future, when setupFutureUsage set to on, otherwise it will set to off.

  • 3.2 Click Add a card.

  • 3.3 After create a payment method and attach the payment method to customer will save the card details to customer.

4.Customer selects the card to make payment

Click on the Pay Now button to complete the transaction.

5.Return the payment result

The payment result is obtained by calling the confirmPayment API for payment confirmation, and then the result data is passed to the component.

  [[MCAPIClient shared] confirmPaymentWithParams:params completionBlock:^(NSDictionary * _Nullable responseObject, NSError * _Nullable error) {
                
                    if (!error) { // Request succeeded
                        
                        // Determine whether to trigger 3D Secure authentication
                        NSDictionary *nextAction = [[responseObject objectForKey:@"data"] objectForKey:@"nextAction"];
                        
                        if (nextAction) { // If this object exists, will trigger 3D Secure authentication
                            
                            NSString *redirectToUrl = [nextAction objectForKey:@"redirectToUrl"];
                            NSString *paymentID = [[responseObject objectForKey:@"data"] objectForKey:@"id"];
                            NSString *clientSecret = [[responseObject objectForKey:@"data"] objectForKey:@"clientSecret"];
                            
                            // Load 3D secure page
                            MCThreeDSWebViewController *threeDSVC = [[MCThreeDSWebViewController alloc] init];
                            [threeDSVC loadURL:redirectToUrl paymentID:paymentID clientSecret:clientSecret];
                            
                            threeDSVC.completeBlock = ^(NSString *msg, NSDictionary *responseObject){
                                
                                // Eliminate animation
                                [weakSelf requestCompletedMsg:msg];
                                
                            };
                            
                            [weakSelf presentViewController:threeDSVC animated:YES completion:nil];
                            
                        }else { // Ordinary transaction
                            
                            // Transaction status
                            NSString *status = [[responseObject objectForKey:@"data"] objectForKey:@"status"];
                            // Hint
                            NSString *msg = @"";
                            
                            if ([status isEqualToString:@"succeeded"]) {
                                
                                msg = @"success";
                                
                            }else if ([status isEqualToString:@"failed"]) {
                                
                                msg = [[responseObject objectForKey:@"data"] objectForKey:@"errorMessage"];
                                
                            }else if ([status isEqualToString:@"pending"]) {
                                
                                msg = @"the payment is pending";
                                
                            }else if ([status isEqualToString:@"uncaptured"]) {
                                
                                msg = @"the payment is uncaptured";
                                
                            }else if ([status isEqualToString:@"canceled"]) {
                                
                                msg = @"the payment is canceled";
                                
                            }else {
                                
                                msg = @"the payment is pending";
                                
                            }
                            
                            // Eliminate animation
                            [weakSelf requestCompletedMsg:msg];
                        }
                    
                        NSLog(@"Confirm charge:%@",responseObject);
                        
                    }else { // Request failed
                        
                        // Eliminate animation
                        [weakSelf requestCompletedMsg:error.localizedDescription];
                        
                        NSLog(@"failed to confirm charge,code = %ld Error message = %@",error.code,error.localizedDescription);
                    }
                                
                }];


#pragma mark - End
- (void)requestCompletedMsg:(NSString *)msg
{
    _bottomPayNow.msg = msg;
    
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:0.25 animations:^{
        weakSelf.bottomView.y -= weakSelf.bottomPayNow.textH;
        weakSelf.bottomView.height += weakSelf.bottomPayNow.textH;
    }];
}
PreviousSave a card during paymentNextAndroid

Last updated 3 years ago