为IOS SDK 2.1.6的凭据设置Paypal客户端ID

为IOS SDK 2.1.6的凭据设置Paypal客户端ID,ios,xcode,paypal,paypal-sandbox,Ios,Xcode,Paypal,Paypal Sandbox,我在我的应用程序中使用Paypal SDK。我将我的环境设置为PayPalenEnvironmentSandbox,但当我运行我的应用程序时,会出现一条警告:“与Paypal服务器通信时出现问题。请重试”。我在谷歌上搜索了很多次,其他人说我需要更改客户端Id,但我不知道如何更改客户端Id,我在paypal的sandbox上有一个测试帐户,但我不知道如何在我的应用程序中实现它们。我读了文档,他们说我需要更改客户Id,但我不知道如何更改。需要你们的帮助,伙计们,谢谢。我使用的是iOS paypal

我在我的应用程序中使用Paypal SDK。我将我的环境设置为PayPalenEnvironmentSandbox,但当我运行我的应用程序时,会出现一条警告:“与Paypal服务器通信时出现问题。请重试”。我在谷歌上搜索了很多次,其他人说我需要更改客户端Id,但我不知道如何更改客户端Id,我在paypal的sandbox上有一个测试帐户,但我不知道如何在我的应用程序中实现它们。我读了文档,他们说我需要更改客户Id,但我不知道如何更改。需要你们的帮助,伙计们,谢谢。我使用的是iOS paypal SDK 2.1.6

代码:

