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

feat: Implement Co-badged Cards on Drop-in #1050

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions Debug App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ PODS:
- PrimerIPay88MYSDK (0.1.7)
- PrimerKlarnaSDK (1.1.1)
- PrimerNolPaySDK (1.0.1)
- PrimerSDK (2.32.0):
- PrimerSDK/Core (= 2.32.0)
- PrimerSDK/Core (2.32.0)
- PrimerSDK (2.32.1):
- PrimerSDK/Core (= 2.32.1)
- PrimerSDK/Core (2.32.1)
- PrimerStripeSDK (1.0.0)

DEPENDENCIES:
Expand Down Expand Up @@ -37,9 +37,9 @@ SPEC CHECKSUMS:
PrimerIPay88MYSDK: 436ee0be7e2c97e4e81456ccddee20175e9e3c4d
PrimerKlarnaSDK: 564105170cc7b467bf95c31851813ea41c468f8b
PrimerNolPaySDK: 08b140ed39b378a0b33b4f8746544a402175c0cc
PrimerSDK: db06e6553747bdadf8a8ca276d556745af38bba3
PrimerSDK: 41eb9f627fa189f3edafdb18ea2a671d4403b3e2
PrimerStripeSDK: c37d4e7c1b5256d67d4890c4cc4b38ddc9427489

PODFILE CHECKSUM: fa17ead44d40b0b09abc2f30a5cc3d8aefe389e1

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
10 changes: 5 additions & 5 deletions Debug App/Resources/Localized Views/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1235,13 +1235,13 @@
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="7" translatesAutoresizingMaskIntoConstraints="NO" id="vYu-uC-Lwg" userLabel="Surcharge Stack View">
<rect key="frame" x="0.0" y="51" width="374" height="58"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Apple Pay" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eF4-2g-Y8U">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Card Network surcharge" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eF4-2g-Y8U" userLabel="Card Network">
<rect key="frame" x="0.0" y="0.0" width="374" height="17"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="e.g. customer_1234" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="XRQ-T7-rG4">
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Amount " textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="XRQ-T7-rG4">
<rect key="frame" x="0.0" y="24" width="374" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
Expand Down Expand Up @@ -1327,7 +1327,6 @@
<outlet property="applePayShippingContactPhoneSwitch" destination="5AD-oh-3KE" id="2lJ-0f-1Zm"/>
<outlet property="applePayShippingControlStackView" destination="hmd-vB-Ft9" id="LCC-bs-UVf"/>
<outlet property="applePayShippingDetailsSwitch" destination="l2a-lu-nlK" id="RbG-0x-lQg"/>
<outlet property="applePaySurchargeTextField" destination="XRQ-T7-rG4" id="dnh-ml-Uz0"/>
<outlet property="applyThemingSwitch" destination="Xts-VY-QHZ" id="qQC-rP-kmS"/>
<outlet property="billingAddressCityTextField" destination="b68-sT-v40" id="537-Vp-BCo"/>
<outlet property="billingAddressCountryTextField" destination="Gxo-QT-E5X" id="8Yg-xu-Kez"/>
Expand Down Expand Up @@ -1380,6 +1379,7 @@
<outlet property="surchargeGroupStackView" destination="32O-OV-0ey" id="FDB-vq-q3D"/>
<outlet property="surchargeStackView" destination="vYu-uC-Lwg" id="7yI-tG-axF"/>
<outlet property="surchargeSwitch" destination="9eb-B5-B2t" id="bc9-Bn-FWV"/>
<outlet property="surchargeTextField" destination="XRQ-T7-rG4" id="dnh-ml-Uz0"/>
<outlet property="test3DSScenarioTextField" destination="io7-2z-MxC" id="Cy0-nh-2P5"/>
<outlet property="test3DSStackView" destination="fxV-mt-ulz" id="65c-eM-qZo"/>
<outlet property="testErrorDescriptionTextField" destination="dNP-tk-egr" id="0np-AM-Wdo"/>
Expand Down Expand Up @@ -1910,13 +1910,13 @@
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="placeholderTextColor">
<color red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.29803921570000003" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.29803921568627451" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemRedColor">
<color red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="1" green="0.23137254901960785" blue="0.18823529411764706" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
71 changes: 59 additions & 12 deletions Debug App/Sources/Model/CreateClientToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,24 @@ struct ClientSessionRequestBody {
var extraMerchantData: [String: Any]?
var captureVaultedCardCvv: Bool?
var merchantName: String?
var networks: NetworkOptionGroup?

enum CodingKeys: CodingKey {
case surcharge, instalmentDuration, extraMerchantData, captureVaultedCardCvv, merchantName
case surcharge, instalmentDuration, extraMerchantData, captureVaultedCardCvv, merchantName, networks
}

init(surcharge: SurchargeOption?,
instalmentDuration: String?,
extraMerchantData: [String: Any]?,
captureVaultedCardCvv: Bool?,
merchantName: String?) {
merchantName: String?,
networks: NetworkOptionGroup?) {
self.surcharge = surcharge
self.instalmentDuration = instalmentDuration
self.extraMerchantData = extraMerchantData
self.captureVaultedCardCvv = captureVaultedCardCvv
self.merchantName = merchantName
self.networks = networks
}

func encode(to encoder: Encoder) throws {
Expand All @@ -409,27 +412,36 @@ struct ClientSessionRequestBody {
let jsonString = String(data: jsonData, encoding: .utf8)
try container.encode(jsonString, forKey: .extraMerchantData)
}


if let captureVaultedCardCvv = captureVaultedCardCvv {
try container.encode(captureVaultedCardCvv, forKey: .captureVaultedCardCvv)
}

if let merchantName = merchantName {
try container.encode(merchantName, forKey: .merchantName)
}

if let networks = networks {
try container.encode(networks, forKey: .networks)
}
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

surcharge = try container.decodeIfPresent(SurchargeOption.self, forKey: .surcharge)
instalmentDuration = try container.decodeIfPresent(String.self, forKey: .instalmentDuration)

let jsonString = try container.decodeIfPresent(String.self, forKey: .extraMerchantData)
if let jsonData = jsonString?.data(using: .utf8) {
if let jsonString = try container.decodeIfPresent(String.self, forKey: .extraMerchantData),
let jsonData = jsonString.data(using: .utf8) {
extraMerchantData = try JSONSerialization.jsonObject(with: jsonData) as? [String: Any]
} else {
extraMerchantData = nil
}

merchantName = try container.decodeIfPresent(String.self, forKey: .merchantName)

captureVaultedCardCvv = try container.decodeIfPresent(Bool.self, forKey: .captureVaultedCardCvv) ?? false
captureVaultedCardCvv = try container.decodeIfPresent(Bool.self, forKey: .captureVaultedCardCvv)
merchantName = try container.decodeIfPresent(String.self, forKey: .merchantName)
networks = try container.decodeIfPresent(NetworkOptionGroup.self, forKey: .networks)
}

var dictionaryValue: [String: Any]? {
Expand All @@ -447,15 +459,19 @@ struct ClientSessionRequestBody {
dic["extraMerchantData"] = extraMerchantData
}

if let captureVaultedCardCvv = captureVaultedCardCvv, captureVaultedCardCvv == true {
if let captureVaultedCardCvv = captureVaultedCardCvv {
dic["captureVaultedCardCvv"] = captureVaultedCardCvv
}

if let merchantName = merchantName {
dic["merchantName"] = merchantName
}

return dic.keys.count == 0 ? nil : dic
if let networks = networks {
dic["networks"] = networks.dictionaryValue
}

return dic.isEmpty ? nil : dic
}
}

Expand All @@ -472,8 +488,39 @@ struct ClientSessionRequestBody {
return dic.keys.count == 0 ? nil : dic
}
}
}

