Skip to content

Instantly share code, notes, and snippets.

View philipshen's full-sized avatar

Philip Shen philipshen

View GitHub Profile
let request = self.paymentRepository.createPKRequest(order: order)
if self.paymentRepository.canSubmit(paymentRequest: request) {
group.enter()
let paymentController = PaymentAuthorizationController()
paymentController.present(paymentRequest: request) { [weak self] controller, payment, authCompletion in
self?.paymentRepository.createStripeToken(payment: payment, completion: { token, error in
defer { group.leave() }
guard let token = token, error == nil else {
let request = self.paymentRepository.createPKRequest(order: order)
if self.paymentRepository.canSubmit(paymentRequest: request) {
group.enter()
let paymentController = PaymentAuthorizationController()
paymentController.present(paymentRequest: request) { [weak self] controller, payment, authCompletion in
self?.paymentRepository.createStripeToken(payment: payment, completion: { token, error in
defer { group.leave() }
guard let token = token, error == nil else {
let request = self.paymentRepository.createPKRequest(order: order)
if self.paymentRepository.canSubmit(paymentRequest: request) {
group.enter()
let paymentController = PaymentAuthorizationController()
paymentController.present(paymentRequest: request) { [weak self] controller, payment, authCompletion in
self?.paymentRepository.createStripeToken(payment: payment, completion: { token, error in
defer { group.leave() }
guard let token = token, error == nil else {
class PaymentAuthorizationController: NSObject {
public typealias AuthorizationHandler = (PaymentAuthorizationController, PKPayment, (PKPaymentAuthorizationResult) -> Void) -> Void
private var onAuthorize: AuthorizationHandler?
func present(paymentRequest: PKPaymentRequest, onAuthorize: @escaping AuthorizationHandler) {
self.onAuthorize = onAuthorize
let controller = PKPaymentAuthorizationController(paymentRequest: paymentRequest)
controller.delegate = self
let query: [String:Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrSynchronizable as String: kCFBooleanFalse,
kSecAttrAccount as String: "accountName".data(using: .utf8)!,
kSecReturnData as String: kCFBooleanTrue
]
var result: AnyObject?
let status: OSStatus = withUnsafeMutablePointer(to: &result) {
SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
let query: [String:Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrSynchronizable as String: kCFBooleanTrue,
kSecAttrAccount as String: "accountName".data(using: .utf8)!,
kSecReturnData as String: kCFBooleanTrue
]
var result: AnyObject?
let status: OSStatus = withUnsafeMutablePointer(to: &result) {
SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
@philipshen
philipshen / example_add_query.swift
Last active August 20, 2019 02:26
Keychain Examples
let query: [String:Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrSynchronizable as String: kCFBooleanTrue,
kSecAttrAccount as String: "accountName".data(using: .utf8)!,
kSecValueData as String: "data to store".data(using: .utf8)!,
]
let status: OSStatus = SecItemAdd(addQuery as CFDictionary, nil)
@philipshen
philipshen / delegateMethods.swift
Last active September 6, 2018 15:47
JTAppleCalendar Issue
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
let startDate = formatter.date(from: "2017 01 01")!
let endDate = formatter.date(from: "2017 12 31")!
let parameters = ConfigurationParameters(
startDate: startDate,
const animationConfigs = new Map([
[AnimationType.spring, {
duration: 300,
update: {
type: LayoutAnimation.Types.spring,
springDamping: 0.5
},
}],
[AnimationType.linear, {
duration: 300,
const PropertiesEnum = {
opacity: true,
scaleXY: true,
};
const Properties = keyMirror(PropertiesEnum);