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.After the payment is completed, redirect to the webpage for 3D Secure authentication
  • 2.3D Secure authentication on web
  • 3.Get the payment result
  1. Payment
  2. 3D secure authentication

iOS

1.After the payment is completed, redirect to the webpage for 3D Secure authentication

After confirming the returned data after the payment contains the nextAction object and the web redirection addressredirectToUrl is not empty, the web page will be redirected to 3D Secure authentication.

[[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, 3D secure authentication  is required
                            
                            NSString *redirectToUrl = [nextAction objectForKey:@"redirectToUrl"];
                            NSString *paymentID = [[responseObject objectForKey:@"data"] objectForKey:@"id"];
                            NSString *clientSecret = [[responseObject objectForKey:@"data"] objectForKey:@"clientSecret"];
                            
                            // Load 3Ds page
                            MCThreeDSWebViewController *threeDSVC = [[MCThreeDSWebViewController alloc] init];
                            [threeDSVC loadURL:redirectToUrl paymentID:paymentID clientSecret:clientSecret];
                    
                            // 3D page request completion callback  msg:status responseObject:(retrievePayment)检索支付接口后台返回数据
                            threeDSVC.completeBlock = ^(NSString *msg, NSDictionary *responseObject){
                                
                                // Eliminate animation
                                [weakSelf requestCompleted:msg];
                                weakSelf.responseObject = responseObject;
                                
                            };
        
                            [weakSelf presentViewController:threeDSVC animated:YES completion:nil];
                            
                        }else { // Ordinary transaction
                            
                            //  transaction status
                            NSString *status = [[responseObject objectForKey:@"data"] objectForKey:@"status"];
                            // Prompt
                            NSString *msg = @"";
                            
                            if ([status isEqualToString:@"succeeded"]) {
                                
                                msg = @"success";
                                weakSelf.responseObject = responseObject;
                                
                            }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 requestCompleted:msg];
                            
                        }
                    
                        NSLog(@"Charge confirmation:%@",responseObject);
                        
                    }else { // Request failed
                        
                        // Eliminate animation
                        [weakSelf requestCompleted:error.localizedDescription];
                        
                        NSLog(@"failed to confirm charge, code = %ld error message = %@",(long)error.code,error.localizedDescription);
                    }
                                
                }];

2.3D Secure authentication on web

After directing to the webpage, please check the current url address firstly. If the authenticated rules are met, retrievepayment interface will be called and the payment result will be returned to the customer.

If you click Return button during the verification process, an Exit prompt box will be displayed. Clicking to exit will call the retrievePayment interface, and then return the payment result to the customer. For details, please refer to the MCThreeDSWebViewController class under the MoneyCollect Example.

// Retrieve whether the url contains these 3 fields
- (void)getStringFromH5QuitWithURLStr:(NSString *)urlStr
{
    if ([urlStr rangeOfString:@"payment_id"].location != NSNotFound && [urlStr rangeOfString:@"payment_client_secret"].location != NSNotFound && [urlStr rangeOfString:@"source_redirect_slug"].location != NSNotFound) {  // 包含
        
        [self retrievePayment];
        
    }else { // Does not contain
        
    }
    
}

// Retrieve payment
- (void)retrievePayment
{
    __weak typeof(self) weakSelf = self;
    // Retrieve
    [[MCAPIClient shared] retrievePayment:_paymentID clientSecret:_clientSecret completionBlock:^(NSDictionary * _Nullable responseObject, NSError * _Nullable error) {
                
        // Prompt
        NSString *msg = @"";
        
        if (!error) {
            
            NSString *code = [responseObject objectForKey:@"code"];
            
            if ([code isEqualToString:@"success"]) {
                
                // Transaction status
                 NSString *status = [[responseObject objectForKey:@"data"] objectForKey:@"status"];
                
                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";
                    
                }
                
            }else {
                
                msg = [responseObject objectForKey:@"msg"];
            }
            
        }else {
            msg = error.localizedDescription;
        }
         
        // Pass parameter
        if (weakSelf.completeBlock) {
            weakSelf.completeBlock(msg, responseObject);
        }
        
        [weakSelf.presentingViewController dismissViewControllerAnimated:YES completion:nil];
        
    }];
}

3.Get the payment result

/** The returned result of 3D Secure authentication completion */
@property (nonatomic, copy) void(^completeBlock)(NSString *msg, NSDictionary *responseObject);

Note:msg: prompt  responseObject: The data returned from server, please see <retrievePayment> Method above for analysis👆🏻
Previous3D secure authenticationNextAndroid

Last updated 3 years ago