Skip to content

Commit

Permalink
Merge pull request #125 from buckaroo-it/develop
Browse files Browse the repository at this point in the history
version 3.4.0
  • Loading branch information
serpentscode authored Sep 8, 2022
2 parents 1ce09f0 + 96eb442 commit 7c74e1e
Show file tree
Hide file tree
Showing 59 changed files with 5,822 additions and 932 deletions.
44 changes: 28 additions & 16 deletions Buckaroo_Load_Gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class Buckaroo_Load_Gateways
'filename' => 'gateway-buckaroo-klarnapii.php',
'classname' => 'WC_Gateway_Buckaroo_KlarnaPII'
),
'KlarnaKp' => array(
'filename' => 'gateway-buckaroo-klarnakp.php',
'classname' => 'WC_Gateway_Buckaroo_KlarnaKp'
),
'P24' => array(
'filename' =>
'gateway-buckaroo-p24.php',
Expand Down Expand Up @@ -178,18 +182,24 @@ public function hook_gateways_to_woocommerce($methods)
*
* @return void
*/
protected function load_gateways()
{
foreach ($this->methods as $method) {
require_once $this->dir . $method['filename'];
}
require_once $this->dir. "gateways-creditcard/gateway-buckaroo-creditcard-single.php";

foreach ($this->get_creditcard_methods() as $method) {
require_once $this->dir . $method['filename'];
}

}
protected function load_gateways()
{
foreach ($this->methods as $method) {
$file = $this->dir . $method['filename'];
if(file_exists($file)) {
require_once $file;
}
}
require_once $this->dir. "gateways-creditcard/gateway-buckaroo-creditcard-single.php";

foreach ($this->get_creditcard_methods() as $method) {
$file = $this->dir . $method['filename'];
if(file_exists($file)) {
require_once $file;
}
}

}
/**
* Get all gateways
*
Expand Down Expand Up @@ -231,10 +241,12 @@ protected function get_creditcard_methods()


foreach ($this->get_creditcards_to_show() as $creditcard) {
$creditcardMethods[$creditcard.'_creditcard'] = array(
'filename' => "gateways-creditcard/gateway-buckaroo-${creditcard}.php",
'classname' => 'WC_Gateway_Buckaroo_'.ucfirst($creditcard)
);
if (strlen(trim($creditcard)) !== 0) {
$creditcardMethods[$creditcard.'_creditcard'] = array(
'filename' => "gateways-creditcard/gateway-buckaroo-${creditcard}.php",
'classname' => 'WC_Gateway_Buckaroo_'.ucfirst($creditcard)
);
}
}
return $creditcardMethods;
}
Expand Down
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Contribution Guidelines

### Repository setup:
- Fork the repository to your account.
- More details about [how to fork a repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) can be found [here](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo).

### Making changes:
- Create a branch from the develop branch (if there is a develop branch).
- The name of the branch should be something like: `feature/GITHUB-ISSUE-ID-slug` (eg: `feature/50-configprovider-update`)
- Your code changes should follow the WooCommerce coding standard.
- Including unit tests is encouraged.

### Pull Request:
- Open the PR to the develop branch (if there is a develop branch).
- If there is no issue referenced, add a description about the problem and the way it is being solved.
- Allow edits from maintainers.
1 change: 1 addition & 0 deletions assets/js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
108 changes: 0 additions & 108 deletions assets/js/checkout.js

This file was deleted.

112 changes: 112 additions & 0 deletions assets/js/checkout/checkout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
class BuckarooCheckout {
listen() {
let self = this;
jQuery("body").on("change", 'input[name="payment_method"]', function () {
jQuery("body").trigger("update_checkout");
});
jQuery("body").on("updated_checkout", function (e) {
self.afterpay();
self.afterpaynew();
self.bilink();
self.klarna();
});
/**
* toggle between bilink payment types on company name change
*/
jQuery("#billing_company").on("input", function () {
self.bilink_toggle(jQuery(this).val());

jQuery("#buckaroo-afterpaynew-coc")
.parent()
.toggle(jQuery.trim(jQuery(this).val()).length !== 0);
});
/**
* toggle in3 coc & company name if debtor
*/
jQuery("body").on("change", "#buckaroo-in3-orderas", function () {
jQuery(
"#buckaroo-in3-coc-container, #buckaroo-in3-companyname-container"
).toggle(jQuery(this).val().toLowerCase() !== "debtor");
});

/**
* toggle afterpay b2b fields
*/
jQuery("body").on("change", "#buckaroo-afterpay-b2b", function () {
let b2bActive = jQuery(this).is(":checked");
let birthdate = jQuery("#buckaroo-afterpay-birthdate");
let birthdateParent = birthdate.parent();

let gender = jQuery('[name="buckaroo-afterpay-gender"]');
let genderParent = gender.parent();

jQuery("#showB2BBuckaroo").toggle(b2bActive);

if (jQuery("#billing_company").length) {
jQuery("#buckaroo-afterpay-CompanyName").val(
jQuery("#billing_company").val()
);
}

birthdate.prop("disabled", !b2bActive);
birthdateParent.toggle(!b2bActive);
birthdateParent.toggleClass("validate-required", !b2bActive);

gender.prop("disabled", !b2bActive);
genderParent.toggle(!b2bActive);
});
}

