Skip to content

Instantly share code, notes, and snippets.

import UIKit
class BSPopupView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
// Dismiss payment authorization view controller
dismiss(animated: true, completion: {
})
}
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
STPAPIClient.shared().createToken(with: payment) { (token: STPToken?, error: Error?) in
guard let token = token, error == nil else {
// Present error to user...
return
}
submitTokenToBackend(token, completion: { (error: Error?) in
if let error = error {
// Present error to user...
func handleApplePayButtonTapped(){
let merchIdentifier = "merchant.com.yourApp"
let paymentRequest = Stripe.paymentRequest(withMerchantIdentifier: merchIdentifier, country: "US", currency: "USD")
paymentRequest.paymentSummaryItems = [
PKPaymentSummaryItem(label: "Something", amount: 50.00),
PKPaymentSummaryItem(label: "Your Company", amount: 50.00)]
if Stripe.canSubmitPaymentRequest(paymentRequest) {
extension YourViewController: PKPaymentAuthorizationViewControllerDelegate { }
import Stripe
...
...
STPPaymentConfiguration.shared().publishableKey =“pk_test_xxxxxxxxxxxx”
let address = STPAddress()
address.line1 = "Some Street"
address.city = "Some City"
address.postalCode = "55202"
address.state = "CA"
address.country = "US"
address.phone = "1234567890"
address.email = "[email protected]"
address.name = "Farhan Syed"
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = UIColor.white
}
import UIKit
class View: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
addViews()
}
required init?(coder aDecoder: NSCoder) {
let sortedArray = companyArray.sorted(by: { $0 < $1 })
print(sortedArray)