我正在使用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客户端ID为沙箱环境初始化了PayPalMobile
。
旁边问题:
merchantName
应包含哪些内容?它应该与paypal网站上提到的相同吗?
答案 0 :(得分:2)
@ engr-anum有this information帮忙吗?
在测试您的应用时,在SDK的用户界面中登录PayPal时,您应该使用个人沙盒帐户电子邮件和密码。即,不是您的Sandbox业务凭证。
您可以在Sandbox accounts页面上创建商业和个人沙盒帐户。
关于merchantName
:正如您在标题文件中对此属性的评论中所看到的,merchantName
仅适用于使用PayPalFuturePaymentViewController
的情况。它与PayPalPaymentViewController
无关。