2014-08-27 122 views
0

我在iOS上的PayPal sdk有一些問題。我在https://developer.paypal.com/webapps/developer/applications/myapps創建了我的應用程序並獲得了客戶端ID。我使用貝寶示例應用程序與我的ID在模擬和沙箱模式下工作正常。當我在我的應用程序中使用此應用程序時,每當我的應用程序以模擬數據模式移動時,我都會從PayPal服務器獲得響應。PayPal sdk不會進入沙箱模式

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

回答

2

您的操作方法有問題。

只是傳遞環境 {

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]; 
} 
+0

讓我知道如果有任何問題 – Sport 2014-08-27 11:51:36

+0

它的工作與否? – Sport 2014-08-27 11:59:04

+0

感謝,其工作@sport – square 2014-08-27 12:04:16

2

改變你的PayPal環境PayPalEnvironmentSandbox

這是沙盒模式

self.environment = PayPalEnvironmentSandbox; 
如果你想活的方式去

..

self.environment = PayPalEnvironmentProduction; 

檢查PayPalMobile.h文件

///必須用作應用商店提交這個環境。

extern NSString *const PayPalEnvironmentProduction; 

/// Sandbox:使用PayPal沙盒進行交易。用於開發。

extern NSString *const PayPalEnvironmentSandbox; 

/// NoNetwork:模擬模式。不提交交易給PayPal。取得成功的迴應。用於單元測試。

extern NSString *const PayPalEnvironmentNoNetwork; 
+0

環境= kPayPalEnvironment;我已經使用這個但在沙箱模式仍然沒有得到。 – square 2014-08-27 11:32:10

+0

什麼是kPayPalEnvironment?在哪裏初始化? – karthikeyan 2014-08-27 11:36:56