gpt4 book ai didi

ios - 适用于 iOS 的 Paypal SDK

转载 作者:太空宇宙 更新时间:2023-11-03 16:09:59 25 4
gpt4 key购买 nike

我正在尝试将 Paypal SDK 实现到我的 iOS 应用程序中。我完全从自述文件说明中复制了代码,导入了文件,并将我的按钮链接到我的操作,但是当我单击该按钮时,它给我一个“线程 1 信号:SIGABRT”错误并崩溃。

这是我的 .m 文件中的 Paypal 代码:

- (IBAction)pay {

// Create a PayPalPayment
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:@"39.95"];
payment.currencyCode = @"USD";
payment.shortDescription = @"Product";

// Check whether payment is processable.
if (!payment.processable) {
// If, for example, the amount was negative or the shortDescription was empty, then
// this payment would not be processable. You would want to handle that here.
}


// Provide a payerId that uniquely identifies a user within the scope of your system,
// such as an email address or user ID.
NSString *aPayerId = @"someone@someone.com";

// Create a PayPalPaymentViewController with the credentials and payerId, the PayPalPayment
// from the previous step, and a PayPalPaymentDelegate to handle the results.
PayPalPaymentViewController *paymentViewController;
paymentViewController = [[PayPalPaymentViewController alloc] initWithClientId:@"MY-CLIENT-ID-HERE"
receiverEmail:@"MY-EMAIL-HERE"
payerId:aPayerId
payment:payment
delegate:self];

// Present the PayPalPaymentViewController.
[self presentViewController:paymentViewController animated:YES completion:nil];
}

#pragma mark - PayPalPaymentDelegate methods

- (void)payPalPaymentDidComplete:(PayPalPayment *)completedPayment {
// Payment was processed successfully; send to server for verification and fulfillment.
[self verifyCompletedPayment:completedPayment];

// Dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)payPalPaymentDidCancel {
// The payment was canceled; dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {
// Send the entire confirmation dictionary
NSData *confirmation = [NSJSONSerialization dataWithJSONObject:completedPayment.confirmation
options:0
error:nil];

// Send confirmation to your server; your server should verify the proof of payment
// and give the user their goods or services. If the server is not reachable, save
// the confirmation and try again later.
}

有人知道问题出在哪里吗?

最佳答案

你知道吗?

因为您在货币上使用十进制数字。所以你需要在这段代码中做一些事情


//检查付款是否可处理。

如果(!payment.processable){

// If, for example, the amount was negative or the shortDescription was empty, then
// this payment would not be processable. You would want to handle that here.


如果你在debug点你可以在payment, display中找到一个关键字,这意味着你的货币将变为40.0。试试吧。

关于ios - 适用于 iOS 的 Paypal SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20256427/

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