This repository has been archived by the owner on Nov 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsection-1.swift
55 lines (45 loc) · 3.92 KB
/
section-1.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import Braintree
import XCPlayground
import PassKit
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
// Obtain a client token from your server in this block.
var clientTokenHandler : Braintree.Client.ClientTokenProvider = { completion in
// Note: This value is hard-coded only for the sake of this exmaple. In your integration, you
// should obtain a fresh client token via from an authenticated endpoint on your server.
completion("eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiIwM2FjZGJjNTAxMjI0ZjMwMWUyMGE2MTIxOTNlM2QzMzViNjJlOTIzZjQwYjhkZjRiZTEzOTMwMjlhODI1YWJjfGNyZWF0ZWRfYXQ9MjAxNC0xMS0xNFQxODozNjoyMi4zOTkxNjM2OTIrMDAwMFx1MDAyNm1lcmNoYW50X2lkPWRjcHNweTJicndkanIzcW5cdTAwMjZwdWJsaWNfa2V5PTl3d3J6cWszdnIzdDRuYzgiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvZGNwc3B5MmJyd2RqcjNxbi9jbGllbnRfYXBpL3YxL2NvbmZpZ3VyYXRpb24iLCJjaGFsbGVuZ2VzIjpbXSwicGF5bWVudEFwcHMiOltdLCJjbGllbnRBcGlVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvZGNwc3B5MmJyd2RqcjNxbi9jbGllbnRfYXBpIiwiYXNzZXRzVXJsIjoiaHR0cHM6Ly9hc3NldHMuYnJhaW50cmVlZ2F0ZXdheS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cnRlZE5ldHdvcmtzIjpbInZpc2EiLCJtYXN0ZXJjYXJkIiwiYW1leCJdfX0=")
}
// Initialize a Braintree instance with the client token handler.
let braintree = Braintree.Client(clientTokenProvider: clientTokenHandler)
// Initialize a Tokenizable, such as CardDetails, based on user input.
let expiration = Braintree.TokenizationRequest.Expiration(expirationMonth: 12, expirationYear: 2015)
let card = Braintree.TokenizationRequest.Card(number: "4111111111111111", expiration: expiration)
// Send the raw card details directly to Braintree in exchange for a payment method nonce.
braintree.tokenize(card) { result in
switch result {
case let .RequestError(message):
println("Got an error: \(message)")
XCPCaptureValue("Braintree tokenization request error", message)
case let .BraintreeError(message):
println("Got a Braintree error: \(message)")
XCPCaptureValue("Braintree tokenization internal error", message)
case let .PaymentMethodNonce(nonce):
println("Got a nonce: \(nonce)")
XCPCaptureValue("Braintree tokenization nonce", nonce)
}
}
// Example Apple Pay payment
let payment : PKPayment = PKPayment()
braintree.tokenize(Braintree.TokenizationRequest.ApplePay(payment: payment)) { result in
switch result {
case let .RequestError(message):
println("Got an error: \(message)")
XCPCaptureValue("Braintree tokenization request error", message)
case let .BraintreeError(message):
println("Got a Braintree error: \(message)")
XCPCaptureValue("Braintree tokenization internal error", message)
case let .PaymentMethodNonce(nonce):
println("Got a nonce: \(nonce)")
XCPCaptureValue("Braintree tokenization nonce", nonce)
}
}
XCPSetExecutionShouldContinueIndefinitely()