gpt4 book ai didi

ios - 使用 Braintree 支付流程的客户端 IOS 到服务器

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:41:28 25 4
gpt4 key购买 nike

我在我的应用程序中使用 Braintree 进行支付流程
[BTPaymentViewController paymentViewControllerWithVenmoTouchEnabled:NO];并使用此方法进行加密`

(void)paymentViewController:(BTPaymentViewController *)paymentViewController
didSubmitCardWithInfo:(NSDictionary *)cardInfo
andCardInfoEncrypted:(NSDictionary *)cardInfoEncrypted {
NSDictionary *dict=[self encryptFormData:cardInfo];
[self savePaymentInfoToServer:dict];
}

-(NSDictionary *) encryptFormData:(NSDictionary *) formData {
BTEncryption *braintree = [[BTEncryption alloc] initWithPublicKey: PUBLIC_KEY];
NSMutableDictionary *encryptedParams = [[NSMutableDictionary alloc] init];

[formData enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
[encryptedParams setObject: [braintree encryptString: object] forKey: key];
}];

return encryptedParams;
}

call to this method to post the data to localhost server for testing
- (void) savePaymentInfoToServer:(NSDictionary *)paymentInfo {
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"%@/card", SAMPLE_CHECKOUT_BASE_URL]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] 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 = [[UIDevice currentDevice] identifierForVendor].UUIDString;
AppDelegate *appdelegate=(AppDelegate *) [[UIApplication sharedApplication]delegate];

[paymentInfo setValue:appdelegate.referenceId forKey:@"bookingRefId"];
[paymentInfo setValue:appdelegate.passengerId forKey:@"passengerId"];


request.HTTPBody = [self postDataFromDictionary:paymentInfo];
request.HTTPMethod = @"POST";
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *body, NSError *requestError)
{
NSError *err = nil;
if (!response && requestError) {
NSLog(@"requestError: %@", requestError);
[self.paymentViewController showErrorWithTitle:@"Error" message:@"Unable to reach the network."];
return;
}

NSDictionary *<b>responseDictionary</b> = [NSJSONSerialization JSONObjectWithData:body options:kNilOptions error:&err];
NSLog(@"saveCardToServer: paymentInfo: %@ response: %@, error: %@", paymentInfo, responseDictionary, requestError);

if ([[responseDictionary valueForKey:@"success"] isEqualToNumber:@1]) { // Success!
// Don't forget to call the cleanup method,
// `prepareForDismissal`, on your `BTPaymentViewController`
[self.paymentViewController prepareForDismissal];
// Now you can dismiss and tell the user everything worked.
[self dismissViewControllerAnimated:YES completion:^(void) {
[[[UIAlertView alloc] 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`
[self.paymentViewController showErrorWithTitle:@"Error saving your card" message:[self messageStringFromResponse:responseDictionary]];
}
}];
}`

contain responseDictionary is null and error is null how to fix the issue can help me

最佳答案

您要将 paymentInfo 字典发送到哪里(即 SAMPLE_CHECKOUT_BASE_URL 是什么)? Braintree 构建的示例项目模拟了一个后端,就像您自己拥有一个后端一样。您需要将该 URL 替换为后端的 URL。

BTPaymentViewController 提供了一个客户端信用卡结账页面,但您的后端仍然需要执行交易。为了让您的后端执行该交易,您必须将该 paymentInfo 字典发送到您的服务器。

如果您还没有为您的 iOS 应用构建后端,您可以使用 Braintree 在几分钟内快速完成设置并获得批准。处理您的付款。

关于ios - 使用 Braintree 支付流程的客户端 IOS 到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18081548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com