问题
I've integrated the new PayPal iOS SDK into my app. Reference can be found here. The new SDK is really easy to set up and it allows you to work in 3 different environments 1.) PayPalEnvrionmentNoNetwork 2.) PayPalEnvironmentSandBox and 3) No environment meaning to go onto their live servers. Everything works for the NoNetwork Environment, obviously because it uses mock dummy data, not having to access any servers. When I try to switch to the SandBox environment, PayPal can't connect to the servers, I get the following error:
We're Sorry
There was a problem communicating with the PayPal servers. [Cancel][Try Again]
I'm not sure if this is a problem on my side or theirs. The following is the configuration:
#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: Finally I figured out the problem, you need to add this after the view loads. I didn't have this at all.
[PayPalPaymentViewController prepareForPaymentUsingClientId:kPayPalClientId];
回答1:
As my colleagues determined in the comments, the issue was a bug in the PayPal iOS SDK, not in your code. We've fixed the issue in version 1.0.4 (.tgz).
With the updated library, your code should now work as expected; the prepareForPaymentUsingClientId:
call should always be optional (though still recommended).
Thanks again!
回答2:
I have been having the same issue.
This is all because PayPals new SDK is only available in the US and I'm guessing your elsewhere. Thanks!
来源:https://stackoverflow.com/questions/15556622/new-paypal-ios-sdk-beta-cant-connect-to-sandbox