Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "processout.js",
"version": "1.7.1",
"version": "1.7.2",
"description": "ProcessOut.js is a JavaScript library for ProcessOut's payment processing API.",
"scripts": {
"build:processout": "tsc -p src/processout && uglifyjs --compress --keep-fnames --ie8 dist/processout.js -o dist/processout.js",
Expand Down
61 changes: 29 additions & 32 deletions src/dynamic-checkout/payment-methods/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,22 @@ module ProcessOut {
cardForm => {
this.getCardDetailsSectionEventListeners()

// Dynamically change scheme logo based on the card number
cardForm.getNumberField().addEventListener("input", e => {
const scheme = e.schemes[0]
const cardSchemeLogo = document.querySelector(".dco-card-scheme-logo")

if (scheme && CARD_SCHEMES_ASSETS[scheme]) {
cardSchemeLogo.removeAttribute("hidden")

cardSchemeLogo.setAttribute(
"src",
this.procesoutInstance.endpoint("js", CARD_SCHEMES_ASSETS[scheme]),
)
} else {
cardSchemeLogo.setAttribute("hidden", "true")
if (!this.paymentMethod.card.scheme_selection_enabled) {
// Dynamically change scheme logo based on the card number
const scheme = e.schemes[0]
const cardSchemeLogo = document.querySelector(".dco-card-scheme-logo")

if (scheme && CARD_SCHEMES_ASSETS[scheme]) {
cardSchemeLogo.removeAttribute("hidden")

cardSchemeLogo.setAttribute(
"src",
this.procesoutInstance.endpoint("js", CARD_SCHEMES_ASSETS[scheme]),
)
} else {
cardSchemeLogo.setAttribute("hidden", "true")
}
}

this.validateCardRestrictions(e.schemes || [])
Expand Down Expand Up @@ -193,6 +195,8 @@ module ProcessOut {
options.expiryAutoNext = false
options.cardNumberAutoNext = true
options.requireCVC = this.paymentMethod.card.cvc_required
options.enableCardSchemeSelection = this.paymentMethod.card.scheme_selection_enabled
options.preferredSchemes = this.paymentMethod.card.scheme_selection_default_order

return options
}
Expand Down Expand Up @@ -434,7 +438,9 @@ module ProcessOut {
},
])

HTMLElements.appendChildren(cardNumberInput, [cardSchemeLogo])
if (!this.paymentMethod.card.scheme_selection_enabled) {
HTMLElements.appendChildren(cardNumberInput, [cardSchemeLogo])
}

HTMLElements.appendChildren(cardNumberInputWrapper, [
cardNumberInput,
Expand Down Expand Up @@ -722,23 +728,17 @@ module ProcessOut {
if (!restrictToIins || restrictToIins.length === 0 || !data) {
return
}

const iin = data.card_iin || ""

if (iin.length === 0) {
this.setCardRestrictionState(false)
return
}

var isBlockedIin = false
const isAllowedIin = restrictToIins.indexOf(iin) !== -1

restrictToIins.forEach(function (blockedIin) {
if (blockedIin === iin) {
isBlockedIin = true
return
}
})

this.setCardRestrictionState(isBlockedIin)
this.setCardRestrictionState(!isAllowedIin)
}

private validateCardRestrictions(schemes: string[]) {
Expand All @@ -753,18 +753,15 @@ module ProcessOut {
return
}

var isBlockedScheme = false
var hasAllowedScheme = false

restrictToSchemes.forEach(function (blockedScheme) {
schemes.forEach(function (scheme) {
if (blockedScheme === scheme) {
isBlockedScheme = true
return
}
})
schemes.forEach(function (scheme) {
if (restrictToSchemes.indexOf(scheme) !== -1) {
hasAllowedScheme = true
}
})

this.setCardRestrictionState(isBlockedScheme)
this.setCardRestrictionState(!hasAllowedScheme)
}

private setCardRestrictionState(isRestricted: boolean) {
Expand Down
2 changes: 2 additions & 0 deletions src/dynamic-checkout/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type Card = {
cvc_required: boolean
cardholder_name_required: boolean
scheme_selection_allowed: boolean
scheme_selection_enabled: boolean
scheme_selection_default_order: string[]
saving_allowed: boolean
billing_address: BillingAddress
restrict_to_iins: string[] | null
Expand Down