struct NetworkOptionGroup: Codable {
var VISA: NetworkOption?
var MASTERCARD: NetworkOption?
var JCB: NetworkOption?

var dictionaryValue: [String: Any]? {
var dic: [String: Any] = [:]

if let VISA = VISA {
dic["VISA"] = VISA.dictionaryValue
}

if let MASTERCARD = MASTERCARD {
dic["MASTERCARD"] = MASTERCARD.dictionaryValue
}

if let JCB = JCB {
dic["JCB"] = JCB.dictionaryValue
}

return dic.isEmpty ? nil : dic
}
}

struct NetworkOption: Codable {
var surcharge: SurchargeOption

var dictionaryValue: [String: Any] {
return ["surcharge": surcharge.dictionaryValue ?? [:]]
}
}
}
}

extension Encodable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ struct MerchantMockDataManager {
instalmentDuration: "test",
extraMerchantData: extraMerchantData,
captureVaultedCardCvv: false,
merchantName: nil))
merchantName: nil,
networks: nil))

static var extraMerchantData: [String: Any] = [
"subscription": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ class MerchantHeadlessCheckoutRawDataViewController: UIViewController {
extension MerchantHeadlessCheckoutRawDataViewController: UITextFieldDelegate {

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

let text = textField.text

var newText: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class MerchantSessionAndSettingsViewController: UIViewController {

@IBOutlet weak var surchargeSwitch: UISwitch!
@IBOutlet weak var surchargeStackView: UIStackView!
@IBOutlet weak var applePaySurchargeTextField: UITextField!
@IBOutlet weak var surchargeTextField: UITextField!

@IBOutlet weak var primerSDKButton: UIButton!
@IBOutlet weak var primerHeadlessSDKButton: UIButton!
Expand Down Expand Up @@ -525,19 +525,35 @@ class MerchantSessionAndSettingsViewController: UIViewController {
instalmentDuration: nil,
extraMerchantData: nil,
captureVaultedCardCvv: enableCVVRecaptureFlowSwitch.isOn,
merchantName: nil)
merchantName: nil,
networks: nil)

clientSession.paymentMethod?.options?.PAYMENT_CARD = option
}

let applePayOptions = ClientSessionRequestBody.PaymentMethod.PaymentMethodOption(surcharge: nil,
instalmentDuration: nil,
extraMerchantData: nil,
captureVaultedCardCvv: nil,
merchantName: "Primer Merchant iOS")

let applePayOptions = ClientSessionRequestBody.PaymentMethod.PaymentMethodOption(surcharge: nil,
instalmentDuration: nil,
extraMerchantData: nil,
captureVaultedCardCvv: nil,
merchantName: "Primer Merchant iOS",
networks: nil)
clientSession.paymentMethod?.options?.APPLE_PAY = applePayOptions


if let text = surchargeTextField.text, let amount = Int(text), surchargeSwitch.isOn {
let surcharge = ClientSessionRequestBody.PaymentMethod.SurchargeOption(amount: amount)
var networkOptionGroup = ClientSessionRequestBody.PaymentMethod.NetworkOptionGroup()
networkOptionGroup.VISA = ClientSessionRequestBody.PaymentMethod.NetworkOption(surcharge: surcharge)
networkOptionGroup.JCB = ClientSessionRequestBody.PaymentMethod.NetworkOption(surcharge: surcharge)
networkOptionGroup.MASTERCARD = ClientSessionRequestBody.PaymentMethod.NetworkOption(surcharge: surcharge)
let paymentCardOptions = ClientSessionRequestBody.PaymentMethod.PaymentMethodOption(surcharge: nil,
instalmentDuration: nil,
extraMerchantData: nil,
captureVaultedCardCvv: nil,
merchantName: "Primer Merchant iOS",
networks: networkOptionGroup)
clientSession.paymentMethod?.options?.PAYMENT_CARD = paymentCardOptions
}

if let metadata = metadataTextField.text, !metadata.isEmpty {
clientSession.metadata = MetadataParser().parse(metadata)
}
Expand Down
16 changes: 16 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "Primer3DS",
"repositoryURL": "https://github.com/primer-io/primer-sdk-3ds-ios",
"state": {
"branch": null,
"revision": "7d2c9ac8825a4459034a1416012cae61761543fd",
"version": "2.4.1"
}
}
]
},
"version": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public class PrimerCardNetwork: NSObject {
guard let network = network else { return nil }
self.init(network: network)
}

