Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V5 mpan demo app #1526

Merged
merged 8 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

## 5.26.0 (2024-05-07)
* Updated expiring pinned vendor SSL certificates

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,44 @@ - (void)tappedApplePayButton {

PKPaymentAuthorizationViewController *viewController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:paymentRequest];
viewController.delegate = self;


if (@available(iOS 16.0, *)) {
PKRecurringPaymentSummaryItem *recurringItem = [self createRecurringPaymentSummaryItem];
NSURL *managementURL = [NSURL URLWithString:@"https://example.com/manage"];

PKRecurringPaymentRequest *recurringPaymentRequest = [
[PKRecurringPaymentRequest alloc] initWithPaymentDescription:@"Payment description."
regularBilling:recurringItem
managementURL:managementURL
];
}

self.progressBlock(@"Presenting Apple Pay Sheet");
[self presentViewController:viewController animated:YES completion:nil];
}];
}

- (PKRecurringPaymentSummaryItem *)createRecurringPaymentSummaryItem API_AVAILABLE(ios(15.0)){
NSDecimalNumber *amount = [NSDecimalNumber decimalNumberWithString:@"10.99"];
NSDate *startDate = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitMonth
value:1
toDate:[NSDate date]
options:0];
NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitMonth
value:12
toDate:startDate
options:0];

PKRecurringPaymentSummaryItem *recurringItem = [[PKRecurringPaymentSummaryItem alloc] init];
recurringItem.label = @"Subscription Payment";
recurringItem.amount = amount;
recurringItem.startDate = startDate;
recurringItem.intervalUnit = NSCalendarUnitMonth; // Monthly billing cycle
recurringItem.intervalCount = 1; // Every 1 month
recurringItem.endDate = endDate; // Optional end date

return recurringItem;
}

#pragma mark PKPaymentAuthorizationViewControllerDelegate

Expand Down
1 change: 1 addition & 0 deletions Sources/BraintreeApplePay/BTApplePayCardNonce.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ - (instancetype)initWithJSON:(BTJSON *)json {
self = [super initWithNonce:[json[@"nonce"] asString] type:cardType isDefault:[json[@"default"] isTrue]];

if (self) {
_isDeviceToken = [json[@"details"][@"isDeviceToken"] isTrue];
_binData = [[BTBinData alloc] initWithJSON:json[@"binData"]];
}
return self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, strong) BTBinData *binData;

/**
This Boolean (available on iOS 16+) indicates whether this tokenized card is a device-specific account number (DPAN) or merchant/cloud token (MPAN). If `isDeviceToken` is `false`, then token type is MPAN.
*/
@property (nonatomic, assign) BOOL isDeviceToken;

/**
Used to initialize a `BTApplePayCardNonce` with parameters.
*/
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 @@ -33,4 +33,42 @@ class BTApplePayCardNonce_Tests: XCTestCase {
XCTAssertEqual(applePayNonce?.type, "ApplePayCard")
}

func testInitWithJSON_whenApplePayTokenIsMPAN() {
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_whenApplePayTokenIsDPAN() {
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)
}

}
Loading