首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PayPal sdk没有进入沙箱模式,并且App没有改变

PayPal sdk没有进入沙箱模式,并且App没有改变
EN

Stack Overflow用户
提问于 2015-05-26 09:59:51
回答 1查看 803关注 0票数 0

我在id上使用PayPal sdk有一些问题。我在https://developer.paypal.com/webapps/developer/applications/myapps上创建了我的应用程序,并获得了客户端id。我使用paypal示例应用程序的ID,它在模拟和沙箱模式下工作良好。每当我的应用程序在模拟数据模式下运行时,我都会从paypal服务器获得响应。id始终是API-PAYMENT 1843。

代码语言:javascript
复制
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;

我的代码如下

代码语言:javascript
复制
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];

有什么解决办法吗?

EN

回答 1

Stack Overflow用户

发布于 2015-05-26 11:24:49

嗨,我附上了所有的贝宝密码。引用这段代码。

重要

在应用程序代理中,您应该考虑环境

代码语言:javascript
复制
- (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;
}

头文件

代码语言:javascript
复制
@property (nonatomic, strong, readwrite) PayPalConfiguration *payPalConfiguration;

实施文件

代码语言:javascript
复制
- (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;
}

//调用此方法以支付按钮单击事件

代码语言:javascript
复制
- (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];

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30455337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档