2017-06-17 109 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()調用。 –