diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index abe9083..d11f43d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -65,7 +65,7 @@ test-cypress-1: - curl --retry 10 --retry-delay 20 -v http:\/\/${DOCKER_SERVICE}-${CI_COMMIT_REF_SLUG}-${CI_JOB_ID}-web/ - cd bin/tests - yarn install - - bash ./run_test.sh -p 0 -e $EXCLUDED_TEST_FILES --config baseUrl=http://${DOCKER_SERVICE}-${CI_COMMIT_REF_SLUG}-${CI_JOB_ID}-web/ --env $CYPRESS_ENV + - bash /tools/run-cypress-test.sh -f $TESTS_FOLDERS_1 -e $EXCLUDED_TEST_FILES --config baseUrl=http://${DOCKER_SERVICE}-${CI_COMMIT_REF_SLUG}-${CI_JOB_ID}-web/ --env $CYPRESS_ENV after_script: - /tools/clean-job.sh $PROJECT_NAME_TEST_1 docker-compose.test.yml wordpress ${DOCKER_STACK}-${DOCKER_SERVICE}_web:${CI_COMMIT_REF_SLUG} @@ -82,7 +82,7 @@ test-cypress-2: - curl --retry 10 --retry-delay 20 -v http:\/\/${DOCKER_SERVICE}-${CI_COMMIT_REF_SLUG}-${CI_JOB_ID}-web/ - cd bin/tests - yarn install - - bash ./run_test.sh -p 1 -e $EXCLUDED_TEST_FILES --config baseUrl=http://${DOCKER_SERVICE}-${CI_COMMIT_REF_SLUG}-${CI_JOB_ID}-web/ --env $CYPRESS_ENV + - bash /tools/run-cypress-test.sh -f $TESTS_FOLDERS_2 -e $EXCLUDED_TEST_FILES --config baseUrl=http://${DOCKER_SERVICE}-${CI_COMMIT_REF_SLUG}-${CI_JOB_ID}-web/ --env $CYPRESS_ENV after_script: - /tools/clean-job.sh $PROJECT_NAME_TEST_2 docker-compose.test.yml wordpress ${DOCKER_STACK}-${DOCKER_SERVICE}_web:${CI_COMMIT_REF_SLUG} diff --git a/bin/docker/images/woocommerce/setup-woocommerce.sh b/bin/docker/images/woocommerce/setup-woocommerce.sh index 12cd03f..e8fdf20 100644 --- a/bin/docker/images/woocommerce/setup-woocommerce.sh +++ b/bin/docker/images/woocommerce/setup-woocommerce.sh @@ -56,6 +56,7 @@ sleep 20 SHIPPING_ZONE=$(wp wc shipping_zone create --allow-root --name="FR" --user=admin-wordpress@hipay.com --porcelain) wp wc --allow-root shipping_zone_method create $SHIPPING_ZONE --method_id="flat_rate" --user=admin-wordpress@hipay.com wp wc --allow-root shop_coupon create --code=test --amount=12.25 --discount_type=percent --user=admin-wordpress@hipay.com + wp wc --allow-root customer create --email='d.denis@hipay.com' --user=1 --password='password123' CONFIG=$(wp option --allow-root get hipay_enterprise --format=json) CONFIG=${CONFIG/'"api_username_sandbox":""'/'"api_username_sandbox":"'$HIPAY_API_USER_TEST'"'} diff --git a/bin/tests/cypress/fixtures/customerFR.json b/bin/tests/cypress/fixtures/customerFR.json index 881b075..7b91916 100644 --- a/bin/tests/cypress/fixtures/customerFR.json +++ b/bin/tests/cypress/fixtures/customerFR.json @@ -6,5 +6,6 @@ "city": "Nantes", "zipCode": "44000", "country": "FR", - "phone": "0210236596" + "phone": "0210236596", + "password": "password123" } diff --git a/bin/tests/cypress/fixtures/order.json b/bin/tests/cypress/fixtures/order.json index 6fd615f..f16f4c8 100644 --- a/bin/tests/cypress/fixtures/order.json +++ b/bin/tests/cypress/fixtures/order.json @@ -1,4 +1,4 @@ { - "lastOrderId": "213", - "lastCapturedOrderId": "" + "lastOrderId": "117", + "lastCapturedOrderId": "145" } \ No newline at end of file diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/014-aura.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/014-astropay-aura.js similarity index 93% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/014-aura.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/014-astropay-aura.js index 2c2bb55..1e3619c 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/014-aura.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/014-astropay-aura.js @@ -5,6 +5,9 @@ describe('Pay by Aura', function () { before(function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("aura"); cy.switchWooCurrency("BRL"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/016-banamex.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/016-astropay-banamex.js similarity index 91% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/016-banamex.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/016-astropay-banamex.js index 87410db..6e979c4 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/016-banamex.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/016-astropay-banamex.js @@ -6,6 +6,9 @@ describe('Pay by Banamex', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("banamex"); cy.switchWooCurrency("MXN"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/017-banco-do-brasil.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/017-astropay-banco-do-brasil.js similarity index 92% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/017-banco-do-brasil.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/017-astropay-banco-do-brasil.js index 3cf1656..45d86ac 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/017-banco-do-brasil.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/017-astropay-banco-do-brasil.js @@ -6,6 +6,9 @@ describe('Pay by Banco Do Brasil', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("banco_do_brasil"); cy.switchWooCurrency("BRL"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/018-bbva-bancomer.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/018-astropay-bbva-bancomer.js similarity index 92% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/018-bbva-bancomer.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/018-astropay-bbva-bancomer.js index 14779a3..58e5b16 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/018-bbva-bancomer.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/018-astropay-bbva-bancomer.js @@ -6,6 +6,9 @@ describe('Pay by BBVA Bancomer', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("bbva_bancomer"); cy.switchWooCurrency("MXN"); cy.adminLogOut(); @@ -31,7 +34,6 @@ describe('Pay by BBVA Bancomer', function () { it('Pay by BBVA Bancomer', function () { - cy.waitOrderUpdate(); cy.get('[for="payment_method_hipayenterprise_bbva_bancomer"]').click({force: true}); cy.get('#bbva-bancomer-national_identification_number') .type(bbvaBancomerJson.data.national_identification_number, {force: true}) diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/019-boleto-bancario.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/019-astropay-boleto-bancario.js similarity index 92% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/019-boleto-bancario.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/019-astropay-boleto-bancario.js index 2c765df..f56cfe5 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/019-boleto-bancario.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/019-astropay-boleto-bancario.js @@ -6,6 +6,9 @@ describe('Pay by Boleto Bancario', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("boleto_bancario"); cy.switchWooCurrency("BRL"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/020-bradesco.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/020-astropay-bradesco.js similarity index 91% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/020-bradesco.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/020-astropay-bradesco.js index fa90aea..e937b96 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/020-bradesco.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/020-astropay-bradesco.js @@ -6,6 +6,9 @@ describe('Pay by Bradesco', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("bradesco"); cy.switchWooCurrency("BRL"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/021-caixa.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/021-astropay-caixa.js similarity index 91% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/021-caixa.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/021-astropay-caixa.js index 1b49ab2..fe78967 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/021-caixa.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/021-astropay-caixa.js @@ -6,6 +6,9 @@ describe('Pay by Caïxa', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("caixa"); cy.switchWooCurrency("BRL"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/022-itau.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/022-astropay-itau.js similarity index 91% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/022-itau.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/022-astropay-itau.js index 1a9c8b6..db980e7 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/022-itau.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/022-astropay-itau.js @@ -6,6 +6,9 @@ describe('Pay by Itau', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("itau"); cy.switchWooCurrency("BRL"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/023-oxxo.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/023-astropay-oxxo.js similarity index 91% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/023-oxxo.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/023-astropay-oxxo.js index 6773bf8..40b314f 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/023-oxxo.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/023-astropay-oxxo.js @@ -6,6 +6,9 @@ describe('Pay by Oxxo', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("oxxo"); cy.switchWooCurrency("MXN"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/024-santander-cash.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/024-astropay-santander-cash.js similarity index 94% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/024-santander-cash.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/024-astropay-santander-cash.js index 930925d..c46966b 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/024-santander-cash.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/024-astropay-santander-cash.js @@ -6,6 +6,9 @@ describe('Pay by Santander Cash', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("santander_cash"); cy.switchWooCurrency("MXN"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/025-santander-home-banking.js b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/025-astropay-santander-home-banking.js similarity index 92% rename from bin/tests/cypress/integration/006_LOCAL_PAYMENTS/025-santander-home-banking.js rename to bin/tests/cypress/integration/006_LOCAL_PAYMENTS/025-astropay-santander-home-banking.js index fae19e7..ec684ea 100644 --- a/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/025-santander-home-banking.js +++ b/bin/tests/cypress/integration/006_LOCAL_PAYMENTS/025-astropay-santander-home-banking.js @@ -6,6 +6,9 @@ describe('Pay by Santander HomeBanking', function () { cy.logToAdmin(); cy.goToPaymentsTab(); + cy.goToAdminHipayConfig(); + cy.activateAstropayMethods(); + cy.goToPaymentsTab(); cy.activatePaymentMethods("santander_home_banking"); cy.switchWooCurrency("BRL"); cy.adminLogOut(); diff --git a/bin/tests/cypress/integration/007_ONE_CLICK/001-one-click.js b/bin/tests/cypress/integration/007_ONE_CLICK/001-one-click.js new file mode 100644 index 0000000..35c21ef --- /dev/null +++ b/bin/tests/cypress/integration/007_ONE_CLICK/001-one-click.js @@ -0,0 +1,104 @@ +describe('Pay by credit card One click', function () { + + it('Pay by : visa_ok', function () { + + cy.logToAdmin(); + cy.goToPaymentsTab(); + cy.activatePaymentMethods("credit_card"); + cy.goToAdminHipayConfig(); + + cy.get('#methods-tab').click(); + cy.get('#operating_mode').select("hosted_fields"); + cy.get('#card_token').check(); + + cy.resetCCConfigForm(); + + cy.get('.submit > .button-primary').click(); + + cy.adminLogOut(); + + cy.customerLogIn(); + cy.goToFront(); + cy.selectItemAndGoToCart(); + cy.addProductQuantity(15); + cy.goToCheckout(); + cy.fillBillingForm(); + + cy.get('[for="payment_method_hipayenterprise_credit_card"]').click({force: true}); + cy.get('#hipay-field-cardHolder > iframe'); + cy.wait(3000); + + cy.fill_hostedfield_card('visa_ok'); + cy.get("#wc-hipayenterprise_credit_card-new-payment-method").check(); + cy.get('#place_order').click({force: true}); + cy.checkOrderSuccess(); + cy.saveLastOrderId(); + }); + + + it('Send authorization notification', function () { + cy.fixture('notification').as("notification"); + cy.connectAndSelectAccountOnHipayBO(); + cy.fixture('order').then((order) => { + cy.openTransactionOnHipayBO(order.lastOrderId + "-"); + cy.openNotificationOnHipayBO(116).then(() => { + cy.sendNotification(this.notification.url, {data: this.data, hash: this.hash}); + }); + }); + }); + + it('Check card in My account', function () { + cy.customerLogIn(); + cy.get('.woocommerce-MyAccount-navigation-link--payment-methods').click(); + cy.get(".woocommerce-MyAccount-paymentMethods > tbody > tr:last-child > td:nth-child(1)") + .contains("Visa ending in 411111******1111"); + + }); + + it('Pay by : one click', function () { + + cy.logToAdmin(); + cy.goToPaymentsTab(); + cy.activatePaymentMethods("credit_card"); + cy.goToAdminHipayConfig(); + + cy.get('#methods-tab').click(); + cy.get('#operating_mode').select("hosted_fields"); + cy.get('#card_token').check(); + + cy.resetCCConfigForm(); + + cy.get('.submit > .button-primary').click(); + + cy.adminLogOut(); + + cy.customerLogIn(); + cy.goToFront(); + cy.selectItemAndGoToCart(); + cy.addProductQuantity(15); + cy.goToCheckout(); + cy.fillBillingForm(); + + cy.get('[for="payment_method_hipayenterprise_credit_card"]').click({force: true}); + cy.get('#hipay-field-cardHolder > iframe'); + cy.wait(3000); + + cy.get('#place_order').click({force: true}); + cy.checkOrderSuccess(); + cy.saveLastOrderId(); + }); + + // it('Add card in My account', function () { + // cy.customerLogIn(); + // cy.get('.woocommerce-MyAccount-navigation-link--payment-methods').click(); + // cy.get('.woocommerce-MyAccount-content > a').click(); + // + // cy.get('[for="payment_method_hipayenterprise_credit_card"]').click({force: true}); + // cy.get('#hipay-field-cardHolder > iframe'); + // cy.wait(3000); + // cy.fill_hostedfield_card('mastercard_ok'); + // cy.get('#place_order').click(); + // cy.get(".woocommerce-MyAccount-paymentMethods > tbody > tr:last-child > td:nth-child(1)") + // .contains("MasterCard ending in 539999******9999"); + // }); +}); diff --git a/bin/tests/cypress/support/admin.js b/bin/tests/cypress/support/admin.js index 6b3f6f0..29df4e2 100644 --- a/bin/tests/cypress/support/admin.js +++ b/bin/tests/cypress/support/admin.js @@ -52,6 +52,11 @@ Cypress.Commands.add("switchWooCurrency", (currency) => { /** * Go to Hipay configuration */ +Cypress.Commands.add("activateAstropayMethods", () => { + cy.get('#enableAstropay').check({force: true}); + cy.get('button[name="save"]').click(); +}); + Cypress.Commands.add("goToAdminHipayConfig", () => { cy.get('[data-gateway_id="hipayenterprise_credit_card"] > .name > .wc-payment-gateway-method-title').click({force: true}); }); diff --git a/bin/tests/cypress/support/checkout.js b/bin/tests/cypress/support/checkout.js index 22cea2b..4d9b0b3 100644 --- a/bin/tests/cypress/support/checkout.js +++ b/bin/tests/cypress/support/checkout.js @@ -225,3 +225,12 @@ Cypress.Commands.add("waitOrderUpdate", () => { cy.route('POST', "/?wc-ajax=update_order_review").as("updateOrder"); cy.wait("@updateOrder"); }); + +Cypress.Commands.add("customerLogIn", () => { + cy.fixture('customerFR').then((customer) => { + cy.visit('/my-account/'); + cy.get('#username').type(customer.email); + cy.get('#password').type(customer.password); + cy.get('[name="login"]').click(); + }); +}); diff --git a/bin/tests/run_test.sh b/bin/tests/run_test.sh deleted file mode 100755 index da33229..0000000 --- a/bin/tests/run_test.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# -------- -# Parse command line options -# ---------- -function parse_args () -{ - while [[ $# -gt 0 ]]; do - opt="$1" - shift - - case "$opt" in - -e|--exclude) - exclude+="$1 " - ;; - -p|--part) - part="$1" - ;; - -c|--config) - config="$1" - ;; - --env) - env="$1" - ;; - esac - done -} - -function join_by () { - local d=$1; shift; - echo -n "$1"; - shift; - printf "%s" "${@/#/$d}"; -} - -function exclude_file () { - local e file="$1" - shift - for e; do [[ "$file" == *"${e%%*( )}"* ]] && return 0; done - return 1 -} - -BACKEND_TESTS_DIR=(cypress/integration/001_BACKEND) -LOCAL_TESTS_DIR=(cypress/integration/006_LOCAL_PAYMENTS) -CREDIT_CARD_TESTS_DIR=(cypress/integration/002_CREDIT_CARD) -NOTIFICATIONS_TESTS_DIR=(cypress/integration/003_NOTIFICATIONS) -BASKET_TESTS_DIR=(cypress/integration/004_BASKET) -CAPTURE_REFUND_TESTS_DIR=(cypress/integration/005_CAPTURE_REFUND) - -parse_args "$@" - -if [ "$part" = "0" ];then - - ARRAY=() - IFS=',' read -a EXCL_ARRAY <<< "${exclude}" - - for file in $BACKEND_TESTS_DIR/* $LOCAL_TESTS_DIR/*; - do - if ! exclude_file "${file}" ${EXCL_ARRAY[@]} ; then - ARRAY+=($file) - fi - done - - TESTS=$(join_by , "${ARRAY[@]}") - - echo $TESTS - $(npm bin)/cypress run --spec "${TESTS}" --config $config --env $env -fi - -if [ "$part" = "1" ];then - - ARRAY=() - IFS=',' read -a EXCL_ARRAY <<< "${exclude}" - - for file in $CREDIT_CARD_TESTS_DIR/* $NOTIFICATIONS_TESTS_DIR/* $BASKET_TESTS_DIR/* $CAPTURE_REFUND_TESTS_DIR/*; - do - if ! exclude_file "${file}" ${EXCL_ARRAY[@]} ; then - ARRAY+=($file) - fi - done - - TESTS=$(join_by , "${ARRAY[@]}") - - echo $TESTS - $(npm bin)/cypress run --spec "${TESTS}" --config $config --env $env -fi diff --git a/src/woocommerce_hipayenterprise/assets/css/frontend/hipay.css b/src/woocommerce_hipayenterprise/assets/css/frontend/hipay.css index f8a3431..7c1d6bc 100644 --- a/src/woocommerce_hipayenterprise/assets/css/frontend/hipay.css +++ b/src/woocommerce_hipayenterprise/assets/css/frontend/hipay.css @@ -1,3 +1,21 @@ +.msg-local-payment { + margin-top: 15px; +} + +.sdd { + width: 100% +} + +#wc-hipayenterprise_credit_card-new-payment-method { + margin-left: 10px; +} + +.hosted-page{ + padding-left: 30px; + padding-top: 10px; + padding-bottom: 10px; +} + .woocommerce-hipay-error { background-color: #e2401c; list-style: none; @@ -44,8 +62,7 @@ font-weight: bold; } - -.error-text-hp{ +.error-text-hp { font-weight: bold; color: #ff4c4c; font-size: 12px; diff --git a/src/woocommerce_hipayenterprise/assets/css/frontend/hosted-fields.css b/src/woocommerce_hipayenterprise/assets/css/frontend/hosted-fields.css index a3d0ca7..233c3ca 100644 --- a/src/woocommerce_hipayenterprise/assets/css/frontend/hosted-fields.css +++ b/src/woocommerce_hipayenterprise/assets/css/frontend/hosted-fields.css @@ -5,35 +5,9 @@ text-align: center; } -#hipay-container-hosted-fields { - width: 500px; - padding: 20px; - display: inline-block; - border: 1px solid #ddd; - box-shadow: 0 2px 4px rgba(0, 0, 0, .1); - margin: 10px; -} - -#hipay-container-hosted-fields span.icon { - position: relative; - top: 0.2em; - margin-right: 0.2em; -} - -@media screen and (max-width: 768px) { - #hipay-container-hosted-fields { - max-width: 500px; - width: auto; - display: block; - } -} - -@media (min-width: 768px) { - #hipay-container-hosted-fields .actions-toolbar .primary { - width: 100% !important; - margin-top: 10px !important; - float: none !important; - } +.hipay-container-hosted-fields { + margin-top: 10px; + width: 100%; } .hipay-row { diff --git a/src/woocommerce_hipayenterprise/assets/js/frontend/form-input-control.js b/src/woocommerce_hipayenterprise/assets/js/frontend/form-input-control.js index fee816b..c63ccc9 100755 --- a/src/woocommerce_hipayenterprise/assets/js/frontend/form-input-control.js +++ b/src/woocommerce_hipayenterprise/assets/js/frontend/form-input-control.js @@ -238,7 +238,7 @@ function normalizePrice(price) { */ function checkNotEmptyField(element) { - if (element.value === null || element.value === "") { + if (inputEmpty(element)) { errorMessage(element, hipay_i18n.i18nFieldIsMandatory); return false; } @@ -246,6 +246,15 @@ function checkNotEmptyField(element) { return true; } +/** + * + * @param element + * @returns {boolean} + */ +function inputEmpty(element) { + return element.value === null || element.value === ""; +} + /** * * @param {type} element @@ -253,11 +262,7 @@ function checkNotEmptyField(element) { */ function checkIban(element) { - if (!checkNotEmptyField(element)) { - return false; - } - - if (!validIBAN(element.value)) { + if (!inputEmpty(element) && !validIBAN(element.value)) { errorMessage(element, hipay_i18n.i18nBadIban); return false; } @@ -271,11 +276,7 @@ function checkIban(element) { */ function checkBic(element) { - if (!checkNotEmptyField(element)) { - return false; - } - - if (!validBic(element.value)) { + if (!inputEmpty(element) && !validBic(element.value)) { errorMessage(element, hipay_i18n.i18nBadBic); return false; } @@ -289,11 +290,7 @@ function checkBic(element) { */ function checkCPF(element) { - if (!checkNotEmptyField(element)) { - return false; - } - - if (!isCPFValid(element.value)) { + if (!inputEmpty(element) && !isCPFValid(element.value)) { errorMessage(element, hipay_i18n.i18nBadCPF); return false; } @@ -307,11 +304,7 @@ function checkCPF(element) { */ function checkCPNCURP(element) { - if (!checkNotEmptyField(element)) { - return false; - } - - if (!isCPNCURPValid(element.value)) { + if (!inputEmpty(element) && !isCPNCURPValid(element.value)) { errorMessage(element, hipay_i18n.i18nBadCPNCURP); return false; } @@ -327,6 +320,10 @@ function typeControlCheck(input) { var element = document.getElementById(input.field); removeClass(element, "error-input-hp"); + if (input.required && !checkNotEmptyField(element)) { + return false; + } + switch (input.type) { case "iban": return checkIban(element); @@ -336,8 +333,6 @@ function typeControlCheck(input) { return checkCPF(element); case "curp-cpn": return checkCPNCURP(element); - default : - return checkNotEmptyField(element); } } diff --git a/src/woocommerce_hipayenterprise/assets/js/frontend/hosted-fields.js b/src/woocommerce_hipayenterprise/assets/js/frontend/hosted-fields.js index bd0931e..e21e417 100755 --- a/src/woocommerce_hipayenterprise/assets/js/frontend/hosted-fields.js +++ b/src/woocommerce_hipayenterprise/assets/js/frontend/hosted-fields.js @@ -6,14 +6,14 @@ jQuery(function ($) { checkout_form: $('form.checkout'), - init: function () { + init: function (form) { var self = this; + this.form = form; this.checkout_form.on('change', '#billing_first_name, #billing_last_name', function () { $(document.body).trigger('update_checkout'); }); - // Evenement plutot sur le onSubmit $(document.body).on('click', '#place_order', function (e) { self.submitOrder(e, self); }); @@ -49,7 +49,7 @@ jQuery(function ($) { this.configHostedFields = { selector: "hipayHF-container", - multi_use: false, + multi_use: hipay_config.oneClick === "1", fields: { cardHolder: { selector: "hipay-field-cardHolder", @@ -84,8 +84,42 @@ jQuery(function ($) { hostedFieldsInstance = this.hipaySDK.create("card", this.configHostedFields); var self = this; - hostedFieldsInstance.on("change", function (data) { - self.handleError(data.valid, data.error); + hostedFieldsInstance.on("blur", function (data) { + // Get error container + let domElement = document.querySelector( + `[data-hipay-id='hipay-field-error-${data.element}']` + ); + + // Finish function if no error DOM element + if (!domElement) { + return; + } + + // If not valid & not empty add error + if (!data.validity.valid || data.validity.empty) { + domElement.innerText = data.validity.error; + } else { + domElement.innerText = ''; + } + }); + + hostedFieldsInstance.on("inputChange", function (data) { + // Get error container + let domElement = document.querySelector( + `[data-hipay-id='hipay-field-error-${data.element}']` + ); + + // Finish function if no error DOM element + if (!domElement) { + return; + } + + // If not valid & not potentiallyValid add error (input is focused) + if (!data.validity.valid && !data.validity.potentiallyValid) { + domElement.innerText = data.validity.error; + } else { + domElement.innerText = ''; + } }); hostedFieldsInstance.on("ready", function () { @@ -112,7 +146,7 @@ jQuery(function ($) { * @param response */ processPayment: function () { - $('form[name="checkout"]').submit(); + this.form.submit(); }, /** @@ -124,14 +158,17 @@ jQuery(function ($) { $("#payment-product").val(result.payment_product); $("#card-token").val(result.token); $("#card-holder").val(result.card_holder); + $("#card-pan").val(result.pan.replace(/x/g, '*')); + $("#card-expiry-month").val(result.card_expiry_month); + $("#card-expiry-year").val(result.card_expiry_year); }, /** * * @returns {boolean} */ - isHipayHostedFieldsSelected: function () { - return $('input[name="payment_method"]:checked').val() === hipay_config.hipay_gateway_id; + isCreditCardSelected: function () { + return $('input[name="payment_method"]:checked').val() === 'hipayenterprise_credit_card'; }, /** @@ -141,45 +178,62 @@ jQuery(function ($) { return $("#hipayHF-container").length; }, - /** - * - * @param e - * @param hostedFields - */ - submitOrder: function (e, hostedFields) { - if (hostedFields.containerExist() && hostedFields.isHipayHostedFieldsSelected()) { - e.preventDefault(); - e.stopPropagation(); - hostedFieldsInstance.createToken() - .then(function (response) { - if (isCardTypeActivated(response)) { - hostedFields.applyTokenization(response); - hostedFields.processPayment(); - } else { - hostedFields.handleError(true, hipay_config_i18n.activated_card_error); - } - }, - function (error) { - hostedFields.handleError(true, error); + isHiPayMethod: function () { + return $('input[name="payment_method"]:checked').val().indexOf('hipayenterprise_') !== -1; + }, + + handleTokenization: function () { + hostedFieldsInstance.createToken() + .then(function (response) { + if (isCardTypeActivated(response)) { + hostedFields.applyTokenization(response); + hostedFields.processPayment(); + } else { + hostedFields.handleError(true, hipay_config_i18n.activated_card_error); } - ); + }, + function (error) { + hostedFields.handleError(true, error); + } + ); + }, + + handleLocalPayments: function () { + var hipayMethod = $('input[name="payment_method"]:checked') + .val() + .replace('hipayenterprise_', '') + .replace('_', '-'); + + if (hiPayInputControl.checkControl(hipayMethod)) { + hostedFields.processPayment(); } else { + $([document.documentElement, document.body]).animate({ + scrollTop: $('input[name="payment_method"]:checked').offset().top + }, 1000); + } + }, + + isOneClick: function () { + return $('input[name="wc-hipayenterprise_credit_card-payment-token"]:checked').val() !== undefined + && $('input[name="wc-hipayenterprise_credit_card-payment-token"]:checked').val() !== 'new' + && this.isCreditCardSelected(); + }, + + submitOrder: function (e, hostedFields) { + + if (hostedFields.isHiPayMethod()) { e.preventDefault(); e.stopPropagation(); - var hipayMethod = $('input[name="payment_method"]:checked') - .val() - .replace('hipayenterprise_','') - .replace('_', '-'); - - if (hiPayInputControl.checkControl(hipayMethod)) { + if (hostedFields.isOneClick()) { hostedFields.processPayment(); - }else{ - $([document.documentElement, document.body]).animate({ - scrollTop: $('input[name="payment_method"]:checked').offset().top - }, 1000); + } else if (hostedFields.containerExist() && hostedFields.isCreditCardSelected()) { + hostedFields.handleTokenization(); + } else { + hostedFields.handleLocalPayments(); } } + } }; @@ -193,7 +247,11 @@ jQuery(function ($) { } $(document.body).on('updated_checkout', function () { - hostedFields.init(); + hostedFields.init($('form[name="checkout"]')); + }); + + $(document.body).on('init_add_payment_method', function () { + hostedFields.init($('#add_payment_method')); }); }); diff --git a/src/woocommerce_hipayenterprise/class-wc-hipay-enterprise.php b/src/woocommerce_hipayenterprise/class-wc-hipay-enterprise.php index 4e86fbe..7dade36 100644 --- a/src/woocommerce_hipayenterprise/class-wc-hipay-enterprise.php +++ b/src/woocommerce_hipayenterprise/class-wc-hipay-enterprise.php @@ -47,8 +47,7 @@ public function initPlugin() $currentPluginVersion = get_option('hipay_enterprise_version'); - if (!empty($currentPluginVersion) - && WC_HIPAYENTERPRISE_VERSION !== $currentPluginVersion) { + if (!empty($currentPluginVersion) && WC_HIPAYENTERPRISE_VERSION !== $currentPluginVersion) { $this->updatePlugin($currentPluginVersion); } else if (empty($currentPluginVersion)) { $this->installPlugin(); @@ -94,7 +93,17 @@ public function installPlugin() */ public function addGateway($methods) { + $config = new Hipay_Config(); + $localMethod = Hipay_Autoloader::getLocalMethodsNames(); + if (!$config->getPaymentGlobal()["enableAstropay"]) { + $localMethod = array_filter( + $localMethod, + function ($value) { + return !strpos($value, 'Astropay'); + } + ); + } $methods[] = 'Gateway_Hipay'; return array_merge($methods, $localMethod); } diff --git a/src/woocommerce_hipayenterprise/composer.json b/src/woocommerce_hipayenterprise/composer.json index 5c211cf..28bf6f4 100755 --- a/src/woocommerce_hipayenterprise/composer.json +++ b/src/woocommerce_hipayenterprise/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "hipay/hipay-fullservice-sdk-php": "1.10.0" + "hipay/hipay-fullservice-sdk-php": "2.0.1" }, "require-dev": { "phpunit/phpunit": "5.6.1" diff --git a/src/woocommerce_hipayenterprise/includes/admin/class-hipay-admin-capture.php b/src/woocommerce_hipayenterprise/includes/admin/class-hipay-admin-capture.php index fa3c81b..37a5e5c 100644 --- a/src/woocommerce_hipayenterprise/includes/admin/class-hipay-admin-capture.php +++ b/src/woocommerce_hipayenterprise/includes/admin/class-hipay-admin-capture.php @@ -34,7 +34,12 @@ public function __construct() add_action('woocommerce_admin_order_totals_after_total', array($this, 'totals_after_total')); add_action('wp_ajax_woocommerce_capture_line_items', array($this, 'capture_line_items')); add_action('woocommerce_order_item_line_item_html', array($this, 'admin_order_item_line_items_html'), 10, 3); - add_action('woocommerce_admin_order_items_after_shipping', array($this, 'admin_order_items_after_shipping'), 10, 1); + add_action( + 'woocommerce_admin_order_items_after_shipping', + array($this, 'admin_order_items_after_shipping'), + 10, + 1 + ); add_filter('woocommerce_data_stores', array($this, 'filter_woocommerce_data_stores')); } @@ -57,7 +62,8 @@ public function admin_order_items_after_shipping($order_id) 'item_id' => $item_id, 'item' => $item, 'order' => $order - )); + ) + ); } } } @@ -111,8 +117,14 @@ public function capture_line_items() } $order_id = absint($_POST['order_id']); - $capture_amount = wc_format_decimal(sanitize_text_field(wp_unslash($_POST['capture_amount'])), wc_get_price_decimals()); - $captured_amount = wc_format_decimal(sanitize_text_field(wp_unslash($_POST['captured_amount'])), wc_get_price_decimals()); + $capture_amount = wc_format_decimal( + sanitize_text_field(wp_unslash($_POST['capture_amount'])), + wc_get_price_decimals() + ); + $captured_amount = wc_format_decimal( + sanitize_text_field(wp_unslash($_POST['captured_amount'])), + wc_get_price_decimals() + ); $line_item_qtys = json_decode(sanitize_text_field(wp_unslash($_POST['line_item_qtys'])), true); $line_item_totals = json_decode(sanitize_text_field(wp_unslash($_POST['line_item_totals'])), true); $line_item_tax_totals = json_decode(sanitize_text_field(wp_unslash($_POST['line_item_tax_totals'])), true); @@ -120,13 +132,17 @@ public function capture_line_items() try { $order = wc_get_order($order_id); - $max_capture = wc_format_decimal($order->get_total() - Hipay_Order_Helper::get_total_captured($order), wc_get_price_decimals()); + $max_capture = wc_format_decimal( + $order->get_total() - Hipay_Order_Helper::get_total_captured($order), + wc_get_price_decimals() + ); if (!$capture_amount || $max_capture < $capture_amount || 0 > $capture_amount) { throw new exception(__('Invalid capture amount', 'woocommerce')); } - if ($captured_amount !== wc_format_decimal(Hipay_Order_Helper::get_total_captured($order), wc_get_price_decimals())) { + if ($captured_amount !== + wc_format_decimal(Hipay_Order_Helper::get_total_captured($order), wc_get_price_decimals())) { throw new exception(__('Error processing capture. Please try again.', 'woocommerce')); } @@ -202,8 +218,13 @@ public function create_capture_item($args = array()) throw new Exception(__('Invalid order ID.', 'woocommerce')); } - $remaining_capture_amount = wc_format_decimal($order->get_total() - Hipay_Order_Helper::get_total_captured($order), wc_get_price_decimals()); - $remaining_capture_items = absint($order->get_item_count() - Hipay_Order_Helper::get_item_count_captured('', $order)); + $remaining_capture_amount = wc_format_decimal( + $order->get_total() - Hipay_Order_Helper::get_total_captured($order), + wc_get_price_decimals() + ); + $remaining_capture_items = absint( + $order->get_item_count() - Hipay_Order_Helper::get_item_count_captured('', $order) + ); $capture_item_count = 0; $capture = new Hipay_Order_Capture($args['capture_id']); @@ -228,7 +249,9 @@ public function create_capture_item($args = array()) $qty = isset($args['line_items'][$item_id]['qty']) ? $args['line_items'][$item_id]['qty'] : 0; $capture_total = $args['line_items'][$item_id]['capture_total']; - $capture_tax = isset($args['line_items'][$item_id]['capture_tax']) ? array_filter((array)$args['line_items'][$item_id]['capture_tax']) : array(); + $capture_tax = isset($args['line_items'][$item_id]['capture_tax']) ? array_filter( + (array)$args['line_items'][$item_id]['capture_tax'] + ) : array(); if (empty($qty) && empty($capture_total) && empty($args['line_items'][$item_id]['capture_tax'])) { continue; @@ -291,7 +314,8 @@ public function create_capture_item($args = array()) // Trigger notification emails. - if (($remaining_capture_amount - $args['amount']) > 0 || ($order->has_free_item() && ($remaining_capture_items - $capture_item_count) > 0)) { + if (($remaining_capture_amount - $args['amount']) > 0 || + ($order->has_free_item() && ($remaining_capture_items - $capture_item_count) > 0)) { do_action('woocommerce_order_partially_captured', $order->get_id(), $capture->get_id()); } else { do_action('woocommerce_order_fully_captured', $order->get_id(), $capture->get_id()); @@ -341,13 +365,20 @@ function manual_capture($order, $amount, $reason = '') } if (!$gateway->supports('captures')) { - throw new Exception(__('The payment gateway for this order does not support automatic captures.', 'woocommerce')); + throw new Exception( + __('The payment gateway for this order does not support automatic captures.', 'woocommerce') + ); } $result = $gateway->process_capture($order->get_id(), $amount); if (!$result) { - throw new Exception(__('An error occurred while attempting to create the refund using the payment gateway API.', 'woocommerce')); + throw new Exception( + __( + 'An error occurred while attempting to create the refund using the payment gateway API.', + 'woocommerce' + ) + ); } if (is_wp_error($result)) { @@ -372,22 +403,25 @@ public function add_action_buttons($order) $payment_gateways = WC()->payment_gateways->payment_gateways(); } - if (isset($payment_gateways[$order->get_payment_method()]) && $payment_gateways[$order->get_payment_method()]->supports('refunds')) { + if ( + isset($payment_gateways[$order->get_payment_method()]) && + $payment_gateways[$order->get_payment_method()]->supports('captures') + ) { $payment_gateway = $payment_gateways[$order->get_payment_method()]; - } - if (!in_array($order->get_status(), array('completed', 'canceled'), true) - && 0 < $order->get_total() - Hipay_Order_Helper::get_total_captured($order)) { - Hipay_Helper::process_template( - 'html-order-additional.php', - 'admin', - array( - 'payment_gateway' => $payment_gateway, - 'order' => $order - ) - ); - } + if (!in_array($order->get_status(), array('completed', 'canceled'), true) + && 0 < $order->get_total() - Hipay_Order_Helper::get_total_captured($order)) { + Hipay_Helper::process_template( + 'html-order-additional.php', + 'admin', + array( + 'payment_gateway' => $payment_gateway, + 'order' => $order + ) + ); + } + } } /** @@ -396,14 +430,17 @@ public function add_action_buttons($order) public function totals_after_total($order_id) { $order = wc_get_order($order_id); - if (Hipay_Order_Helper::get_total_captured($order) > 0 ) { - ?> + if (Hipay_Order_Helper::get_total_captured($order) > 0) { + ?> : - $order->get_currency())); ?> $order->get_currency()) + ); ?> - -