stripe支付的核心代码
import UIKit
import Stripe
class CheckoutViewController: UIViewController, STPPaymentContextDelegate {
// 1) To get started with this demo, first head to https://dashboard.stripe.com/account/apikeys
// and copy your "Test Publishable Key" (it looks like pk_test_abcdef) into the line below.
let stripePublishableKey = "pk_test_8LwPyj7Srlke48c6MIohzaGW"
// 2) Next, optionally, to have this demo save your user's payment details, head to
// https://github.com/stripe/example-ios-backend , click "Deploy to Heroku", and follow
// the instructions (don't worry, it's free). Replace nil on the line below with your
let backendBaseURL: String? = nil //"http://:8083/pay.json?"
// 3) Optionally, to enable Apple Pay, follow the instructions at https://stripe.com/docs/mobile/apple-pay
// to create an Apple Merchant ID. Replace nil on the line below with it (it looks like merchant.com.yourappname).
let appleMerchantID: String? = nil
// These values will be shown to the user when they purchase with Apple Pay.
let companyName = "Emoji Apparel"
let paymentCurrency = "usd"
let paymentContext: STPPaymentContext
let theme: STPTheme
let paymentRow: CheckoutRowView
let totalRow: CheckoutRowView
let buyButton: BuyButton
let rowHeight: CGFloat = 44
let productImage = UILabel()
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
var product = ""
var paymentInProgress: Bool = false {
didSet {
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseIn, animations: {
if self.paymentInProgress {
self.activityIndicator.startAnimating()
self.activityIndicator.alpha = 1
self.buyButton.alpha = 0
}
else {
self.activityIndicator.stopAnimating()
self.activityIndicator.alpha = 0
self.buyButton.alpha = 1
}
}, completion: nil)
}
}
init(product: String, price: Int, settings: Settings) {
self.product = product
self