我正在使用最新的iOS Paypal SDK
,尝试在沙盒环境中测试登录和付款交易。我已经在沙盒测试账户页面创建了一个商业账户。因此,我有一个用户电子邮件、密码和签名。但是我无法使用这些凭据登录。我收到以下响应错误:
PayPal SDK: Request has failed with error: invalid_user - Incorrect username/password. Please try again. (401) | PayPal Debug-ID: c3dd83c83d43e | Details: (
{
"error_description" = "Invalid user credentials";
}
).
我无法理解凭据无效的原因。在使用iOS SDK登录沙盒账户时,我需要使用哪些凭据?或者我的代码有什么问题吗?
代码
- (void)viewDidLoad
{
//paypal setup
// Set up payPalConfig
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;
_payPalConfig.languageOrLocale = @"en";
_payPalConfig.merchantName = @"Merchant nmae";
_payPalConfig.merchantPrivacyPolicyURL = [NSURL URLWithString:@"https://www.paypal.com/webapps/mpp/ua/privacy-full"];
_payPalConfig.merchantUserAgreementURL = [NSURL URLWithString:@"https://www.paypal.com/webapps/mpp/ua/useragreement-full"];
_payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
self.environment = PayPalEnvironmentSandbox;
self.payPalConfig.acceptCreditCards = NO;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
// Preconnect to PayPal early
[PayPalMobile preconnectWithEnvironment:self.environment];
}
- (IBAction)makePayment:(UIButton *)sender {
if([self.amount.text isEqualToString:@""])
{
[[[UIAlertView alloc] initWithTitle:@"Message" message:@"Please enter amount to proceed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
return;
}
self.resultText = nil;
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:self.amount.text];
payment.currencyCode = @"GBP";
payment.shortDescription = @"Payment for Web77";
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.
[[[UIAlertView alloc] initWithTitle:@"Message" message:@"Payment is unprocessable" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
return;
}
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment configuration:self.payPalConfig delegate:self];
[self presentViewController:paymentViewController animated:YES completion:nil];
}
#pragma mark PayPalPaymentDelegate methods
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(@"PayPal Payment Success!");
self.resultText = [completedPayment description];
[[[UIAlertView alloc] initWithTitle:@"Message" message:@"Please enter amount to proceed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
[self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
NSLog(@"PayPal Payment Canceled");
self.resultText = nil;
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark Proof of payment validation
- (void)sendCompletedPaymentToServer:(PayPalPayment *)completedPayment {
// TODO: Send completedPayment.confirmation to server
NSLog(@"Here is your proof of payment:\n\n%@\n\nSend this to your server for confirmation and fulfillment.", completedPayment.confirmation);
}
注意: 我已经使用PayPal沙箱环境的PayPal客户端ID初始化了PayPalMobile
。
附加问题:
merchantName
应该包含什么?是否应与PayPal网站上提到的相同?