ios - 使用 Braintree 支付流程的客户端 IOS 到服务器
<p><p>我在我的应用程序中使用 Braintree 进行付款流程<br/>
<b>;</b>并使用此方法进行加密
`</p>
<pre><code>(void)paymentViewController:(BTPaymentViewController *)paymentViewController
didSubmitCardWithInfo:(NSDictionary *)cardInfo
andCardInfoEncrypted:(NSDictionary *)cardInfoEncrypted {
NSDictionary *dict=;
;
}
-(NSDictionary *) encryptFormData:(NSDictionary *) formData {
BTEncryption *braintree = [ initWithPublicKey: PUBLIC_KEY];
NSMutableDictionary *encryptedParams = [ init];
[formData enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
forKey: key];
}];
return encryptedParams;
}
call to this method to post the data to localhost server for testing
- (void) savePaymentInfoToServer:(NSDictionary *)paymentInfo {
NSURL *url = ];
NSMutableURLRequest *request = [ initWithURL:url];
// You need a customer id in order to save a card to the Braintree vault.
// Here, for the sake of example, we set customer_id to device id.
// In practice, this is probably whatever user_id your app has assigned to this user.
// NSString *customerId = [ identifierForVendor].UUIDString;
AppDelegate *appdelegate=(AppDelegate *) [delegate];
;
;
request.HTTPBody = ;
request.HTTPMethod = @"POST";
[NSURLConnection sendAsynchronousRequest:request
queue:
completionHandler:^(NSURLResponse *response, NSData *body, NSError *requestError)
{
NSError *err = nil;
if (!response && requestError) {
NSLog(@"requestError: %@", requestError);
;
return;
}
NSDictionary *<b>responseDictionary</b> = ;
NSLog(@"saveCardToServer: paymentInfo: %@ response: %@, error: %@", paymentInfo, responseDictionary, requestError);
if ([ isEqualToNumber:@1]) { // Success!
// Don't forget to call the cleanup method,
// `prepareForDismissal`, on your `BTPaymentViewController`
;
// Now you can dismiss and tell the user everything worked.
[self dismissViewControllerAnimated:YES completion:^(void) {
[[ initWithTitle:@"Success" message:@"Saved your card!" delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}];
} else { // The card did not save correctly, so show the error from server with convenenience method `showErrorWithTitle`
];
}
}];
}`
</code></pre>
<p>contain responseDictionary 为 null 且错误为 null 如何解决此问题,谁能帮帮我</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您要将 <code>paymentInfo</code> 字典发送到哪里(即 <code>SAMPLE_CHECKOUT_BASE_URL</code> 是什么)? Braintree 构建的示例项目模拟了一个后端,就好像你自己有一个一样。您需要将该 URL 替换为后端的 URL。</p>
<p><code>BTPaymentViewController</code> 提供客户端信用卡结账页面,但您的后端仍需执行交易。为了让您的后端执行该交易,您必须将该 <code>paymentInfo</code> 字典发送到您的服务器。</p>
<p>如果您还没有为您的 iOS 应用程序构建后端,您可以通过 <a href="https://www.braintreepayments.com/" rel="noreferrer noopener nofollow">Braintree</a> 快速设置并在几分钟内获得批准处理您的付款。</p></p>
<p style="font-size: 20px;">关于ios - 使用 Braintree 支付流程的客户端 IOS 到服务器,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18081548/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18081548/
</a>
</p>
页:
[1]