Skip to content

Commit

Permalink
feat: compatibilization with bundle js
Browse files Browse the repository at this point in the history
  • Loading branch information
mateus-picoloto authored Aug 11, 2023
1 parent b449d91 commit a1200bf
Show file tree
Hide file tree
Showing 29 changed files with 2,870 additions and 2,883 deletions.
113 changes: 56 additions & 57 deletions view/frontend/web/js/core/checkout/Bin.js
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;
}
};
});
68 changes: 35 additions & 33 deletions view/frontend/web/js/core/checkout/CreditCardToken.js
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
});
}
}
});
Loading

0 comments on commit a1200bf

Please sign in to comment.