2017-06-17 81 views
0

我跟进了针对objective-c的BrainTree教程并结束了以下实施。我想知道,我怎么能够存储用户的信用卡信息,如UberAirBnb。每次用户点击进行付款,并显示信用卡信息输入视图控制器。商店用户信用信息

顺便说一句,交易成功发生,我可以在我的BrainTree沙箱帐户上看到费用。

- (IBAction)placeOrderBtnClicked:(id)sender {  
    [self showDropIn: TOKEN]; 
} 

- (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"); 
      [self dismissViewControllerAnimated:YES completion:NULL]; 
     } else { 
      [self postNonceToServer:result.paymentMethod.nonce]; 
     } 
    }]; 
    [self presentViewController:dropIn animated:YES completion:nil]; 
} 

- (void)postNonceToServer:(NSString *)paymentMethodNonce { 
     self.manager = [AFHTTPSessionManager manager]; 
     NSDictionary *params = @{@"amount" : @"44", @"payment_method_nonce" : paymentMethodNonce}; 
     manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 
     [manager POST:URLString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull operation, id _Nonnull responseObject) { 
      NSLog (@"transaction is succesfull"); 
     } failure:^(NSURLSessionDataTask * _Nullable operation, NSError * _Nonnull error) { 

     }]; 
    } 

// the following method never gets called!!! 
- (void)fetchExistingPaymentMethod:(NSString *)clientToken { 
    [BTDropInResult fetchDropInResultForAuthorization:clientToken handler:^(BTDropInResult * _Nullable result, NSError * _Nullable error) { 
     if (error != nil) { 
      NSLog(@"ERROR"); 
     } else { 
      // Use the BTDropInResult properties to update your UI 
      NSLog(@"Payment method :%@", result.paymentMethod); 
      NSLog(@"Payment Description :%@", result.paymentDescription); 
      NSLog(@"Payment option type :%ld", (long)result.paymentOptionType); 
     } 
    }]; 
} 

更新:我想看看下面突出显示的部分

enter image description here

回答

1

全面披露:我在布伦特里工作。如果您有任何其他问题,请随时联系support

您的意思是说您希望付款表单显示存储的付款,或者您是否问如何存储付款?为了让Drop-in显示先前存储的付款方式,您需要将customer_id传递到服务器端的ClientToken.generate()调用中。如果您希望保存付款方式,那么您的服务器端调用将发生这种情况,因为您必须将nonce从客户端传递到服务器,并在调用PaymentMethod.create()时使用该随机数。

+0

请参阅我的更新。 – hotspring

+1

对于上面的要求,您需要按照上述评论中的链接显示以前存储的付款方式。这个UI是通过将'customer_id'传递到服务器端的ClientToken.generate()调用中创建的。这不是你在前端编写的代码。只有该客户存储了付款方式时才会显示此信息。因此,您还需要如上所述进行PaymentMethod.create()调用。 –