我在id上使用PayPal sdk有一些问题。我在https://developer.paypal.com/webapps/developer/applications/myapps上创建了我的应用程序,并获得了客户端id。我使用paypal示例应用程序的ID,它在模拟和沙箱模式下工作良好。每当我的应用程序在模拟数据模式下运行时,我都会从paypal服务器获得响应。id始终是API-PAYMENT 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];有什么解决办法吗?
发布于 2015-05-26 11:24:49
嗨,我附上了所有的贝宝密码。引用这段代码。
重要
在应用程序代理中,您应该考虑环境
- (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];
}https://stackoverflow.com/questions/30455337
复制相似问题