override public var description: String {
return "PrimerCardNetwork(displayName: \(displayName), network: \(network), allowed: \(allowed))"
}
}

@objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,28 @@ extension PrimerButton {

func startAnimating() {
if activityIndicator.isAnimating { return }
activityIndicator.startAnimating()
var buttonStates: [ActivityIndicatorButtonState] = []
for state in [UIControl.State.disabled] {
let buttonState = ActivityIndicatorButtonState(state: state, title: title(for: state), image: image(for: state))
buttonStates.append(buttonState)
setTitle("", for: state)
setImage(UIImage(), for: state)
}
self.activityIndicatorButtonStates = buttonStates
DispatchQueue.main.async {

self.activityIndicator.startAnimating()
var buttonStates: [ActivityIndicatorButtonState] = []
for state in [UIControl.State.disabled] {
let buttonState = ActivityIndicatorButtonState(state: state, title: self.title(for: state), image: self.image(for: state))
buttonStates.append(buttonState)
self.setTitle("", for: state)
self.setImage(UIImage(), for: state)
}
self.activityIndicatorButtonStates = buttonStates
self.isEnabled = false
}
}

func stopAnimating() {
activityIndicator.stopAnimating()
for buttonState in activityIndicatorButtonStates {
setTitle(buttonState.title, for: buttonState.state)
setImage(buttonState.image, for: buttonState.state)
}
DispatchQueue.main.async {
self.activityIndicator.stopAnimating()
for buttonState in self.activityIndicatorButtonStates {
self.setTitle(buttonState.title, for: buttonState.state)
self.setImage(buttonState.image, for: buttonState.state)
}
self.isEnabled = true
}
}
Expand Down
Loading
Loading