PayPal sdk 不进入沙盒模式

Posted

技术标签:

【中文标题】PayPal sdk 不进入沙盒模式【英文标题】:PayPal sdk doesn't go in sandbox mode 【发布时间】:2014-10-20 22:16:06 【问题描述】:

我在 ios 上使用 PayPal sdk 时遇到了一些问题。我在 https://developer.paypal.com/webapps/developer/applications/myapps 创建了我的应用程序并获得了客户端 ID。我使用带有我的 ID 的 paypal 示例应用程序,它在模拟和沙盒模式下工作正常。当我在我的应用程序中使用它时,每次我的应用程序以模拟数据模式移动时,我都会从贝宝服务器获得响应。


    client =     
        environment = mock;
        "paypal_sdk_version" = "2.2.1";
        platform = iOS;
        "product_name" = "PayPal iOS SDK";
    ;
    response =     
        "create_time" = "2014-08-27T10:18:57Z";
        id = "PAY-8UD377151U972354RKOQ3DTQ";
        intent = sale;
        state = approved;
    ;
    "response_type" = payment;

.我不能设置沙盒模式我需要使用哪个变量。

- (void)viewDidLoad


    // Set up payPalConfig
    _payPalConfig = [[PayPalConfiguration alloc] init];
    _payPalConfig.acceptCreditCards = YES;
    _payPalConfig.languageOrLocale = @"en";
    _payPalConfig.merchantName = @"KicksCloset Shoes, Inc.";
    _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];
    // use default environment, should be Production in real life
     self.environment = @"sandbox";

    NSLog(@"PayPal iOS SDK version: %@", [PayPalMobile libraryVersion]);



这是我的付款操作

   
    PayPalPayment *payment = [[PayPalPayment alloc] init];
    payment.amount = [[NSDecimalNumber alloc] initWithString:amountforserver];
    payment.currencyCode = @"USD";
    payment.shortDescription = creditsforserver;
   // payment.items = items;  // if not including multiple items, then leave payment.items as nil
  //  payment.paymentDetails = paymentDetails; // if not including payment details, then leave payment.paymentDetails as nil

    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.
    

    // Update payPalConfig re accepting credit cards.
    self.payPalConfig.acceptCreditCards = self.acceptCreditCards;

    PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
                                                                                                configuration:self.payPalConfig
                                                                                                     delegate:self];
    [self presentViewController:paymentViewController animated:YES completion:nil];

【问题讨论】:

【参考方案1】:

您的操作方法有问题。

只是传递环境

PayPalPayment *payment = [[PayPalPayment alloc] init];
    payment.amount = [[NSDecimalNumber alloc] initWithString:amountforserver];
    payment.currencyCode = @"USD";
    payment.shortDescription = creditsforserver;
   // payment.items = items;  // if not including multiple items, then leave payment.items as nil
  //  payment.paymentDetails = paymentDetails; // if not including payment details, then leave payment.paymentDetails as nil

    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.
    
    self.environment = kPayPalEnvironment;

        PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
                                                                                                    configuration:self.payPalConfig
                                                                                                         delegate:self];

        [self presentViewController:paymentViewController animated:YES completion:nil];

就用这个

中的代码
-(void)viewWillAppear:(BOOL)animated


    [PayPalMobile preconnectWithEnvironment:self.environment];

【讨论】:

如果有任何问题请告诉我【参考方案2】:

将您的贝宝环境更改为 PayPalEnvironmentSandbox

这是沙盒模式

self.environment = PayPalEnvironmentSandbox;

如果你想使用实时模式..

  self.environment = PayPalEnvironmentProduction;

检查您的 PayPalMobile.h 文件

/// 此环境必须用于 App Store 提交。

extern NSString *const PayPalEnvironmentProduction;

/// 沙盒:使用 PayPal 沙盒进行交易。对开发很有用。

extern NSString *const PayPalEnvironmentSandbox;

/// NoNetwork:模拟模式。不向 PayPal 提交交易。伪造成功的响应。对单元测试很有用。

extern NSString *const PayPalEnvironmentNoNetwork;

【讨论】:

environment = kPayPalEnvironment;我用过这个,但仍然没有进入沙盒模式。 什么是 kPayPalEnvironment?你在哪里初始化它?

以上是关于PayPal sdk 不进入沙盒模式的主要内容,如果未能解决你的问题,请参考以下文章

使用 PayPal-PHP-SDK 进行第三方支付的 Paypal 沙盒测试

Paypal:从沙盒上线

PayPal REST API (PHP SDK) 成功交易未在沙盒模式下显示,在实时模式下显示

PayPal 显示沙盒交易

通过信用卡使用 PayPal SDK 进行沙盒支付

带有 paypal ios sdk 的应用程序。沙盒和实时凭据?