#导入“ZZMainViewController.h”
#进口
#导入“PayPalMobile.h”
//设置环境:
//-对于实时收费,请使用PayPalenEnvironmentProduction(默认设置)。
//-要使用PayPal沙盒,请使用PayPalenEnvironment沙盒。
//-对于测试,请使用PayPalenEnvironment非网络。
//#定义kPayPalenEnvironment PayPalenEnvironment非网络
#定义kPayPalenEnvironment PayPalenEnvironment沙盒
@接口ZZMainViewController()
@属性(非原子、强、读写)IBUIButton*payNowButton;
@属性(非原子、强、读写)IBUIButton*payFutureButton;
@属性(非原子、强、读写)IBMOutlet UIView*successView;
@属性(非原子、强、读写)PayPalConfiguration*payPalConfig;
@结束
@主视图控制器的实现
-(无效)viewDidLoad{
[超级视图下载];
self.view.backgroundColor=[UIColor whiteColor];
//设置payPalConfig
_payPalConfig=[[PayPalConfiguration alloc]init];
_payPalConfig.acceptCreditCards=是;
_payPalConfig.languageOrLocale=@“en”;
_payPalConfig.merchantName=@“真棒衬衫有限公司”;
_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"];
//设置languageOrLocale属性是可选的。
//
//如果未设置languageOrLocale,则将显示PayPalmPaymentViewController
//它的用户界面根据设备的当前语言设置。
//
//将languageOrLocale设置为特定语言(例如,西班牙语为@“es”),或
//区域设置(例如,墨西哥西班牙语的@“es_MX”)强制PayPalPaymentViewController
//使用该语言/区域设置。
//
//有关完整的详细信息,包括可用语言和地区的列表,请参阅PayPalPaymentViewController.h。
_payPalConfig.languageOrLocale=[NSLocale preferredLanguages][0];
//加载视图后,通常从nib执行任何其他设置。
self.successView.hidden=是;
//使用默认环境,应该是现实生活中的生产环境
//self.environment=kPayPalEnvironment;
//self.environment=PayPalEnvironmentSandbox;
[PayPalmMobile与环境预连接:PayPalenEnvironment沙盒];
NSLog(@“PayPal iOS SDK版本:%@,[PayPalmMobile libraryVersion]);
[自付];
}
-(无效)视图将显示:(BOOL)动画{
[超级视图将显示:是];
//提前连接到PayPal
[PayPalmMobile与环境预连接:PayPalenEnvironment沙盒];
}
#pragma标记-接收单一付款
-(无效)支付{
//删除我们最后完成的付款,仅用于演示目的。
self.resultText=nil;
//注:为便于说明,此示例显示了包括以下内容的付款:
//付款明细(小计、装运、税务)和多个项目。
//只有在适合您的情况下,您才会指定这些。
//否则,您可以将payment.items和/或payment.paymentDetails保留为零,
//只需将payment.amount设置为您的总费用。
//可选:包括多个项目
PayPalItem*item1=[PayPalItem itemWithName:@“有洞的旧牛仔裤”
数量:2
withPrice:[NSDecimalNumber decimalNumberWithString:@“84.99”]
货币:@“美元”
withSku:@“Hip-00037”];
PayPalItem*item2=[PayPalItem itemWithName:@“免费彩虹补丁”
数量:1
withPrice:[NSDecimalNumber decimalNumberWithString:@“0.00”]
货币:@“美元”
使用SKU:@“Hip-00066”];
PayPalItem*item3=[PayPalItemWithName:@“长袖格子衬衫(不包括胡子)”
数量:1
withPrice:[NSDecimalNumber decimalNumberWithString:@“37.99”]
货币:@“美元”
使用SKU:@“Hip-00291”];
NSArray*items=@[item1,item2,item3];
NSDecimalNumber*小计=[PayPalItem totalPriceForItems:items];
//可选:包括付款详细信息
NSDecimalNumber*shipping=[[NSDecimalNumber alloc]initWithString:@“5.99”];
NSDecimalNumber*税=[[NSDecimalNumber alloc]initWithString:@“2.50”];
PayPalPaymentDetails*paymentDetails=[PayPalPaymentDetails paymentDetails WithSubtotal:小计
装运:装运
含税:税];
NSDecimalNumber*总计=[[小计decimalNumberByAdding:shipping]decimalNumberByAdding:tax];
PayPalPayment*payment=[[PayPalPayment alloc]init];
付款金额=总额;
payment.currencyCode=@“USD”;
payment.shortDescription=@“时髦服装”;
payment.items=items;//如果不包括多个项目,则将payment.items保留为零
payment.paymentDetails=paymentDetails;//如果不包括付款详细信息,则将payment.paymentDetails保留为零
如果(!payment.processable){
//此特定付款始终是可处理的。如果
//例如,金额为
#import "ZZMainViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "PayPalMobile.h"

// Set the environment:
// - For live charges, use PayPalEnvironmentProduction (default).
// - To use the PayPal sandbox, use PayPalEnvironmentSandbox.
// - For testing, use PayPalEnvironmentNoNetwork.
//#define kPayPalEnvironment PayPalEnvironmentNoNetwork
#define kPayPalEnvironment PayPalEnvironmentSandbox

@interface ZZMainViewController ()

@property(nonatomic, strong, readwrite) IBOutlet UIButton *payNowButton;
@property(nonatomic, strong, readwrite) IBOutlet UIButton *payFutureButton;
@property(nonatomic, strong, readwrite) IBOutlet UIView *successView;

@property(nonatomic, strong, readwrite) PayPalConfiguration *payPalConfig;

@end

@implementation ZZMainViewController

- (void)viewDidLoad {
  [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

  // Set up payPalConfig
  _payPalConfig = [[PayPalConfiguration alloc] init];
  _payPalConfig.acceptCreditCards = YES;
  _payPalConfig.languageOrLocale = @"en";
  _payPalConfig.merchantName = @"Awesome Shirts, 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"];


  // Setting the languageOrLocale property is optional.
  //
  // If you do not set languageOrLocale, then the PayPalPaymentViewController will present
  // its user interface according to the device's current language setting.
  //
  // Setting languageOrLocale to a particular language (e.g., @"es" for Spanish) or
  // locale (e.g., @"es_MX" for Mexican Spanish) forces the PayPalPaymentViewController
  // to use that language/locale.
  //
  // For full details, including a list of available languages and locales, see PayPalPaymentViewController.h.

    _payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];


  // Do any additional setup after loading the view, typically from a nib.

  self.successView.hidden = YES;



  // use default environment, should be Production in real life
  //self.environment = kPayPalEnvironment;
   //self.environment = PayPalEnvironmentSandbox;
  [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentSandbox];
  NSLog(@"PayPal iOS SDK version: %@", [PayPalMobile libraryVersion]);
 [self pay];
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:YES];

  // Preconnect to PayPal early
  [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentSandbox];
}

#pragma mark - Receive Single Payment

- (void)pay {
  // Remove our last completed payment, just for demo purposes.
  self.resultText = nil;

  // Note: For purposes of illustration, this example shows a payment that includes
  //       both payment details (subtotal, shipping, tax) and multiple items.
  //       You would only specify these if appropriate to your situation.
  //       Otherwise, you can leave payment.items and/or payment.paymentDetails nil,
  //       and simply set payment.amount to your total charge.

  // Optional: include multiple items
  PayPalItem *item1 = [PayPalItem itemWithName:@"Old jeans with holes"
                                  withQuantity:2
                                     withPrice:[NSDecimalNumber decimalNumberWithString:@"84.99"]
                                  withCurrency:@"USD"
                                       withSku:@"Hip-00037"];
  PayPalItem *item2 = [PayPalItem itemWithName:@"Free rainbow patch"
                                  withQuantity:1
                                     withPrice:[NSDecimalNumber decimalNumberWithString:@"0.00"]
                                  withCurrency:@"USD"
                                       withSku:@"Hip-00066"];
  PayPalItem *item3 = [PayPalItem itemWithName:@"Long-sleeve plaid shirt (mustache not included)"
                                  withQuantity:1
                                     withPrice:[NSDecimalNumber decimalNumberWithString:@"37.99"]
                                  withCurrency:@"USD"
                                       withSku:@"Hip-00291"];
  NSArray *items = @[item1, item2, item3];
  NSDecimalNumber *subtotal = [PayPalItem totalPriceForItems:items];

  // Optional: include payment details
  NSDecimalNumber *shipping = [[NSDecimalNumber alloc] initWithString:@"5.99"];
  NSDecimalNumber *tax = [[NSDecimalNumber alloc] initWithString:@"2.50"];
  PayPalPaymentDetails *paymentDetails = [PayPalPaymentDetails paymentDetailsWithSubtotal:subtotal
                                                                             withShipping:shipping
                                                                                  withTax:tax];

  NSDecimalNumber *total = [[subtotal decimalNumberByAdding:shipping] decimalNumberByAdding:tax];

  PayPalPayment *payment = [[PayPalPayment alloc] init];
  payment.amount = total;
  payment.currencyCode = @"USD";
  payment.shortDescription = @"Hipster clothing";
  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];

}

