2013-03-21 91 views
3

我已经将新PayPal iOS SDK集成到我的应用程序中。可以参考here。新的SDK非常容易设置,它允许你在3个不同的环境中工作1.)PayPalEnvrionmentNoNetwork 2.)PayPalEnvironmentSandBox和3)没有环境意义上去他们的实时服务器。一切适用于NoNetwork环境,显然是因为它使用模拟虚拟数据,而不必访问任何服务器。当我尝试切换到沙箱环境,贝宝不能连接到服务器,我收到以下错误:新PayPal iOS SDK(beta) - 无法连接到沙箱

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]; 

+0

我不能在这里重现。你在模拟器或设备上?什么是iOS版本?此外,FYI,'client_id'是一个公共证书,所以如果你愿意,可以安全地共享。 (它必须是 - 在应用程序中嵌入的东西永远都不是秘密。) – 2013-03-22 03:42:17

+0

设备,iOS 6.0。我更新了客户端ID。 – TMan 2013-03-22 12:07:27

+0

我不确定那可能是什么问题。 – TMan 2013-03-22 12:13:32

回答

5

正如我的同事在评论中所确定的那样,问题是PayPal iOS SDK中的错误,而不是您的代码中的错误。我们已在version 1.0.4.tgz)中解决了该问题。

随着更新的库,你的代码现在应该按预期工作;呼叫应始终为可选(尽管仍然建议)。

再次感谢!

+0

根本没有prooblem,爱新的SDK顺便说一句。很光滑。 – TMan 2013-03-28 03:28:55

1

我一直有同样的问题。

这都是因为PayPal的新SDK只在美国上市,我猜你在其他地方。谢谢!

+0

如果你去PayPals开发者网站并创建一个美国沙盒帐户,这将工作得很好:-) – Aaron 2013-03-22 20:49:16

+0

是的,我在美国,不知道我的账户是不是美国,但我会看到。 – TMan 2013-03-22 21:58:54

+0

所以,我的帐户是美国帐户,我甚至经历了一个全新的PayPal帐户,但仍然无法使用。您通常将客户ID设置为什么? – TMan 2013-03-23 02:34:09