本文介绍了带有多个对象的ios paypal简单支付的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
更新代码多亏了 ragnesh,我可以进行多件商品付款,但没有折扣,我需要每件产品 10% 的折扣,有人可以帮忙解决这个问题吗?
UPDATED CODEthanks to ragnesh I am able to do multiple items payment but without a discount, i needed a 10% discount on each product, can anyone help regarding this?
- (void)simplePayment {
[PayPal getPayPalInst].shippingEnabled = TRUE;
[PayPal getPayPalInst].dynamicAmountUpdateEnabled = TRUE;
[PayPal getPayPalInst].feePayer = FEEPAYER_EACHRECEIVER;
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.recipient = @"email@example.com";
payment.paymentCurrency = @"USD";
payment.invoiceData = [[PayPalInvoiceData alloc] init];
payment.invoiceData.totalShipping = [NSDecimalNumber decimalNumberWithString:@"0"];
payment.invoiceData.totalTax = [NSDecimalNumber decimalNumberWithString:@"0.00"];
payment.invoiceData.invoiceItems = [NSMutableArray array];
NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
for (int i = 0; i < [db.array count]; i++) {
myData =[db.array objectAtIndex:i];
[dic setValue:myData.itemName forKey:[NSString stringWithFormat:@"title%d",i]];
[dic setValue:[NSString stringWithFormat:@"%d",myData.itemPrice] forKey:[NSString stringWithFormat:@"price%d",i]];
[dic setValue:[NSString stringWithFormat:@"%d",myData.itemQuantity] forKey:[NSString stringWithFormat:@"quantity%d",i]];
}
NSLog(@"%@",dic);
for (int i=0; i<[db.array count]; i++) {
PayPalInvoiceItem *item = [[PayPalInvoiceItem alloc] init];
[item setItemCount:[NSDecimalNumber decimalNumberWithString:[dic objectForKey:[NSString stringWithFormat:@"quantity%d",i]]]];
[item setItemPrice:[NSDecimalNumber decimalNumberWithString:[dic objectForKey:[NSString stringWithFormat:@"price%d",i]]]];
item.name = [dic objectForKey:[NSString stringWithFormat:@"title%d",i]];
[payment.invoiceData.invoiceItems addObject:item];
NSDecimalNumber *paypalItemQuantity = [NSDecimalNumber decimalNumberWithString:[dic objectForKey:[NSString stringWithFormat:@"quantity%d",i]]];
NSDecimalNumber *paypalItemPrice = [NSDecimalNumber decimalNumberWithString:[dic objectForKey:[NSString stringWithFormat:@"price%d",i]]];
payment.subTotal =[NSDecimalNumber decimalNumberWithString: [NSString stringWithFormat:@"%f",[payment.subTotal floatValue]
+[paypalItemPrice floatValue] *
[paypalItemQuantity floatValue]
]];
NSLog(@"%@",[dic objectForKey:[NSString stringWithFormat:@"price%d",i]]);
NSLog(@"%@",[dic objectForKey:[NSString stringWithFormat:@"title%d",i]]);
NSLog(@"%@",payment.subTotal);
}
[[PayPal getPayPalInst] checkoutWithPayment:payment];
}
为了打折,我做了类似的事情:但它弹出错误
payment.subTotal =[NSDecimalNumber decimalNumberWithString: [NSString stringWithFormat:@"%f",([payment.subTotal floatValue]*
[paypalItemQuantity floatValue])
-([paypalItemPrice floatValue] *
[paypalItemQuantity floatValue] *0.1)
]];
推荐答案
按照此操作 payPal 整合
把这条线从你的循环中去掉
Put this line out of your loop
payment.invoiceData.invoiceItems = [NSMutableArray array];
编辑
- (void)simplePayment
{
//dismiss any native keyboards
//optional, set shippingEnabled to TRUE if you want to display shipping
//options to the user, default: TRUE
[PayPal getPayPalInst].shippingEnabled = TRUE;
//optional, set dynamicAmountUpdateEnabled to TRUE if you want to compute
//shipping and tax based on the user's address choice, default: FALSE
[PayPal getPayPalInst].dynamicAmountUpdateEnabled = TRUE;
//optional, choose who pays the fee, default: FEEPAYER_EACHRECEIVER
[PayPal getPayPalInst].feePayer = FEEPAYER_EACHRECEIVER;
//for a payment with a single recipient, use a PayPalPayment object
NSMutableDictionary *dic=[[NSUserDefaults standardUserDefaults]valueForKey:@"drinkDetailDic"];
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.recipient = @"email@example.com";
payment.paymentCurrency = @"USD";
payment.description = [dic objectForKey:@"title"];
//invoiceData is a PayPalInvoiceData object which contains tax, shipping, and a list of PayPalInvoiceItem objects
payment.invoiceData = [[PayPalInvoiceData alloc] init];
//shippping charge
payment.invoiceData.totalShipping = [NSDecimalNumber decimalNumberWithString:@"0"];
payment.invoiceData.totalTax = [NSDecimalNumber decimalNumberWithString:@"0.00"];
payment.invoiceData.invoiceItems = [NSMutableArray array];
for (int i=0; i<2; i++)
{
PayPalInvoiceItem *item = [[PayPalInvoiceItem alloc] init];
item.totalPrice = payment.subTotal;
[item setItemCount:[NSNumber numberWithInt:1]];
[item setItemPrice:[NSDecimalNumber decimalNumberWithString:[dic objectForKey:@"price"]]];
item.name = [dic objectForKey:@"title"];
[payment.invoiceData.invoiceItems addObject:item];
payment.subTotal =[NSDecimalNumber decimalNumberWithString: [NSString stringWithFormat:@"%f",[payment.subTotal floatValue]
+[[dic objectForKey:@"price"] floatValue]]];
}
[[PayPal getPayPalInst] checkoutWithPayment:payment];
}
注意
如果您要添加多个商品,则 subTotal 价格与所有商品价格的总和相同.
If you are adding multiple item then subTotal price is same as sum of all item price.
这篇关于带有多个对象的ios paypal简单支付的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!