【问题标题】:PayPal sdk doesn't go in sandbox mode and App id is not changingPayPal sdk 未进入沙盒模式且 App id 未更改
【发布时间】:2015-08-07 22:30:27
【问题描述】:

我在 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];

有没有办法解决这个问题

【问题讨论】:

    标签: ios paypal paypal-sandbox sandbox


    【解决方案1】:

    嗨,我附上了所有的贝宝代码。请参考此代码。

    重要

    在您的 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];
    
    }
    

    【讨论】:

    • 感谢您的回复。我可以使用贝宝帐户登录进行付款,但使用借记卡或信用卡我得到了正确的响应
    • 检查这个方法 - (instancetype)initWithCoder:(NSCoder *)aDecoder {
    • 你添加了这行 _payPalConfiguration.acceptCreditCards = YES;
    • 是的@puvan 现在我收到以下错误 PayPal SDK:请求失败并出现错误:UNKNOWN_ERROR - 系统错误。请稍后再试。 (400) |贝宝调试 ID:d71a0b18d00b7 [沙盒,贝宝 iOS SDK 2.10.2]
    猜你喜欢
    • 2014-10-20
    • 2016-06-03
    • 2015-12-23
    • 2012-08-31
    • 2016-02-27
    • 2016-09-22
    • 2016-09-29
    • 2022-09-18
    • 2018-01-05
    相关资源
    最近更新 更多