如何从ios中braintree的结果中支付方法Nonce

By simon at 2018-02-07 • 0人收藏 • 97人看过

我正在使用braintree ios sdk,并使用他们的用户界面添加客户卡 细节。我得到了成功和后方的用户界面呃客户提交 信息,我怎样才能从结果对象得到paymentMEthodNonce。 这是我的代码。

- (void)showDropIn:(NSString *)clientTokenOrTokenizationKey {
BTDropInRequest *request = [[BTDropInRequest alloc] init];
BTDropInController *dropIn = [[BTDropInController alloc] initWithAuthorization:clientTokenOrTokenizationKey request:request handler:^(BTDropInController * _Nonnull controller, BTDropInResult * _Nullable result, NSError * _Nullable error) {

    if (error != nil) {
        NSLog(@"ERROR");
    } else if (result.cancelled) {
        NSLog(@"CANCELLED");
    } else {

        // Use the BTDropInResult properties to update your UI
        // result.paymentOptionType
        // result.paymentMethod
        // result.paymentIcon
        // result.paymentDescription
    }
}];
[self presentViewController:dropIn animated:YES completion:nil];}
我认为,当客户提交结果时,将会导致付款申请 目的??如果这个想法是正确的,怎么能得到这个发出一个变量发送 它到我的服务器。我是相当新的IOS,所以任何帮助将不胜感激。

3 个回复 | 最后更新于 2018-02-07
2018-02-07   #1

您实现BTDropInViewControllerDelegate获取付款方式 现成的nonce,并在eith中关闭Drop In UI呃情况:

- (void)dropInViewController:(__unused BTDropInViewController *)viewController didSucceedWithPaymentMethod:(BTPaymentMethod *)paymentMethod {
    [self postNonceToServer:paymentMethod.nonce]; // Send payment method nonce to your server
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)dropInViewControllerDidCancel:(__unused BTDropInViewController *)viewController {
    [self dismissViewControllerAnimated:YES completion:nil];
}
发送付款方式随机数到服务器
- (void)postNonceToServer:(NSString *)paymentMethodNonce {
    // Update URL with your server
    NSURL *paymentURL = [NSURL URLWithString:@"https://your-server.example.com/checkout"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:paymentURL];
    request.HTTPBody = [[NSString stringWithFormat:@"payment_method_nonce=%@", paymentMethodNonce] dataUsingEncoding:NSUTF8StringEncoding];
    request.HTTPMethod = @"POST";

    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        // TODO: Handle success and failure
    }] resume];
}

2018-02-07   #2

BTDropInRequest *request = [[BTDropInRequest alloc] init];
request.amount = @"10";
BTDropInController *dropIn = [[BTDropInController alloc] initWithAuthorization:clientTokenOrTokenizationKey request:request handler:^(BTDropInController * _Nonnull controller, BTDropInResult * _Nullable result, NSError * _Nullable error) {

    if (error != nil) {
        NSLog(@"ERROR");
    } else if (result.cancelled) {
        NSLog(@"CANCELLED");
    } else {

        BTPaymentMethodNonce *selectedNonce = result.paymentMethod;
       [self postNonceToServer:self.selectedNonce.nonce];

    }
}];
[self presentViewController:dropIn animated:YES completion:nil];

2018-02-07   #3

对于新的iOS v4 SDK我也必须导入Braintree,我没有访问权限 BTDropInResult ot的paymentMethod属性好。

import BraintreeDropIn
import Braintree

登录后方可回帖

Loading...