Developer's Guide
34 August 2012 PayPal Mobile Payments Developer Guide and Reference – iOS Edition
Dynamic Amount Calculation
This method is called by the library when buyers choose a shipping address. The demo
application calculates the tax based on the state of the shipping address, and then it passes the
updated amounts to the library.
Your method must be implemented as shown:
-(PayPalAmounts *)adjustAmountsForAddress:(PayPalAddress const
*)inAddress andCurrency:(NSString const *)inCurrency
andAmount:(NSDecimalNumber const *)inAmount andTax:(NSDecimalNumber
const *)inTax andShipping:(NSDecimalNumber const *)inShipping
andErrorCode:(PayPalAmountErrorCode *)outErrorCode;
-(NSMutableArray *)adjustAmountsAdvancedForAddress:(PayPalAddress const
*)inAddress andCurrency:(NSString const *)inCurrency
andReceiverAmounts:(NSMutableArray *)recieverAmounts
andErrorCode:(PayPalAmountErrorCode *)outErrorCode;
The demo application implements this method like this:
- (PayPalAmounts *)adjustAmountsForAddress:(PayPalAddress const
*)inAddress andCurrency:(NSString const *)inCurrency
andAmount:(NSDecimalNumber const *)inAmount
andTax:(NSDecimalNumber const *)inTax
andShipping:(NSDecimalNumber const *)inShipping
andErrorCode:(PayPalAmountErrorCode *)outErrorCode {
//do any logic here that would adjust the amount based on the shipping
address
PayPalAmounts *newAmounts = [[[PayPalAmounts alloc] init]
autorelease];
newAmounts.currency = @"USD";
newAmounts.payment_amount = (NSDecimalNumber *)inAmount;
//change tax based on the address
if ([inAddress.state isEqualToString:@"CA"]) {
newAmounts.tax = [NSDecimalNumber
decimalNumberWithString:[NSString
stringWithFormat:@"%.2f",[inAmount floatValue] * .1]];
} else {
newAmounts.tax = [NSDecimalNumber
decimalNumberWithString:[NSString
stringWithFormat:@"%.2f",[inAmount floatValue] * .08]];
}
newAmounts.shipping = (NSDecimalNumber *)inShipping;
//if you need to notify the library of an error condition, do one of
the following
//*outErrorCode = AMOUNT_ERROR_SERVER;
//*outErrorCode = AMOUNT_ERROR_OTHER;
return newAmounts;
}