更新されたコード ragnesh のおかげで、複数のアイテムの支払いを行うことができますが、割引なしで、各製品を 10% 割引する必要がありました。これに関して誰か助けてもらえますか?
- (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)
]];