Created
August 23, 2016 13:59
-
-
Save jayrparro/652a99439d7607c04667f2bf733c43b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func buyClothingAction(sender: AnyObject) { | |
// Remove our last completed payment, just for demo purposes. | |
resultText = "" | |
// Note: For purposes of illustration, this example shows a payment that includes | |
// both payment details (subtotal, shipping, tax) and multiple items. | |
// You would only specify these if appropriate to your situation. | |
// Otherwise, you can leave payment.items and/or payment.paymentDetails nil, | |
// and simply set payment.amount to your total charge. | |
// Optional: include multiple items | |
let item1 = PayPalItem(name: "Old jeans with holes", withQuantity: 2, withPrice: NSDecimalNumber(string: "84.99"), withCurrency: "USD", withSku: "Hip-0037") | |
let item2 = PayPalItem(name: "Free rainbow patch", withQuantity: 1, withPrice: NSDecimalNumber(string: "0.00"), withCurrency: "USD", withSku: "Hip-00066") | |
let item3 = PayPalItem(name: "Long-sleeve plaid shirt (mustache not included)", withQuantity: 1, withPrice: NSDecimalNumber(string: "37.99"), withCurrency: "USD", withSku: "Hip-00291") | |
let items = [item1, item2, item3] | |
let subtotal = PayPalItem.totalPriceForItems(items) | |
// Optional: include payment details | |
let shipping = NSDecimalNumber(string: "5.99") | |
let tax = NSDecimalNumber(string: "2.50") | |
let paymentDetails = PayPalPaymentDetails(subtotal: subtotal, withShipping: shipping, withTax: tax) | |
let total = subtotal.decimalNumberByAdding(shipping).decimalNumberByAdding(tax) | |
let payment = PayPalPayment(amount: total, currencyCode: "USD", shortDescription: "Hipster Clothing", intent: .Sale) | |
payment.items = items | |
payment.paymentDetails = paymentDetails | |
if (payment.processable) { | |
let paymentViewController = PayPalPaymentViewController(payment: payment, configuration: payPalConfig, delegate: self) | |
presentViewController(paymentViewController!, animated: true, completion: nil) | |
} | |
else { | |
// 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. | |
print("Payment not processalbe: \(payment)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment