Skip to content

Commit

Permalink
Expose isDeviceToken on BTApplePayCardNonce (#1516)
Browse files Browse the repository at this point in the history
* Exposed `isDeviceToken`

* Added unit tests

* Changed default to `true`
  • Loading branch information
stechiu authored Feb 10, 2025
1 parent 0c4d3af commit d48d6f8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Braintree iOS SDK Release Notes

## unreleased
* BraintreeApplePay
* Add `BTApplePayCardNonce.isDeviceToken` for MPAN identification

## 6.28.0 (2025-02-05)
* BraintreeVenmo
* Allow universal links to be set without a return URL scheme (fixes #1505)
Expand Down
6 changes: 6 additions & 0 deletions Sources/BraintreeApplePay/BTApplePayCardNonce.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import BraintreeCore
/// The BIN data for the card number associated with this nonce.
public let binData: BTBinData

/// This Boolean indicates whether this tokenized card is a device-specific account number (DPAN) or merchant/cloud token (MPAN). Available on iOS 16+.
/// If `isDeviceToken` is `false`, then token type is MPAN
public var isDeviceToken: Bool

init?(json: BTJSON) {
guard let nonce = json["nonce"].asString() else { return nil }

let cardType = json["details"]["cardType"].asString() ?? "ApplePayCard"
let isDefault = json["default"].isTrue

self.isDeviceToken = json["details"]["isDeviceToken"].asBool() ?? true

binData = BTBinData(json: json["binData"])
super.init(nonce: nonce, type: cardType, isDefault: isDefault)
}
Expand Down
38 changes: 38 additions & 0 deletions UnitTests/BraintreeApplePayTests/BTApplePayCardNonce_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,44 @@ class BTApplePayCardNonce_Tests: XCTestCase {
XCTAssertEqual(applePayNonce?.type, "fake-card-type")
}

func testInitWithJSON_whenApplePayTokenIsMPAN() {
let applePayCard = BTJSON(
value: [
"consumed": false,
"binData": [
"commercial": "yes"
],
"details": [
"cardType": "fake-card-type",
"isDeviceToken": false
],
"nonce": "a-nonce"
] as [String: Any]
)

let applePayNonce = BTApplePayCardNonce(json: applePayCard)
XCTAssertEqual(applePayNonce?.isDeviceToken, false)
}

func testInitWithJSON_whenApplePayTokenIsDPAN() {
let applePayCard = BTJSON(
value: [
"consumed": false,
"binData": [
"commercial": "yes"
],
"details": [
"cardType": "fake-card-type",
"isDeviceToken": true
],
"nonce": "a-nonce"
] as [String: Any]
)

let applePayNonce = BTApplePayCardNonce(json: applePayCard)
XCTAssertEqual(applePayNonce?.isDeviceToken, true)
}

func testInitWithJSON_setsDefaultProperties() {
let applePayCard = BTJSON(
value: [
Expand Down

0 comments on commit d48d6f8

Please sign in to comment.