/**
* toggle phone number
*/
afterpay() {
if (jQuery("input[name=billing_phone]").length) {
jQuery("#buckaroo-afterpay-phone").parent().hide();
}
}
/**
* toggle phone number
*/
afterpaynew() {
if (jQuery("input[name=billing_phone]").length) {
jQuery("#buckaroo-afterpaynew-phone").parent().hide();
}
jQuery("#buckaroo-afterpaynew-coc")
.parent()
.toggle(jQuery.trim(jQuery("input[name=billing_company]").val()).length !== 0);
}
/**
* toggle between bilink payment types
*/
bilink() {
let billinkCompany = jQuery("#billing_company");
if (billinkCompany.length) {
this.bilink_toggle(billinkCompany.val());
}
}
/**
* toggle between bilink payment types
*
* @param {string} val Company field value
*/
bilink_toggle(val) {
let billinkB2b = jQuery("#buckaroo_billink_b2b");
let billinkB2c = jQuery("#buckaroo_billink_b2c");
if (billinkB2b.length && billinkB2c.length) {
var toggleState = jQuery.trim(val).length > 0;
billinkB2b.toggle(toggleState);
billinkB2c.toggle(!toggleState);
}
}
/**
* hide karna phone if exists
*/
klarna() {
if (jQuery("input[name=billing_phone]").length) {
jQuery('input[id^="buckaroo-klarna"][type="tel"]').parent().hide();
}
}
}

export default BuckarooCheckout;
59 changes: 29 additions & 30 deletions ...y/js/9yards/creditcard-call-encryption.js → ...js/checkout/creditcard-call-encryption.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
buckarooValidateCreditCards = {
form: jQuery('form[name=checkout]'),
validator: BuckarooClientSideEncryption.V001,
import BuckarooClientSideEncryption from "./creditcard-encryption-sdk";
class BuckarooValidateCreditCards {
form = jQuery('form[name=checkout]');
validator = BuckarooClientSideEncryption.V001;

listen: function() {
var validator = this.validator;
var self = this;
listen() {
let validator = this.validator;
let self = this;
this.form.on('input', ".cardNumber", function(e) {
self.toggleClasses(
validator.validateCardNumber(e.target.value),
Expand Down Expand Up @@ -37,36 +38,37 @@ buckarooValidateCreditCards = {
e.target
);
});
this.form.submit(this.submit);
},
this.form.submit(this.submit.bind(this));
};

toggleClasses: function(valid, target) {
target = $(target);
toggleClasses(valid, target) {
target = jQuery(target);

target.toggleClass("error", !valid);
target.toggleClass("validated", valid);

this.submit();
},
};

submit: function(e) {
var parent = jQuery('input[name="payment_method"]:checked').parent();
var cardNumber = parent.find(".cardNumber").val();
var cvc = parent.find(".cvc").val();
var cardHolderName = parent.find(".cardHolderName").val();
var expirationYear = parent.find(".expirationYear").val();
var expirationMonth = parent.find(".expirationMonth").val();
var cardNumberValid = BuckarooClientSideEncryption.V001.validateCardNumber(cardNumber);
var cvcValid = BuckarooClientSideEncryption.V001.validateCvc(cvc);
var cardHolderNameValid = BuckarooClientSideEncryption.V001.validateCardholderName(cardHolderName);
var expirationYearValid = BuckarooClientSideEncryption.V001.validateYear(expirationYear);
var expirationMonthValid = BuckarooClientSideEncryption.V001.validateMonth(expirationMonth);
submit(e) {
let self = this;
let parent = jQuery('input[name="payment_method"]:checked').parent();
let cardNumber = parent.find(".cardNumber").val();
let cvc = parent.find(".cvc").val();
let cardHolderName = parent.find(".cardHolderName").val();
let expirationYear = parent.find(".expirationYear").val();
let expirationMonth = parent.find(".expirationMonth").val();
let cardNumberValid = BuckarooClientSideEncryption.V001.validateCardNumber(cardNumber);
let cvcValid = BuckarooClientSideEncryption.V001.validateCvc(cvc);
let cardHolderNameValid = BuckarooClientSideEncryption.V001.validateCardholderName(cardHolderName);
let expirationYearValid = BuckarooClientSideEncryption.V001.validateYear(expirationYear);
let expirationMonthValid = BuckarooClientSideEncryption.V001.validateMonth(expirationMonth);
if (cardNumberValid && cvcValid && cardHolderNameValid && expirationYearValid && expirationMonthValid) {
this.getEncryptedData(cardNumber, expirationYear, expirationMonth, cvc, cardHolderName, parent);
self.getEncryptedData(cardNumber, expirationYear, expirationMonth, cvc, cardHolderName, parent);
}
},
};

getEncryptedData: function(cardNumber, year, month, cvc, cardholder, parent) {
getEncryptedData(cardNumber, year, month, cvc, cardholder, parent) {
BuckarooClientSideEncryption.V001.encryptCardData(cardNumber,
year,
month,
Expand All @@ -78,7 +80,4 @@ buckarooValidateCreditCards = {
}
};


jQuery(function() {
buckarooValidateCreditCards.listen();
})
export default BuckarooValidateCreditCards;
Loading

0 comments on commit 7c74e1e

Please sign in to comment.