iOS
1.After the payment is completed, redirect to the webpage for 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
3.Get the payment result
Last updated