3

我已将新的 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];

4

2 回答 2

5

正如我的同事在评论中确定的那样,问题出在 PayPal iOS SDK 中,而不是您的代码中。我们已在版本 1.0.4 ( .tgz ) 中修复了该问题。

使用更新后的库,您的代码现在应该可以按预期工作了;该prepareForPaymentUsingClientId:调用应始终是可选的(尽管仍然推荐)。

再次感谢!

于 2013-03-25T22:35:38.593 回答
1

我一直有同样的问题。

这都是因为 PayPal 的新 SDK 仅在美国可用,我猜你在其他地方。谢谢!

于 2013-03-22T20:44:57.113 回答