-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: compatibilization with bundle js
(#217)
- Loading branch information
1 parent
b449d91
commit a1200bf
Showing
29 changed files
with
2,870 additions
and
2,883 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,64 @@ | ||
var Bin = function () { | ||
binValue = '', | ||
brand = '', | ||
checkedBins = [0] | ||
selectedBrand = '' | ||
}; | ||
define(['jquery'], ($) => { | ||
return class Bin { | ||
constructor() { | ||
this.binValue = ''; | ||
this.brand = ''; | ||
this.checkedBins = [0]; | ||
this.selectedBrand = ''; | ||
} | ||
init(newValue) { | ||
|
||
Bin.prototype.init = function (newValue) { | ||
const formattedNewValue = this.formatNumber(newValue); | ||
|
||
var newValue = this.formatNumber(newValue); | ||
if ( | ||
typeof this.checkedBins != 'undefined' && | ||
typeof this.checkedBins[formattedNewValue] != 'undefined' | ||
){ | ||
this.binValue = formattedNewValue; | ||
this.selectedBrand = this.checkedBins[formattedNewValue]; | ||
return; | ||
} | ||
|
||
if ( | ||
typeof this.checkedBins != 'undefined' && | ||
typeof this.checkedBins[newValue] != 'undefined' | ||
){ | ||
this.binValue = newValue; | ||
this.selectedBrand = this.checkedBins[newValue]; | ||
return; | ||
} | ||
if (this.validate(formattedNewValue)) { | ||
this.binValue = formattedNewValue; | ||
this.getBrand().done(function (data) { | ||
this.saveBinInformation(data); | ||
}.bind(this)); | ||
|
||
if (this.validate(newValue)) { | ||
this.binValue = newValue; | ||
this.getBrand().done(function (data) { | ||
this.saveBinInformation(data); | ||
}.bind(this)); | ||
return; | ||
} | ||
|
||
return; | ||
} | ||
this.selectedBrand = ''; | ||
} | ||
formatNumber(number) { | ||
const newValue = String(number); | ||
return newValue.slice(0, 6); | ||
} | ||
validate(newValue) { | ||
if (newValue.length == 6 && this.binValue != newValue) { | ||
return true; | ||
} | ||
|
||
this.selectedBrand = ''; | ||
}; | ||
return false; | ||
} | ||
getBrand() { | ||
const bin = this.binValue.slice(0, 6); | ||
|
||
Bin.prototype.formatNumber = function (number) { | ||
var newValue = String(number); | ||
return newValue.slice(0, 6); | ||
}; | ||
return $.ajax({ | ||
type: 'GET', | ||
dataType: 'json', | ||
url: 'https://api.mundipagg.com/bin/v1/' + bin, | ||
async: false, | ||
cache: true, | ||
}); | ||
} | ||
saveBinInformation(data) { | ||
if (typeof this.checkedBins == 'undefined') { | ||
this.checkedBins = []; | ||
} | ||
|
||
Bin.prototype.validate = function (newValue) { | ||
if (newValue.length == 6 && this.binValue != newValue) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
Bin.prototype.getBrand = function () { | ||
var bin = this.binValue.slice(0, 6); | ||
|
||
return jQuery.ajax({ | ||
type: 'GET', | ||
dataType: 'json', | ||
url: 'https://api.mundipagg.com/bin/v1/' + bin, | ||
async: false, | ||
cache: true, | ||
}); | ||
}; | ||
|
||
Bin.prototype.saveBinInformation = function (data) { | ||
if (typeof this.checkedBins == 'undefined') { | ||
this.checkedBins = []; | ||
} | ||
|
||
this.checkedBins[this.binValue] = data.brand; | ||
this.selectedBrand = data.brand; | ||
}; | ||
this.checkedBins[this.binValue] = data.brand; | ||
this.selectedBrand = data.brand; | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
var CreditCardToken = function (formObject, documentNumber = null) { | ||
this.documentNumber = documentNumber; | ||
if (documentNumber != null) { | ||
this.documentNumber = documentNumber.replace(/(\.|\/|\-)/g,""); | ||
} | ||
this.formObject = formObject; | ||
}; | ||
|
||
CreditCardToken.prototype.getDataToGenerateToken = function () { | ||
return { | ||
type: "card", | ||
card : { | ||
holder_name: this.formObject.creditCardHolderName.val(), | ||
number: this.formObject.creditCardNumber.val(), | ||
exp_month: this.formObject.creditCardExpMonth.val(), | ||
exp_year: this.formObject.creditCardExpYear.val(), | ||
cvv: this.formObject.creditCardCvv.val(), | ||
holder_document: this.documentNumber | ||
define([], () => { | ||
return class CreditCardToken { | ||
constructor(formObject, documentNumber = null) { | ||
this.documentNumber = documentNumber; | ||
if (documentNumber != null) { | ||
this.documentNumber = documentNumber.replace(/(\.|\/|\-)/g,""); | ||
} | ||
this.formObject = formObject; | ||
} | ||
}; | ||
} | ||
|
||
CreditCardToken.prototype.getToken = function (pkKey) { | ||
var data = this.getDataToGenerateToken(); | ||
getDataToGenerateToken() { | ||
return { | ||
type: "card", | ||
card : { | ||
holder_name: this.formObject.creditCardHolderName.val(), | ||
number: this.formObject.creditCardNumber.val(), | ||
exp_month: this.formObject.creditCardExpMonth.val(), | ||
exp_year: this.formObject.creditCardExpYear.val(), | ||
cvv: this.formObject.creditCardCvv.val(), | ||
holder_document: this.documentNumber | ||
} | ||
}; | ||
} | ||
getToken(pkKey) { | ||
const data = this.getDataToGenerateToken(); | ||
|
||
const url = 'https://api.mundipagg.com/core/v1/tokens?appId='; | ||
const url = 'https://api.mundipagg.com/core/v1/tokens?appId='; | ||
|
||
return jQuery.ajax({ | ||
type: 'POST', | ||
dataType: 'json', | ||
url: url + pkKey, | ||
async: false, | ||
cache: true, | ||
data | ||
}); | ||
} | ||
return jQuery.ajax({ | ||
type: 'POST', | ||
dataType: 'json', | ||
url: url + pkKey, | ||
async: false, | ||
cache: true, | ||
data | ||
}); | ||
} | ||
} | ||
}); |
Oops, something went wrong.