# 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 <mark style="color:blue;">`nextAction`</mark> object and the  web redirection address<mark style="color:blue;">`redirectToUrl`</mark> 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.**&#x33;D Secure authentication on web

After directing to the webpage, please check the current url address firstly. If the authenticated rules are met, <mark style="color:blue;">`retrievepayment`</mark> interface  will be called and the payment result will be returned to the customer.&#x20;

If you click <mark style="color:purple;">`Return`</mark> button during the verification process, an <mark style="color:purple;">`Exit`</mark> 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👆🏻
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.moneycollect.com/docs/payment/3d-secure-authentication/ios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
