PayPal sdk没有进入沙箱模式,App ID也没有变化

时间:2015-05-26 09:59:52

标签: ios paypal paypal-sandbox sandbox

我在iOS上遇到PayPal sdk的问题。我在https://developer.paypal.com/webapps/developer/applications/myapps创建了我的应用程序并获得了客户端ID。我使用我的ID的paypal示例应用程序,它在模拟和沙盒模式下工作正常。当我在我的应用程序中使用这个时,每次我的应用程序在模拟数据模式下移动我得到贝宝服务器的响应。 id始终是API-PAYMENT-ID-1843

client =     {
    environment = mock;
    "paypal_sdk_version" = "2.10.2";
    platform = iOS;
    "product_name" = "PayPal iOS SDK";
};
response =     {
    "create_time" = "2015-05-26T09:51:13Z";
    id = "API-PAYMENT-ID-1843";
    intent = sale;
    state = approved;
};
"response_type" = payment;

我的代码如下

PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [NSDecimalNumber decimalNumberWithString:numberStr];
payment.currencyCode = @"USD";
payment.shortDescription = [NSString stringWithFormat:@"Buy %@ Invites",[self.invitesDict objectForKey:@"invites_count"]];
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.
}
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;

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

这是否有任何解决方案

1 个答案:

答案 0 :(得分:0)

您好,我附上了所有的paypal代码。请参阅此代码。

重要

在您的App Delegate中,您应该考虑环境

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


//
//    [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : @"Aat-VBAY9zLQVYJJpC-xxxxxx",
//                                                           PayPalEnvironmentSandbox : @"api.sandbox.paypal.com"}];


    [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : @"API KEY"}];
    return YES;
}

标头文件

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

实施档案

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        _payPalConfiguration = [[PayPalConfiguration alloc] init];

        // See PayPalConfiguration.h for details and default values.
        // Should you wish to change any of the values, you can do so here.
        // For example, if you wish to accept PayPal but not payment card payments, then add:
        _payPalConfiguration.acceptCreditCards = YES;
        // Or if you wish to have the user choose a Shipping Address from those already
        // associated with the user's PayPal account, then add:
        _payPalConfiguration.payPalShippingAddressOption = PayPalShippingAddressOptionNone;
    }
    return self;
}
  

//将此方法称为付款按钮点击事件

- (void)paypalPaymentSettilement:(NSString *)amount{

    float rate = [amount floatValue];
    float totalAmount = [self.lblTotal.text floatValue];

    float usdValue = rate * totalAmount;

    NSNumberFormatter *format = [[NSNumberFormatter alloc]init];
    [format setNumberStyle:NSNumberFormatterDecimalStyle];
    [format setRoundingMode:NSNumberFormatterRoundHalfUp];
    [format setMaximumFractionDigits:2];
    NSString *temp = [format stringFromNumber:[NSNumber numberWithFloat:usdValue]];

    PayPalPayment *payment = [[PayPalPayment alloc] init];

    payment.amount = [[NSDecimalNumber alloc] initWithString:temp];
    payment.currencyCode = @"USD";
    payment.shortDescription = @"payment";
    payment.intent = PayPalPaymentIntentSale;

    if (!payment.processable) {
        NSLog(@"Error");
    }

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

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

}