-
Notifications
You must be signed in to change notification settings - Fork 6
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
chore: Add card validation logic for remote validation and co-badged cards #723
chore: Add card validation logic for remote validation and co-badged cards #723
Conversation
Generated by 🚫 Danger Swift against eecc5e3 |
…e-flagged validation service
Appetize link: https://appetize.io/app/xe6zwfnmrffbs3rvhrvubsuvvq |
Sources/PrimerSDK/Classes/PCI/Checkout Components/PrimerCardData.swift
Outdated
Show resolved
Hide resolved
Sources/PrimerSDK/Classes/Core/BIN Data/CardValidationService.swift
Outdated
Show resolved
Hide resolved
...imerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Models/PrimerCardValidationModels.swift
Outdated
Show resolved
Hide resolved
Debug App/Sources/View Controllers/MerchantHeadlessCheckoutRawDataViewController.swift
Show resolved
Hide resolved
didReceiveCardMetadata: cardMetadata, | ||
forCardState: cardState) | ||
}.catch { error in | ||
// JN TODO: CHKT-1772 - send event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice, I have a saved search in Xcode to make sure I sort them all out before they get to master
private func listCardNetworks(_ cardNumber: String) -> Promise<Response.Body.Bin.Networks> { | ||
|
||
// ⚠️ We must only ever send eight or less digits to the endpoint | ||
let cardNumber = String(cardNumber.prefix(8)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe extract this number 8 to some constants? don't bother doing it if you will never have repetition of this same number in same context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good shout - I'll do this as part of CHKT-1885 (Modify card entry logic to account for eight digit constraint)
...imerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Models/PrimerCardValidationModels.swift
Show resolved
Hide resolved
* chore: Add card networks endpoint to network and API services (#705) * Initial integration of bin data card networks endpoint * Update card networks list API version header to 2.2 * Small cleanup of network mocks * Remove unnecessary whitespace * Post-merge fixes * chore: Add card validation logic for remote validation and co-badged cards (#723) * Extend PrimerCardData with field for network id * Initial implementation of core remote card validation and request debouncing logic * Setup mocks for unit tests + add initial test for checking sanity * Add tests for complex card entry and validation * Better names for sdk mock methods * Code cleanup and rename of bin data service * Rename bin data service * further cleanup * Fix guard logic based on manual testing * Add test for errors, refactor tests + ensure max 8 digits sent to bin data endpoint * Re-add nolpay * Firm up tests with multiple card numbers -> results and better expectation handling * Cleanup tests + prevent existing tests from failing due to non-feature-flagged validation service * pod install for new release * Make cardNetworkIdentifier field optional when init-ing PrimerCardData * CardValidationState -> CardState * PrimerCardState -> PrimerCardNumberEntryState * chore: Add Cartes Bancaires to card networks supported by SDK (#728) * Extend PrimerCardData with field for network id * Initial implementation of core remote card validation and request debouncing logic * Setup mocks for unit tests + add initial test for checking sanity * Add tests for complex card entry and validation * Better names for sdk mock methods * Code cleanup and rename of bin data service * Rename bin data service * further cleanup * Fix guard logic based on manual testing * Add test for errors, refactor tests + ensure max 8 digits sent to bin data endpoint * Re-add nolpay * Firm up tests with multiple card numbers -> results and better expectation handling * Cleanup tests + prevent existing tests from failing due to non-feature-flagged validation service * pod install for new release * Add cartes bancaires to supported card networks * Prepare PaymentNetwork for removal * Remove unnecessary argument that has default for PrimerCardData * chore: Add public settings for configuring supported card networks (#730) * Extend PrimerCardData with field for network id * Initial implementation of core remote card validation and request debouncing logic * Setup mocks for unit tests + add initial test for checking sanity * Add tests for complex card entry and validation * Better names for sdk mock methods * Code cleanup and rename of bin data service * Rename bin data service * further cleanup * Fix guard logic based on manual testing * Add test for errors, refactor tests + ensure max 8 digits sent to bin data endpoint * Re-add nolpay * Firm up tests with multiple card numbers -> results and better expectation handling * Cleanup tests + prevent existing tests from failing due to non-feature-flagged validation service * pod install for new release * Add cartes bancaires to supported card networks * Make cardNetworkIdentifier field optional when init-ing PrimerCardData * CardValidationState -> CardState * Add supported networks to public settings config * Add flag for enabling/disabling card validation service * Move and integrate co-badged cards flags + tests * Prepare PaymentNetwork for removal * Remove unnecessary argument that has default for PrimerCardData * Use merchant defined supported networks to configure apple pay * Use all card networks as default merchant setting for supported card networks * Use internal type for CardNetwork array extension * Use internal type for CardNetwork array extension #2 * Add some clarifying comments * PrimerCardMetadata -> PrimerCardNumberEntryMetadata * supportedNetworks -> supportedCardNetworks * supportedPKCardNetworks -> supportedPKPaymentNetworks * Improve test for isCoBadgedCardsEnabled * Add tests for supported networks settings * Add tests for ApplePayUtils * Add test for ApplePayUtils * Reword log for validation error * Test fixes + mock API client abberation ... * Change supported networks array to set * Fix apple pay utils tests * error log -> warning log + fix grammar * chore: Constrain remote validation logic to eight-digit BIN only (#739) * Implement logic for handling validation only when eight-digit BIN is received * Ensure local validation is honoured for < 8 digits * Extract max bin length constant + change sequence of bin checks to better support eight-digit * Fix card validation tests * Fix card validation tests #2 * Remove debug print * Update typer test helper + add test for changing card number * Card Network #3 -> #4 * Final test fix * chore: Add card network assets for Cartes Bancaires (#743) * Add cartes bancaires assets to XCAssets + reorganise card icons * Add cartes bancaires card network image + add card networks asset function to AssetManager * Fix bug with asset naming + add tests * Bump danger action version from 3.13.0 -> 3.17.1 (latest) * Deprecate old card network image asset function * Rename getCardNetworkAssets -> getCardNetworkAsset for correctness + consistency * Install pods after merge * chore: Add analytics events for co-badged cards (#750) * Add analytics events for co-badged cards * Filter validation errors from remote reporting * Add method for getting all supported card network assets * Don't send validation errors to analytics endpoint * Report events for requesting card network assets * Update card icons in xcassets * revert to eight-digit bin length after testing * Switch to array for card networks to preserve ordering * Fix API client post merge * chore: Refactor card networks (#763) * chore: adds release creation (#755) * Adds release creation flow * fix placement * Remove title * fix: Reduce memory usage for analytics service (#756) * Extract analytics max batch size to constant + reduce to 100 * Rework analytics service to allow automated batch sending and flushing * Update analytics test code * Initial test fixes + add or reintroduce promises where sensible * Further refactor of service + tests * Further refactoring. Separate analytics storage utils into separate class * Tidy up storage interface * Turn analytics service into instance singleton to allow better testing * Implicit self fixes in analytics service * Added new tests + further refactoring and improved analytics log messages * Implicit self usage fixes * Add analytics storage test * Fix for race to delete file after sending analytics events to endpoint * That was a lot more difficult than I expected * Remove background dispatch for final callback * Chain callback for event send from promise * expectation per event, not just for remaining events * expectation per event, not just for remaining events * Better name for analytics file url + small test cleanup * chore: Update 3DS and IPay88MY SDK version in debug app (#757) Update 3DS and IPay88MY SDK version in debug app * Release 2.18.3 (#760) [create-pull-request] automated change Co-authored-by: jnewc <[email protected]> * CardNetworks reflects backend card network values * Add validation source + update tests * Add log and event for use of local validation when remote is preferred * Refactor delegate methods * Add missing card networks assets * chore: Fix mutiple SwiftLint rule violations (#761) Fix mutiple SwiftLint rule violations Co-authored-by: Boris Nikolic <[email protected]> * Correct bancontact enum string value * fix: add additional info to errors (#759) * Refactor context for 3DS error. Add errorId * Added errorId and paymentMethodType where available * Update tests * Add paymentMethodType to failedToProcessPayment * Added paymentMethodType to `failedToPerform3DS` * Add info to Klarna Error * Extend Klarna and iPay88 errors with PrimerErrorProtocol * Refactor paymentMethodType utility * Adding final params * Errors cleanup * Remove invalidSupportedPaymentNetworks * Remove missingCustomUI * Fix for hardcoded error codes in tests * Fix card assets test * Post-merge fix for protocols on api client --------- Co-authored-by: Niall Quinn <[email protected]> Co-authored-by: Security Integrations <[email protected]> Co-authored-by: jnewc <[email protected]> Co-authored-by: borisprimer <[email protected]> Co-authored-by: Boris Nikolic <[email protected]> * chore: Clear Metabase issues (#765) * Temporarily add hard-coded bin data host for example app testing * chore: Consume allowed card networks from configuration response (#770) * Add orderedAllowedCardNetworks to configuration response models * Replace local supportedCardNetworks with remote config orderedAllowedCardNetworks * Update tests * Rename supportedCardNetworks -> allowedCardNetworks * chore: Integration tests for co-badged cards (#766) * CardNetworks reflects backend card network values * Add validation source + update tests * Add log and event for use of local validation when remote is preferred * Refactor delegate methods * Add missing card networks assets * Correct bancontact enum string value * Fix card assets test * Post-merge fix for protocols on api client * Refactor raw data manager tests + add new tests + update raw card data to use network rather than magic string * pod install after merge * Extract error user info dict factory to dictionary extension * reinstall pods * invalidCardNetwork -> invalidCardType * pod fix * Fix merge issues * Fix unit tests * Fix type capture for user info error dict * Update CB asset * post-merge fix up * chore: Retrieve BIN data url from configuration response (#775) * Retrieve bin data url from configuration response * Add missing mapping from card data to tokenization request body model * Local fallback source for remote validation failures + model renames to align with DX * Align debounce time with Android / Nol * getSupportedCardNetworkAssets -> getAllowedCardNetworkAssets * pod reintegrate after merge * Remove isCoBadgedCardsEnabled * Align assets manager interface with web + android * Send event for metadata on 0 card digits entered * Asset manager card icons: use array for return value * Send empty array of networks when card number length is 0 * Add in-mem cache for metadata responses * pod reintegrate * Fix project file after merge * chore: Update co-badged metadata models for new contract (#780) * Refactor metadata to allow selected + detected cards * Update unit tests * pod reintegrate * Test fix * Add generic card icon asset * Return no networks in validation callback when card number is empty * Missing model * Update tests for disjoint allowed and detected cards * Remove version from bin endpoint path * Publicise new fields * Test fix * pod install * Add self refs to make pod lint happy * chore: Rework card network validation logic to allow additive async validate step (#783) * Rework validation logic to allow additive async validate step * Test fix * Fix handler * chore: DX alignment for co-badged cards (#785) * Prioritise unsupported network error * Only provide unsupported card type validation error for remote validation * Fix tests * Remove getAllowedCardNetworkAssets * revalidate for local fallback * revalidate for local fallback #2 * Add timeout support to URLSessionStack + 10s timeout for listCardNetworks * Add display name for card networks + fix dummy endpoint * Remove error throwing from card image asset manager function * Use same handler for cached metadata as for remotely retrieved * migrate co-badged events to new format * Check cache for card type validation when bin is greater than 8 chars * pod install * remove onDidChange cardNetwork foot gun * pod install * Test fix * Fix detected networks logic + add more tests * Test fix * pod install * fix merge formatting issues * test fix * Re-remove dead code in tests (after merge) * Fix test * Code review changes * Clean up warnings * Code review changes #2 * pod install * Fix naming for delegate in test mock * Increase timeout for validation tests --------- Co-authored-by: Niall Quinn <[email protected]> Co-authored-by: Security Integrations <[email protected]> Co-authored-by: jnewc <[email protected]> Co-authored-by: borisprimer <[email protected]> Co-authored-by: Boris Nikolic <[email protected]>
* Initial integration of bin data card networks endpoint * Update card networks list API version header to 2.2 * Small cleanup of network mocks * Remove unnecessary whitespace * chore: Add card networks endpoint to network and API services (#705) * Initial integration of bin data card networks endpoint * Update card networks list API version header to 2.2 * Small cleanup of network mocks * Remove unnecessary whitespace * Prototype - initial setup * Update lockfile * Tidy up prototype * A few prototype tweaks * post-merge fix + update tests * Add card network to payment instruments tokenization request body * SPM -> iOS 13/14 for Combine support * Post-merge fixes * Fixes for validation * chore: Add card validation logic for remote validation and co-badged cards (#723) * Extend PrimerCardData with field for network id * Initial implementation of core remote card validation and request debouncing logic * Setup mocks for unit tests + add initial test for checking sanity * Add tests for complex card entry and validation * Better names for sdk mock methods * Code cleanup and rename of bin data service * Rename bin data service * further cleanup * Fix guard logic based on manual testing * Add test for errors, refactor tests + ensure max 8 digits sent to bin data endpoint * Re-add nolpay * Firm up tests with multiple card numbers -> results and better expectation handling * Cleanup tests + prevent existing tests from failing due to non-feature-flagged validation service * pod install for new release * Make cardNetworkIdentifier field optional when init-ing PrimerCardData * CardValidationState -> CardState * PrimerCardState -> PrimerCardNumberEntryState * chore: Add Cartes Bancaires to card networks supported by SDK (#728) * Extend PrimerCardData with field for network id * Initial implementation of core remote card validation and request debouncing logic * Setup mocks for unit tests + add initial test for checking sanity * Add tests for complex card entry and validation * Better names for sdk mock methods * Code cleanup and rename of bin data service * Rename bin data service * further cleanup * Fix guard logic based on manual testing * Add test for errors, refactor tests + ensure max 8 digits sent to bin data endpoint * Re-add nolpay * Firm up tests with multiple card numbers -> results and better expectation handling * Cleanup tests + prevent existing tests from failing due to non-feature-flagged validation service * pod install for new release * Add cartes bancaires to supported card networks * Prepare PaymentNetwork for removal * Remove unnecessary argument that has default for PrimerCardData * chore: Add public settings for configuring supported card networks (#730) * Extend PrimerCardData with field for network id * Initial implementation of core remote card validation and request debouncing logic * Setup mocks for unit tests + add initial test for checking sanity * Add tests for complex card entry and validation * Better names for sdk mock methods * Code cleanup and rename of bin data service * Rename bin data service * further cleanup * Fix guard logic based on manual testing * Add test for errors, refactor tests + ensure max 8 digits sent to bin data endpoint * Re-add nolpay * Firm up tests with multiple card numbers -> results and better expectation handling * Cleanup tests + prevent existing tests from failing due to non-feature-flagged validation service * pod install for new release * Add cartes bancaires to supported card networks * Make cardNetworkIdentifier field optional when init-ing PrimerCardData * CardValidationState -> CardState * Add supported networks to public settings config * Add flag for enabling/disabling card validation service * Move and integrate co-badged cards flags + tests * Prepare PaymentNetwork for removal * Remove unnecessary argument that has default for PrimerCardData * Use merchant defined supported networks to configure apple pay * Use all card networks as default merchant setting for supported card networks * Use internal type for CardNetwork array extension * Use internal type for CardNetwork array extension #2 * Add some clarifying comments * PrimerCardMetadata -> PrimerCardNumberEntryMetadata * supportedNetworks -> supportedCardNetworks * supportedPKCardNetworks -> supportedPKPaymentNetworks * Improve test for isCoBadgedCardsEnabled * Add tests for supported networks settings * Add tests for ApplePayUtils * Add test for ApplePayUtils * Reword log for validation error * Test fixes + mock API client abberation ... * Change supported networks array to set * Fix apple pay utils tests * error log -> warning log + fix grammar * chore: Constrain remote validation logic to eight-digit BIN only (#739) * Implement logic for handling validation only when eight-digit BIN is received * Ensure local validation is honoured for < 8 digits * Extract max bin length constant + change sequence of bin checks to better support eight-digit * Fix card validation tests * Fix card validation tests #2 * Remove debug print * Update typer test helper + add test for changing card number * Card Network #3 -> #4 * Final test fix * chore: Add card network assets for Cartes Bancaires (#743) * Add cartes bancaires assets to XCAssets + reorganise card icons * Add cartes bancaires card network image + add card networks asset function to AssetManager * Fix bug with asset naming + add tests * Bump danger action version from 3.13.0 -> 3.17.1 (latest) * Deprecate old card network image asset function * Rename getCardNetworkAssets -> getCardNetworkAsset for correctness + consistency * Install pods after merge * chore: Add analytics events for co-badged cards (#750) * Add analytics events for co-badged cards * Filter validation errors from remote reporting * Add method for getting all supported card network assets * Don't send validation errors to analytics endpoint * Report events for requesting card network assets * Update card icons in xcassets * revert to eight-digit bin length after testing * Switch to array for card networks to preserve ordering * Fix API client post merge * chore: Refactor card networks (#763) * chore: adds release creation (#755) * Adds release creation flow * fix placement * Remove title * fix: Reduce memory usage for analytics service (#756) * Extract analytics max batch size to constant + reduce to 100 * Rework analytics service to allow automated batch sending and flushing * Update analytics test code * Initial test fixes + add or reintroduce promises where sensible * Further refactor of service + tests * Further refactoring. Separate analytics storage utils into separate class * Tidy up storage interface * Turn analytics service into instance singleton to allow better testing * Implicit self fixes in analytics service * Added new tests + further refactoring and improved analytics log messages * Implicit self usage fixes * Add analytics storage test * Fix for race to delete file after sending analytics events to endpoint * That was a lot more difficult than I expected * Remove background dispatch for final callback * Chain callback for event send from promise * expectation per event, not just for remaining events * expectation per event, not just for remaining events * Better name for analytics file url + small test cleanup * chore: Update 3DS and IPay88MY SDK version in debug app (#757) Update 3DS and IPay88MY SDK version in debug app * Release 2.18.3 (#760) [create-pull-request] automated change Co-authored-by: jnewc <[email protected]> * CardNetworks reflects backend card network values * Add validation source + update tests * Add log and event for use of local validation when remote is preferred * Refactor delegate methods * Add missing card networks assets * chore: Fix mutiple SwiftLint rule violations (#761) Fix mutiple SwiftLint rule violations Co-authored-by: Boris Nikolic <[email protected]> * Correct bancontact enum string value * fix: add additional info to errors (#759) * Refactor context for 3DS error. Add errorId * Added errorId and paymentMethodType where available * Update tests * Add paymentMethodType to failedToProcessPayment * Added paymentMethodType to `failedToPerform3DS` * Add info to Klarna Error * Extend Klarna and iPay88 errors with PrimerErrorProtocol * Refactor paymentMethodType utility * Adding final params * Errors cleanup * Remove invalidSupportedPaymentNetworks * Remove missingCustomUI * Fix for hardcoded error codes in tests * Fix card assets test * Post-merge fix for protocols on api client --------- Co-authored-by: Niall Quinn <[email protected]> Co-authored-by: Security Integrations <[email protected]> Co-authored-by: jnewc <[email protected]> Co-authored-by: borisprimer <[email protected]> Co-authored-by: Boris Nikolic <[email protected]> * chore: Clear Metabase issues (#765) * Temporarily add hard-coded bin data host for example app testing * chore: Consume allowed card networks from configuration response (#770) * Add orderedAllowedCardNetworks to configuration response models * Replace local supportedCardNetworks with remote config orderedAllowedCardNetworks * Update tests * Rename supportedCardNetworks -> allowedCardNetworks * chore: Integration tests for co-badged cards (#766) * CardNetworks reflects backend card network values * Add validation source + update tests * Add log and event for use of local validation when remote is preferred * Refactor delegate methods * Add missing card networks assets * Correct bancontact enum string value * Fix card assets test * Post-merge fix for protocols on api client * Refactor raw data manager tests + add new tests + update raw card data to use network rather than magic string * pod install after merge * Extract error user info dict factory to dictionary extension * reinstall pods * invalidCardNetwork -> invalidCardType * pod fix * Fix merge issues * Fix unit tests * Fix type capture for user info error dict * Update CB asset * post-merge fix up * chore: Retrieve BIN data url from configuration response (#775) * Retrieve bin data url from configuration response * Add missing mapping from card data to tokenization request body model * Local fallback source for remote validation failures + model renames to align with DX * Align debounce time with Android / Nol * getSupportedCardNetworkAssets -> getAllowedCardNetworkAssets * pod reintegrate after merge * Remove isCoBadgedCardsEnabled * Align assets manager interface with web + android * Send event for metadata on 0 card digits entered * Asset manager card icons: use array for return value * Send empty array of networks when card number length is 0 * Add in-mem cache for metadata responses * pod reintegrate * Fix project file after merge * chore: Update co-badged metadata models for new contract (#780) * Refactor metadata to allow selected + detected cards * Update unit tests * pod reintegrate * Test fix * Add generic card icon asset * Return no networks in validation callback when card number is empty * Missing model * Update tests for disjoint allowed and detected cards * Remove version from bin endpoint path * Publicise new fields * Test fix * pod install * Add self refs to make pod lint happy * chore: Rework card network validation logic to allow additive async validate step (#783) * Rework validation logic to allow additive async validate step * Test fix * Fix handler * chore: DX alignment for co-badged cards (#785) * Prioritise unsupported network error * Only provide unsupported card type validation error for remote validation * Fix tests * Remove getAllowedCardNetworkAssets * revalidate for local fallback * revalidate for local fallback #2 * Add timeout support to URLSessionStack + 10s timeout for listCardNetworks * Add display name for card networks + fix dummy endpoint * Remove error throwing from card image asset manager function * Use same handler for cached metadata as for remotely retrieved * migrate co-badged events to new format * Check cache for card type validation when bin is greater than 8 chars * pod install * pod install * Functional co-badged in debug app * remove onDidChange cardNetwork foot gun * pod install * Test fix * add shared workspace files * pod install * Initial updates for co-badged appium tests * Fix detected networks logic + add more tests * Change ui test branch temporarily * Test fix * pod install * fix merge formatting issues * test fix * Tidy up network display * Re-remove dead code in tests (after merge) * cleanup * update ui test branch * Allow branch configuration for ui tests * print appium repo ref to verify it's what's expected * workflow tweak * pod install * Swiftlint fix * Revert unnecessary changes * Add missing file to spm project --------- Co-authored-by: Niall Quinn <[email protected]> Co-authored-by: Security Integrations <[email protected]> Co-authored-by: jnewc <[email protected]> Co-authored-by: borisprimer <[email protected]> Co-authored-by: Boris Nikolic <[email protected]>
CHKT-1753
ℹ️ This is going to a feature branch, not master
What this PR does
Notable decisions & other stuff
Before merging
QA