我已将新的 PayPal iOS SDK 集成到我的应用程序中。参考可以在这里找到。新的 SDK 非常容易设置,它允许您在 3 种不同的环境中工作 1.) PayPalEnvrionmentNoNetwork 2.) PayPalEnvironmentSandBox 和 3) 没有环境意味着进入他们的实时服务器。一切都适用于 NoNetwork 环境,显然是因为它使用模拟虚拟数据,而不必访问任何服务器。当我尝试切换到沙盒环境时,PayPal 无法连接到服务器,我收到以下错误:
We're Sorry
There was a problem communicating with the PayPal servers. [Cancel][Try Again]
我不确定这是我的问题还是他们的问题。以下是配置:
#define kPayPalClientId @"AbRN_BAV7YMsvde9KUFPsbSC_72NA9swMcY-j0QZL629lXrjSc9CNwfFn8Ac"
#define kPayPalReceiverEmail @"The email I use to login into PayPal"
- (IBAction)pay {
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:@"14.99"];
payment.currencyCode = @"USD";
payment.shortDescription = @"Testing.";
if (!payment.processable) {
// This particular payment will always be processable. If, for
// example, the amount was negative or the shortDescription was
// empty, this payment wouldn't be processable, and you'd want
// to handle that here.
}
// Any customer identifier that you have will work here. Do NOT use a device- or
// hardware-based identifier.
NSString *customerId = nil;
// Set the environment:
// - For live charges, use PayPalEnvironmentProduction (default).
// - To use the PayPal sandbox, use PayPalEnvironmentSandbox.
// - For testing, use PayPalEnvironmentNoNetwork.
[PayPalPaymentViewController setEnvironment:self.environment];
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithClientId:kPayPalClientId
receiverEmail:kPayPalReceiverEmail
payerId:customerId
payment:payment
delegate:self];
paymentViewController.hideCreditCardButton = NO;
[self presentViewController:paymentViewController animated:YES completion:nil];
}
FIX:最后我发现了问题,您需要在视图加载后添加它。我根本没有这个。
[PayPalPaymentViewController prepareForPaymentUsingClientId:kPayPalClientId];