#pragma mark PayPalPaymentDelegate methods

- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
  NSLog(@"PayPal Payment Success!");
  self.resultText = [completedPayment description];
  [self showSuccess];

  [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.successView.hidden = YES;
  [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);
}


#pragma mark - Authorize Future Payments

- (IBAction)getUserAuthorization:(id)sender {

  PayPalFuturePaymentViewController *futurePaymentViewController = [[PayPalFuturePaymentViewController alloc] initWithConfiguration:self.payPalConfig delegate:self];
  [self presentViewController:futurePaymentViewController animated:YES completion:nil];
}


#pragma mark PayPalFuturePaymentDelegate methods

- (void)payPalFuturePaymentViewController:(PayPalFuturePaymentViewController *)futurePaymentViewController didAuthorizeFuturePayment:(NSDictionary *)futurePaymentAuthorization {
  NSLog(@"PayPal Future Payment Authorization Success!");
  self.resultText = futurePaymentAuthorization[@"code"];
  [self showSuccess];

  [self sendAuthorizationToServer:futurePaymentAuthorization];
  [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)payPalFuturePaymentDidCancel:(PayPalFuturePaymentViewController *)futurePaymentViewController {
  NSLog(@"PayPal Future Payment Authorization Canceled");
  self.successView.hidden = YES;
  [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)sendAuthorizationToServer:(NSDictionary *)authorization {
  // TODO: Send authorization to server
  NSLog(@"Here is your authorization:\n\n%@\n\nSend this to your server to complete future payment setup.", authorization);
}


#pragma mark - Helpers

- (void)showSuccess {
  self.successView.hidden = NO;
  self.successView.alpha = 1.0f;
  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:0.5];
  [UIView setAnimationDelay:2.0];
  self.successView.alpha = 0.0f;
  [UIView commitAnimations];
}

#pragma mark - Flipside View Controller

- (void)flipsideViewControllerDidFinish:(ZZFlipsideViewController *)controller {
  if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    [self dismissViewControllerAnimated:YES completion:nil];
  } else {
    [self.flipsidePopoverController dismissPopoverAnimated:YES];
    self.flipsidePopoverController = nil;
  }
}

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
  self.flipsidePopoverController = nil;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  if ([[segue identifier] isEqualToString:@"pushSettings"]) {
    [[segue destinationViewController] setDelegate:self];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
      UIPopoverController *popoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
      self.flipsidePopoverController = popoverController;
      popoverController.delegate = self;
    }
  }
}

- (IBAction)togglePopover:(id)sender {
  if (self.flipsidePopoverController) {
    [self.flipsidePopoverController dismissPopoverAnimated:YES];
    self.flipsidePopoverController = nil;
  } else {
    [self performSegueWithIdentifier:@"showAlternate" sender:sender];
  }
}

@end
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ...
    [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : @"YOUR_CLIENT_ID_FOR_PRODUCTION",
                                                     PayPalEnvironmentSandbox : @"YOUR_CLIENT_ID_FOR_SANDBOX"}];
  // ...
    return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary      *)launchOptions { #warning "Enter your credentials"
  [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction :    @"YOUR_CLIENT_ID_FOR_PRODUCTION",
  PayPalEnvironmentSandbox : @"ATIXyxAAjtL8-HdqfLq0kTCeefUi1SNI_xkfWktHelloqznRxsrm_Hello"}]; return YES;}
    [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction                             :@"YOUR_CLIENT_ID_FOR_PRODUCTION",
      PayPalEnvironmentSandbox : @"ATIXyxAAjtL8-HdqfLq0kTCeefUi1SNI_xkfWktHelloqznRxsrm_Hello"}];
 PayPalMobile.initializeWithClientIdsForEnvironments([PayPalEnvironmentProduction: "ID1", PayPalEnvironmentSandbox: "ID2"])