Skip to content

Instantly share code, notes, and snippets.

@shiningabdul
shiningabdul / IntentHandler.swift
Last active March 2, 2020 06:07
IntentHandler extension for handling SiriKit requests
import Intents
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
// This is the default implementation. If you want different objects to handle different intents,
// you can override this and return the handler you want for that particular intent.
if intent is OrderPizzaIntent {
return OrderPizzaIntentHandler()
}
@shiningabdul
shiningabdul / ViewController.swift
Last active March 1, 2020 18:33
ViewController that loads an INUIAddVoiceShortcutButton.
import UIKit
import IntentsUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let addShortcutButton = INUIAddVoiceShortcutButton(style: .blackOutline)
let intent = OrderPizzaIntent()
@shiningabdul
shiningabdul / ViewController.swift
Created October 8, 2018 21:58
Updated view controller to donate shortcut
@IBAction func showButtonTapped(_ sender: Any) {
guard let newMessage = messageField.text else {
return
}
messageLabel.text = newMessage
let intent = IntentManager.shared.intent(withMessage: newMessage)
IntentManager.shared.donateShortcuts(withIntent: intent)
}
@shiningabdul
shiningabdul / IntentManager.swift
Created October 8, 2018 00:12
Starting intent manager
import Foundation
import Intents
class IntentManager {
static let shared = IntentManager()
func intent(withMessage message:String) -> ShowMessageIntent {
let intent = ShowMessageIntent()
intent.message = message
return intent
@shiningabdul
shiningabdul / ViewController.swift
Created October 7, 2018 23:47
Starting view controller content
class ViewController: UIViewController {
@IBOutlet weak var messageLabel: UILabel!
@IBOutlet weak var messageField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
// Use Stripe to charge the user
STPAPIClient.shared().createToken(with: payment) { (stripeToken, error) in
guard error == nil, let stripeToken = stripeToken else {
print(error!)
return
}
let url = URL(string:"http://localhost:3000/pay")
guard let apiUrl = url else {
// Add packages we need
const express = require('express')
const bodyParser = require('body-parser')
var stripe = require('stripe')('YOUR SECRET KEY FROM STRIPE')
// Create an express app
const app = express()
// Use body parser so we can parse the body of requests
app.use(bodyParser.json())
class UIViewController: UIViewController, PKPaymentAuthorizationViewControllerDelegate {
@objc private func applePayButtonTapped(sender: UIButton) {
// Cards that should be accepted
let paymentNetworks:[PKPaymentNetwork] = [.amex,.masterCard,.visa]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) {
let request = PKPaymentRequest()
request.merchantIdentifier = "merchant.com.shiningdevelopers"
request.countryCode = "CA"
import UIKit
import PassKit
import Stripe
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
import UIKit
import Stripe
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.