Plugin Directory

Changeset 2776894


Ignore:
Timestamp:
08/29/2022 04:04:15 AM (4 years ago)
Author:
zipmoney
Message:

add tokenisation feature

Location:
zipmoney-payments-woocommerce
Files:
242 added
18 edited

Legend:

Unmodified
Added
Removed
  • zipmoney-payments-woocommerce/trunk/README.txt

    r2685692 r2776894  
    33Tags: zipmoney payments woocommerce, zipmoney payments module for woocommerce, zipmoney woocommerce addon , zipmoney payment gateway for woocommerce, zipmoney for woocommerce, zipmoney payment gateway for wordpress, buy now pay later, zippay woocommerce plugin, Own it now, pay later, Zip Co, Zip
    44Requires at least: WP 4.0
    5 Tested up to: 5.9
    6 Stable tag: 2.3.13
     5Tested up to: 6.0.1
     6Stable tag: 2.3.14
    77License: GPLv2 or later License http://www.gnu.org/licenses/gpl-2.0.html
    88
     
    207207* Plugin tested under wordpress version 5.9
    208208* fixed Divi plugin Interfering issue
     209
     210= 2.3.14 =
     211* Plugin tested under wordpress version 6.0.1
     212* Plugin tested under woocommerce version 6.7.0
     213* Added tokenisation feature
  • zipmoney-payments-woocommerce/trunk/assets/css/woocommerce-zipmoney-payment-front.css

    r2464696 r2776894  
    6363    -ms-transform: translate(-50%,-50%);
    6464}
     65
     66.save-zip-account{
     67    margin-left: 10px;
     68    display: inline;
     69}
  • zipmoney-payments-woocommerce/trunk/assets/js/zip_order_button.js

    r2464696 r2776894  
    8989            }
    9090        });
     91        $(".wc-block-components-checkout-place-order-button").on('click', function(e){
     92            var payment_method = $('input[name="radio-control-wc-payment-method-options"]:checked').val();
     93            //show the over lay
     94            if (payment_method == 'zipmoney') {
     95                $('div.zip-overlay').css('display', 'block');
     96            }
     97        });
    9198
    9299    });
  • zipmoney-payments-woocommerce/trunk/build/index.asset.php

    r2662714 r2776894  
    1 <?php return array('dependencies' => array('wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-i18n'), 'version' => 'd1f398c13142613a11516c4c7e32b5fc');
     1<?php return array('dependencies' => array('wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-i18n'), 'version' => 'eb121aaca370f966dd6eda9416301a5e');
  • zipmoney-payments-woocommerce/trunk/build/index.js

    r2662714 r2776894  
    1 !function(){"use strict";var e=window.wp.element,t=window.wp.i18n,n=window.wc.wcSettings,i=window.wc.wcBlocksRegistry;const a="zipmoney";var o;const l=(0,n.getSetting)("zipmoney_data",{}),c=(0,t.__)("Zip now, pay later","zippayment"),r=l.title?l.title:c,s=()=>l.description?l.description:"",p={name:a,label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:r})}),null),content:(0,e.createElement)(s,null),edit:(0,e.createElement)(s,null),canMakePayment:()=>!0,paymentMethodId:a,ariaLabel:r,supports:{features:null!==(o=null==l?void 0:l.supports)&&void 0!==o?o:[]}};(0,i.registerPaymentMethod)(p)}();
     1/******/ (function() { // webpackBootstrap
     2/******/    "use strict";
     3/******/    var __webpack_modules__ = ({
     4
     5/***/ "./client/blocks/constants.js":
     6/*!************************************!*\
     7  !*** ./client/blocks/constants.js ***!
     8  \************************************/
     9/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     10
     11__webpack_require__.r(__webpack_exports__);
     12/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     13/* harmony export */   "PAYMENT_METHOD_NAME": function() { return /* binding */ PAYMENT_METHOD_NAME; }
     14/* harmony export */ });
     15const PAYMENT_METHOD_NAME = 'zipmoney';
     16
     17/***/ }),
     18
     19/***/ "@woocommerce/blocks-registry":
     20/*!******************************************!*\
     21  !*** external ["wc","wcBlocksRegistry"] ***!
     22  \******************************************/
     23/***/ (function(module) {
     24
     25module.exports = window["wc"]["wcBlocksRegistry"];
     26
     27/***/ }),
     28
     29/***/ "@woocommerce/settings":
     30/*!************************************!*\
     31  !*** external ["wc","wcSettings"] ***!
     32  \************************************/
     33/***/ (function(module) {
     34
     35module.exports = window["wc"]["wcSettings"];
     36
     37/***/ }),
     38
     39/***/ "@wordpress/element":
     40/*!*********************************!*\
     41  !*** external ["wp","element"] ***!
     42  \*********************************/
     43/***/ (function(module) {
     44
     45module.exports = window["wp"]["element"];
     46
     47/***/ }),
     48
     49/***/ "@wordpress/i18n":
     50/*!******************************!*\
     51  !*** external ["wp","i18n"] ***!
     52  \******************************/
     53/***/ (function(module) {
     54
     55module.exports = window["wp"]["i18n"];
     56
     57/***/ })
     58
     59/******/    });
     60/************************************************************************/
     61/******/    // The module cache
     62/******/    var __webpack_module_cache__ = {};
     63/******/   
     64/******/    // The require function
     65/******/    function __webpack_require__(moduleId) {
     66/******/        // Check if module is in cache
     67/******/        var cachedModule = __webpack_module_cache__[moduleId];
     68/******/        if (cachedModule !== undefined) {
     69/******/            return cachedModule.exports;
     70/******/        }
     71/******/        // Create a new module (and put it into the cache)
     72/******/        var module = __webpack_module_cache__[moduleId] = {
     73/******/            // no module.id needed
     74/******/            // no module.loaded needed
     75/******/            exports: {}
     76/******/        };
     77/******/   
     78/******/        // Execute the module function
     79/******/        __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
     80/******/   
     81/******/        // Return the exports of the module
     82/******/        return module.exports;
     83/******/    }
     84/******/   
     85/************************************************************************/
     86/******/    /* webpack/runtime/compat get default export */
     87/******/    !function() {
     88/******/        // getDefaultExport function for compatibility with non-harmony modules
     89/******/        __webpack_require__.n = function(module) {
     90/******/            var getter = module && module.__esModule ?
     91/******/                function() { return module['default']; } :
     92/******/                function() { return module; };
     93/******/            __webpack_require__.d(getter, { a: getter });
     94/******/            return getter;
     95/******/        };
     96/******/    }();
     97/******/   
     98/******/    /* webpack/runtime/define property getters */
     99/******/    !function() {
     100/******/        // define getter functions for harmony exports
     101/******/        __webpack_require__.d = function(exports, definition) {
     102/******/            for(var key in definition) {
     103/******/                if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
     104/******/                    Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
     105/******/                }
     106/******/            }
     107/******/        };
     108/******/    }();
     109/******/   
     110/******/    /* webpack/runtime/hasOwnProperty shorthand */
     111/******/    !function() {
     112/******/        __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
     113/******/    }();
     114/******/   
     115/******/    /* webpack/runtime/make namespace object */
     116/******/    !function() {
     117/******/        // define __esModule on exports
     118/******/        __webpack_require__.r = function(exports) {
     119/******/            if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
     120/******/                Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
     121/******/            }
     122/******/            Object.defineProperty(exports, '__esModule', { value: true });
     123/******/        };
     124/******/    }();
     125/******/   
     126/************************************************************************/
     127var __webpack_exports__ = {};
     128// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
     129!function() {
     130/*!********************************!*\
     131  !*** ./client/blocks/index.js ***!
     132  \********************************/
     133__webpack_require__.r(__webpack_exports__);
     134/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
     135/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
     136/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
     137/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
     138/* harmony import */ var _woocommerce_settings__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @woocommerce/settings */ "@woocommerce/settings");
     139/* harmony import */ var _woocommerce_settings__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_woocommerce_settings__WEBPACK_IMPORTED_MODULE_2__);
     140/* harmony import */ var _woocommerce_blocks_registry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @woocommerce/blocks-registry */ "@woocommerce/blocks-registry");
     141/* harmony import */ var _woocommerce_blocks_registry__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_woocommerce_blocks_registry__WEBPACK_IMPORTED_MODULE_3__);
     142/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./constants */ "./client/blocks/constants.js");
     143
     144
     145/**
     146 * External dependencies
     147 */
     148
     149
     150
     151
     152/**
     153 * Internal dependencies
     154 */
     155
     156
     157const settings = (0,_woocommerce_settings__WEBPACK_IMPORTED_MODULE_2__.getSetting)('zipmoney_data', {});
     158console.log('zip settings:'.settings);
     159
     160const defaultLabel = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Zip now, pay later', 'zippayment');
     161
     162const label = settings.title ? settings.title : defaultLabel;
     163/**
     164 * @typedef {import('@woocommerce/type-defs/registered-payment-method-props').RegisteredPaymentMethodProps} RegisteredPaymentMethodProps
     165 */
     166
     167const saveZip = () => {
     168  return settings.savezip;
     169};
     170
     171const SaveZipCheckbox = () => {
     172  const [isChecked, setChecked] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)(saveZip);
     173
     174  const handleChange = event => {
     175    setChecked(!isChecked);
     176    let formData = new FormData();
     177    formData.append("savezipaccount", !isChecked);
     178    const requestOptions = {
     179      method: 'POST',
     180      body: formData
     181    };
     182    fetch(settings.sessionUrl, requestOptions).then(response => response.json());
     183  };
     184
     185  (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
     186    Zip.Widget.render();
     187  }, []);
     188
     189  if (settings.tokenisation === true) {
     190    return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, ' ', (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
     191      class: "zip-overlay",
     192      onclick: "this.style.display = 'none';"
     193    }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
     194      class: "zip-overlay-text"
     195    }, "Creating charge, please wait...")), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", {
     196      id: "zipmoney-learn-more",
     197      class: "zip-hover",
     198      "zm-widget": "popup",
     199      "zm-popup-asset": "checkoutdialog"
     200    }, "Learn More"), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", {
     201      type: "checkbox",
     202      rel: "saveZipAccount",
     203      value: "{isChecked}",
     204      id: "saveZipAccount",
     205      checked: isChecked,
     206      onChange: handleChange,
     207      disabled: false
     208    }), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("label", {
     209      className: "save-zip-account",
     210      htmlFor: "saveZipAccount"
     211    }, "Save Zip Account for future purchases"));
     212  }
     213
     214  return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, ' ', (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
     215    class: "zip-overlay",
     216    onclick: "this.style.display = 'none';"
     217  }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
     218    class: "zip-overlay-text"
     219  }, "Creating charge, please wait...")), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", {
     220    id: "zipmoney-learn-more",
     221    class: "zip-hover",
     222    "zm-widget": "popup",
     223    "zm-popup-asset": "checkoutdialog"
     224  }, "Learn More"));
     225};
     226/**
     227 * Label component
     228 *
     229 * @param {*} props Props from payment API.
     230 */
     231
     232
     233const Label = props => {
     234  const {
     235    PaymentMethodLabel
     236  } = props.components;
     237  return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(PaymentMethodLabel, {
     238    text: label
     239  });
     240};
     241/**
     242 * Zipmoney payment method config object.
     243 */
     244
     245
     246const zipMoneyPaymentMethod = {
     247  name: _constants__WEBPACK_IMPORTED_MODULE_4__.PAYMENT_METHOD_NAME,
     248  label: (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(Label, null),
     249  content: (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(SaveZipCheckbox, null),
     250  edit: (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(SaveZipCheckbox, null),
     251  canMakePayment: () => true,
     252  paymentMethodId: _constants__WEBPACK_IMPORTED_MODULE_4__.PAYMENT_METHOD_NAME,
     253  supports: {
     254    features: ['products']
     255  },
     256  ariaLabel: label
     257};
     258(0,_woocommerce_blocks_registry__WEBPACK_IMPORTED_MODULE_3__.registerPaymentMethod)(zipMoneyPaymentMethod);
     259}();
     260/******/ })()
     261;
     262//# sourceMappingURL=index.js.map
  • zipmoney-payments-woocommerce/trunk/build/index.js.map

    r2662714 r2776894  
    1 {"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;AAAO,MAAMA,mBAAmB,GAAG,UAA5B;;;;;;;;;;ACAP;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA,eAAe,4BAA4B;WAC3C,eAAe;WACf,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA,8CAA8C;;;;;WCA9C;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;;;;;;;;;;ACNA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;;AACA;AAEA,MAAMI,QAAQ,GAAGF,iEAAU,CAAE,eAAF,EAAmB,EAAnB,CAA3B;;AACA,MAAMG,YAAY,GAAGJ,mDAAE,CAAE,oBAAF,EAAwB,YAAxB,CAAvB;;AACA,MAAMK,KAAK,GAAGF,QAAQ,CAACG,KAAT,GAAiBH,QAAQ,CAACG,KAA1B,GAAkCF,YAAhD;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AACA,MAAMG,OAAO,GAAG,MAAM;AACrB,SAAOJ,QAAQ,CAACK,WAAT,GAAuBL,QAAQ,CAACK,WAAhC,GAA8C,EAArD;AACA,CAFD;AAIA;AACA;AACA;AACA;AACA;;;AACA,MAAMC,KAAK,GAAKC,KAAF,IAAa;AAC1B,QAAM;AAAEC,IAAAA;AAAF,MAAyBD,KAAK,CAACE,UAArC;AACA,SAAO,kEAAC,kBAAD;AAAoB,QAAI,EAAGP;AAA3B,IAAP;AACA,CAHD;AAKA;AACA;AACA;;;AACA,MAAMQ,qBAAqB,GAAG;AAC7BC,EAAAA,IAAI,EAAEf,2DADuB;AAE7BM,EAAAA,KAAK,EAAE,kEAAC,KAAD,OAFsB;AAG7BU,EAAAA,OAAO,EAAE,kEAAC,OAAD,OAHoB;AAI7BC,EAAAA,IAAI,EAAE,kEAAC,OAAD,OAJuB;AAK7BC,EAAAA,cAAc,EAAE,MAAM,IALO;AAM7BC,EAAAA,eAAe,EAAEnB,2DANY;AAO7BoB,EAAAA,SAAS,EAAEd,KAPkB;AAQ7Be,EAAAA,QAAQ,EAAE;AACTC,IAAAA,QAAQ,wBAAElB,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEiB,QAAZ,mEAAwB;AADvB;AARmB,CAA9B;AAaAlB,mFAAqB,CAAEW,qBAAF,CAArB,C","sources":["webpack://zipmoney-payments-woocommerce/./client/blocks/constants.js","webpack://zipmoney-payments-woocommerce/external window [\"wc\",\"wcBlocksRegistry\"]","webpack://zipmoney-payments-woocommerce/external window [\"wc\",\"wcSettings\"]","webpack://zipmoney-payments-woocommerce/external window [\"wp\",\"element\"]","webpack://zipmoney-payments-woocommerce/external window [\"wp\",\"i18n\"]","webpack://zipmoney-payments-woocommerce/webpack/bootstrap","webpack://zipmoney-payments-woocommerce/webpack/runtime/compat get default export","webpack://zipmoney-payments-woocommerce/webpack/runtime/define property getters","webpack://zipmoney-payments-woocommerce/webpack/runtime/hasOwnProperty shorthand","webpack://zipmoney-payments-woocommerce/webpack/runtime/make namespace object","webpack://zipmoney-payments-woocommerce/./client/blocks/index.js"],"sourcesContent":["export const PAYMENT_METHOD_NAME = 'zipmoney';\n","module.exports = window[\"wc\"][\"wcBlocksRegistry\"];","module.exports = window[\"wc\"][\"wcSettings\"];","module.exports = window[\"wp\"][\"element\"];","module.exports = window[\"wp\"][\"i18n\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = function(module) {\n\tvar getter = module && module.__esModule ?\n\t\tfunction() { return module['default']; } :\n\t\tfunction() { return module; };\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = function(exports, definition) {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }","// define __esModule on exports\n__webpack_require__.r = function(exports) {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { getSetting } from '@woocommerce/settings';\nimport { registerPaymentMethod } from '@woocommerce/blocks-registry';\n\n/**\n * Internal dependencies\n */\nimport { PAYMENT_METHOD_NAME } from './constants';\n\nconst settings = getSetting( 'zipmoney_data', {} );\nconst defaultLabel = __( 'Zip now, pay later', 'zippayment' );\nconst label = settings.title ? settings.title : defaultLabel;\n\n/**\n * @typedef {import('@woocommerce/type-defs/registered-payment-method-props').RegisteredPaymentMethodProps} RegisteredPaymentMethodProps\n */\n\n/**\n * Content component\n */\nconst Content = () => {\n\treturn settings.description ? settings.description : '';\n};\n\n/**\n * Label component\n *\n * @param {*} props Props from payment API.\n */\nconst Label = ( props ) => {\n\tconst { PaymentMethodLabel } = props.components;\n\treturn <PaymentMethodLabel text={ label } />;\n};\n\n/**\n * Zipmoney payment method config object.\n */\nconst zipMoneyPaymentMethod = {\n\tname: PAYMENT_METHOD_NAME,\n\tlabel: <Label />,\n\tcontent: <Content />,\n\tedit: <Content />,\n\tcanMakePayment: () => true,\n\tpaymentMethodId: PAYMENT_METHOD_NAME,\n\tariaLabel: label,\n\tsupports: {\n\t\tfeatures: settings?.supports ?? [],\n\t},\n};\n\nregisterPaymentMethod( zipMoneyPaymentMethod );\n"],"names":["PAYMENT_METHOD_NAME","__","getSetting","registerPaymentMethod","settings","defaultLabel","label","title","Content","description","Label","props","PaymentMethodLabel","components","zipMoneyPaymentMethod","name","content","edit","canMakePayment","paymentMethodId","ariaLabel","supports","features"],"sourceRoot":""}
     1{"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;AAAO,MAAMA,mBAAmB,GAAG,UAA5B;;;;;;;;;;ACAP;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA,eAAe,4BAA4B;WAC3C,eAAe;WACf,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA,8CAA8C;;;;;WCA9C;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;;;;;;;;ACNA;AACA;AACA;AACC;AACA;AACA;AACA;AAEA;AACD;AACA;;AACC;AAEA,MAAMM,QAAQ,GAAGJ,iEAAU,CAAE,eAAF,EAAmB,EAAnB,CAA3B;AACAK,OAAO,CAACC,GAAR,CAAY,gBAAgBF,QAA5B;;AACA,MAAMG,YAAY,GAAGR,mDAAE,CAAE,oBAAF,EAAwB,YAAxB,CAAvB;;AACA,MAAMS,KAAK,GAAGJ,QAAQ,CAACK,KAAT,GAAiBL,QAAQ,CAACK,KAA1B,GAAkCF,YAAhD;AAEA;AACD;AACA;;AAEC,MAAMG,OAAO,GAAG,MAAM;AACrB,SAAON,QAAQ,CAACO,OAAhB;AACA,CAFD;;AAIA,MAAMC,eAAe,GAAG,MAAM;AAC9B,QAAM,CAAEC,SAAF,EAAaC,UAAb,IAA4BX,4DAAQ,CAAEO,OAAF,CAA1C;;AACA,QAAMK,YAAY,GAAIC,KAAD,IAAW;AAC/BF,IAAAA,UAAU,CAAC,CAACD,SAAF,CAAV;AACA,QAAII,QAAQ,GAAG,IAAIC,QAAJ,EAAf;AACUD,IAAAA,QAAQ,CAACE,MAAT,CAAgB,gBAAhB,EAAkC,CAACN,SAAnC;AACV,UAAMO,cAAc,GAAG;AACtBC,MAAAA,MAAM,EAAE,MADc;AAEtBC,MAAAA,IAAI,EAAEL;AAFgB,KAAvB;AAIAM,IAAAA,KAAK,CAACnB,QAAQ,CAACoB,UAAV,EAAsBJ,cAAtB,CAAL,CACEK,IADF,CACOC,QAAQ,IAAIA,QAAQ,CAACC,IAAT,EADnB;AAEE,GAVH;;AAWEzB,EAAAA,6DAAS,CAAC,MAAM;AACjB0B,IAAAA,GAAG,CAACC,MAAJ,CAAWC,MAAX;AACE,GAFQ,EAEN,EAFM,CAAT;;AAGA,MAAG1B,QAAQ,CAAC2B,YAAT,KAA0B,IAA7B,EAAmC;AACrC,WACC,kIACG,GADH,EAEC;AAAK,WAAK,EAAC,aAAX;AAAyB,aAAO,EAAC;AAAjC,OACI;AAAK,WAAK,EAAC;AAAX,yCADJ,CAFD,EAKC;AAAI,QAAE,EAAC,qBAAP;AAA6B,WAAK,EAAC,WAAnC;AAAgD,mBAAU,OAA1D;AAAmE,wBAAe;AAAlF,oBALD,EAMC;AACC,UAAI,EAAC,UADN;AAEC,SAAG,EAAC,gBAFL;AAGC,WAAK,EAAC,aAHP;AAIC,QAAE,EAAC,gBAJJ;AAKC,aAAO,EAAGlB,SALX;AAMC,cAAQ,EAAGE,YANZ;AAOC,cAAQ,EAAG;AAPZ,MAND,EAgBC;AAAO,eAAS,EAAC,kBAAjB;AAAoC,aAAO,EAAG;AAA9C,OACO,uCADP,CAhBD,CADD;AAuBG;;AACF,SACA,kIACE,GADF,EAEA;AAAK,SAAK,EAAC,aAAX;AAAyB,WAAO,EAAC;AAAjC,KACI;AAAK,SAAK,EAAC;AAAX,uCADJ,CAFA,EAKA;AAAI,MAAE,EAAC,qBAAP;AAA6B,SAAK,EAAC,WAAnC;AAAgD,iBAAU,OAA1D;AAAmE,sBAAe;AAAlF,kBALA,CADA;AASD,CAlDA;AAoDA;AACD;AACA;AACA;AACA;;;AACC,MAAMiB,KAAK,GAAKC,KAAF,IAAa;AAC1B,QAAM;AAAEC,IAAAA;AAAF,MAAyBD,KAAK,CAACE,UAArC;AACA,SAAO,kEAAC,kBAAD;AAAoB,QAAI,EAAG3B;AAA3B,IAAP;AACA,CAHD;AAKA;AACD;AACA;;;AACC,MAAM4B,qBAAqB,GAAG;AAC7BC,EAAAA,IAAI,EAAEvC,2DADuB;AAE7BU,EAAAA,KAAK,EAAE,kEAAC,KAAD,OAFsB;AAG7B8B,EAAAA,OAAO,EAAE,kEAAC,eAAD,OAHoB;AAI7BC,EAAAA,IAAI,EAAE,kEAAC,eAAD,OAJuB;AAK7BC,EAAAA,cAAc,EAAE,MAAM,IALO;AAM7BC,EAAAA,eAAe,EAAE3C,2DANY;AAO7B4C,EAAAA,QAAQ,EAAE;AACTC,IAAAA,QAAQ,EAAE,CAAE,UAAF;AADD,GAPmB;AAU7BC,EAAAA,SAAS,EAAEpC;AAVkB,CAA9B;AAaAP,mFAAqB,CAAEmC,qBAAF,CAArB,C","sources":["webpack://zipmoney-payments-woocommerce/./client/blocks/constants.js","webpack://zipmoney-payments-woocommerce/external window [\"wc\",\"wcBlocksRegistry\"]","webpack://zipmoney-payments-woocommerce/external window [\"wc\",\"wcSettings\"]","webpack://zipmoney-payments-woocommerce/external window [\"wp\",\"element\"]","webpack://zipmoney-payments-woocommerce/external window [\"wp\",\"i18n\"]","webpack://zipmoney-payments-woocommerce/webpack/bootstrap","webpack://zipmoney-payments-woocommerce/webpack/runtime/compat get default export","webpack://zipmoney-payments-woocommerce/webpack/runtime/define property getters","webpack://zipmoney-payments-woocommerce/webpack/runtime/hasOwnProperty shorthand","webpack://zipmoney-payments-woocommerce/webpack/runtime/make namespace object","webpack://zipmoney-payments-woocommerce/./client/blocks/index.js"],"sourcesContent":["export const PAYMENT_METHOD_NAME = 'zipmoney';\r\n","module.exports = window[\"wc\"][\"wcBlocksRegistry\"];","module.exports = window[\"wc\"][\"wcSettings\"];","module.exports = window[\"wp\"][\"element\"];","module.exports = window[\"wp\"][\"i18n\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = function(module) {\n\tvar getter = module && module.__esModule ?\n\t\tfunction() { return module['default']; } :\n\t\tfunction() { return module; };\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = function(exports, definition) {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }","// define __esModule on exports\n__webpack_require__.r = function(exports) {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\r\n * External dependencies\r\n */\r\n import { __ } from '@wordpress/i18n';\r\n import { getSetting } from '@woocommerce/settings';\r\n import { registerPaymentMethod } from '@woocommerce/blocks-registry';\r\n import { useEffect, useState } from '@wordpress/element';\r\n \r\n /**\r\n  * Internal dependencies\r\n  */\r\n import { PAYMENT_METHOD_NAME } from './constants';\r\n \r\n const settings = getSetting( 'zipmoney_data', {} );\r\n console.log('zip settings:'.settings);\r\n const defaultLabel = __( 'Zip now, pay later', 'zippayment' );\r\n const label = settings.title ? settings.title : defaultLabel;\r\n \r\n /**\r\n  * @typedef {import('@woocommerce/type-defs/registered-payment-method-props').RegisteredPaymentMethodProps} RegisteredPaymentMethodProps\r\n  */\r\n \r\n const saveZip = () => {\r\n\t return settings.savezip;\r\n }\r\n \r\n const SaveZipCheckbox = () => {\r\n\tconst [ isChecked, setChecked ] = useState( saveZip );\r\n\tconst handleChange = (event) => {\r\n\t\tsetChecked(!isChecked);\r\n\t\tlet formData = new FormData();\r\n            formData.append(\"savezipaccount\", !isChecked);\r\n\t\tconst requestOptions = {\r\n\t\t\tmethod: 'POST',\r\n\t\t\tbody: formData\r\n\t\t};\r\n\t\tfetch(settings.sessionUrl, requestOptions)\r\n\t\t\t.then(response => response.json());\r\n\t  };\r\n\t  useEffect(() => {\r\n\t\tZip.Widget.render();\r\n\t  }, []);\r\n\t  if(settings.tokenisation === true) {\r\n\treturn (\r\n\t\t<>\r\n\t\t\t{ ' ' }\r\n\t\t\t<div class=\"zip-overlay\" onclick=\"this.style.display = 'none';\">\r\n    \t\t\t<div class=\"zip-overlay-text\">Creating charge, please wait...</div>\r\n\t\t\t</div>\r\n\t\t\t<a  id=\"zipmoney-learn-more\" class=\"zip-hover\"  zm-widget=\"popup\"  zm-popup-asset=\"checkoutdialog\">Learn More</a>\r\n\t\t\t<input\r\n\t\t\t\ttype=\"checkbox\"\r\n\t\t\t\trel=\"saveZipAccount\"\r\n\t\t\t\tvalue=\"{isChecked}\"\r\n\t\t\t\tid=\"saveZipAccount\"\r\n\t\t\t\tchecked={ isChecked }\r\n\t\t\t\tonChange={ handleChange }\r\n\t\t\t\tdisabled={ false }\r\n\r\n\t\t\t/>\r\n\t\t\t<label className='save-zip-account' htmlFor={ \"saveZipAccount\" }>\r\n\t\t\t\t\t\t\t\t{ \"Save Zip Account for future purchases\" }\r\n\t\t\t</label>\r\n\t\t</>\t\r\n\t\t\r\n\t);\r\n\t  }\r\n\t return (\r\n\t\t<>\r\n\t\t{ ' ' }\r\n\t\t<div class=\"zip-overlay\" onclick=\"this.style.display = 'none';\">\r\n    \t\t<div class=\"zip-overlay-text\">Creating charge, please wait...</div>\r\n\t\t</div>\r\n\t\t<a  id=\"zipmoney-learn-more\" class=\"zip-hover\"  zm-widget=\"popup\"  zm-popup-asset=\"checkoutdialog\">Learn More</a>\r\n\t\t</>\r\n\t ); \r\n};\r\n\r\n /**\r\n  * Label component\r\n  *\r\n  * @param {*} props Props from payment API.\r\n  */\r\n const Label = ( props ) => {\r\n\t const { PaymentMethodLabel } = props.components;\r\n\t return <PaymentMethodLabel text={ label } />;\r\n };\r\n \r\n /**\r\n  * Zipmoney payment method config object.\r\n  */\r\n const zipMoneyPaymentMethod = {\r\n\t name: PAYMENT_METHOD_NAME,\r\n\t label: <Label />,\r\n\t content: <SaveZipCheckbox />,\r\n\t edit: <SaveZipCheckbox />,\r\n\t canMakePayment: () => true,\r\n\t paymentMethodId: PAYMENT_METHOD_NAME,\r\n\t supports: {\r\n\t\t features: [ 'products' ],\r\n\t },\r\n\t ariaLabel: label,\r\n };\r\n \r\n registerPaymentMethod( zipMoneyPaymentMethod );\r\n "],"names":["PAYMENT_METHOD_NAME","__","getSetting","registerPaymentMethod","useEffect","useState","settings","console","log","defaultLabel","label","title","saveZip","savezip","SaveZipCheckbox","isChecked","setChecked","handleChange","event","formData","FormData","append","requestOptions","method","body","fetch","sessionUrl","then","response","json","Zip","Widget","render","tokenisation","Label","props","PaymentMethodLabel","components","zipMoneyPaymentMethod","name","content","edit","canMakePayment","paymentMethodId","supports","features","ariaLabel"],"sourceRoot":""}
  • zipmoney-payments-woocommerce/trunk/includes/api/class-wc-zipmoney-payment-gateway-api-charge.php

    r2560395 r2776894  
    1111use \zipMoney\ObjectSerializer;
    1212use \zipMoney\Api\CheckoutsApi;
     13use \zipMoney\Api\TokensApi;
     14use \zipMoney\Model\CreateTokenRequest;
    1315
    1416class WC_Zipmoney_Payment_Gateway_API_Request_Charge extends WC_Zipmoney_Payment_Gateway_API_Abstract
     
    242244     *                      )
    243245     */
    244     public function create_charge(WC_Session $WC_Session, $checkout_id, $api_key)
     246    public function create_charge(WC_Session $WC_Session, $checkout_id, $orderId, $api_key)
    245247    {
    246248        $response = array(
     
    248250            'message' => ''
    249251        );
    250        
     252
    251253
    252254        parent::set_api_key($api_key);
    253255
    254256        try {
    255            
    256             $order_id = get_option($checkout_id);
     257            if ($this->WC_Zipmoney_Payment_Gateway->doTokenisation()) {
     258                $order_id = $orderId;
     259            }
     260            if (!$order_id) {
     261                $order_id = get_option($checkout_id);
     262            }
    257263            //$region = $this->WC_Zipmoney_Payment_Gateway->get_option(WC_Zipmoney_Payment_Gateway_Config::CONFIG_SELECT_REGION);
    258             if($order_id == null) {
     264            if ($order_id == null) {
    259265
    260266                WC_Zipmoney_Payment_Gateway_Util::log(" get checkout API");
     
    263269            }
    264270
    265             $order = new WC_Order( $order_id );
    266             if($order->get_status() == "processing" || $order->get_status() == "zip-authorised"){
    267                     WC_Zipmoney_Payment_Gateway_Util::log(" calling charge 2nd time, order completed, redirect to thank you page");
    268                     wp_redirect($order->get_checkout_order_received_url());
    269                     exit;
    270             }
    271            
     271            $order = new WC_Order($order_id);
     272            if ($order->get_status() == "processing" || $order->get_status() == "zip-authorised") {
     273                WC_Zipmoney_Payment_Gateway_Util::log(" calling charge 2nd time, order completed, redirect to thank you page");
     274                wp_redirect($order->get_checkout_order_received_url());
     275                exit;
     276            }
     277
    272278            $body = $this->_prepare_charges_request($checkout_id, $order_id, $order);
    273             WC_Zipmoney_Payment_Gateway_Util::log(sprintf('Charge request sent for order (%s)', $order_id) , WC_Zipmoney_Payment_Gateway_Config::LOG_LEVEL_DEBUG);
    274            
    275          
     279            WC_Zipmoney_Payment_Gateway_Util::log(sprintf('Charge request sent for order (%s)', $order_id), WC_Zipmoney_Payment_Gateway_Config::LOG_LEVEL_DEBUG);
     280
     281
    276282            //write the charge object info to order meta
    277283
     
    326332                WC_Zipmoney_Payment_Gateway_Util::log('Order cancelled', WC_Zipmoney_Payment_Gateway_Config::LOG_LEVEL_DEBUG);
    327333            }
    328         } catch (ApiException $exception){
     334        } catch (ApiException $exception) {
    329335            $response = WC_Zipmoney_Payment_Gateway_Util::handle_create_charge_api_exception($exception);
    330336            WC_Zipmoney_Payment_Gateway_Util::log($response['message'], WC_Zipmoney_Payment_Gateway_Config::LOG_LEVEL_INFO);
    331             if(!empty($order)){
     337            if ($this->WC_Zipmoney_Payment_Gateway->doTokenisation() && $response['code'] == 403) {
     338                $current_user = wp_get_current_user();
     339                $uId = $current_user->ID;
     340                $this->_removeCustomerToken($uId);
     341            }
     342            if (!empty($order)) {
    332343                $order->add_order_note($response['message']);
    333344                $order->update_status('cancelled', 'order_note');
     
    336347            //delete the option
    337348            delete_option($checkout_id);
    338            
    339349        } catch (Exception $exception) {
    340             if(!empty($order)){
     350            if (!empty($order)) {
    341351                $order->add_order_note($exception->getCode() . $exception->getMessage());
    342352                $order->update_status('cancelled', 'order_note');
     
    345355            $response['message'] = $exception->getMessage();
    346356
    347             WC_Zipmoney_Payment_Gateway_Util::log("Create charge exception ". $exception->getCode() . $exception->getMessage(), WC_Zipmoney_Payment_Gateway_Config::LOG_LEVEL_INFO);
     357            WC_Zipmoney_Payment_Gateway_Util::log("Create charge exception " . $exception->getCode() . $exception->getMessage(), WC_Zipmoney_Payment_Gateway_Config::LOG_LEVEL_INFO);
    348358            wc_add_notice(__('Payment error:', 'zippayment') . $exception->getMessage(), 'error');
    349359            delete_option($checkout_id);
     
    367377        //get the charge order
    368378        $charge_order = $this->_create_charge_order($order_id, $order);
    369 
     379        $accountType = 'checkout_id';
     380        $accountValue = $checkout_id;
     381        if ($this->WC_Zipmoney_Payment_Gateway->doTokenisation()) {
     382            $accountType = 'account_token';
     383            $accountValue = $this->getCustomerToken($checkout_id);
     384        }
    370385        //get authority
    371386        $authority = new Authority(
    372387            array(
    373                 'type' => 'checkout_id',
    374                 'value' => $checkout_id
     388                'type' => $accountType,
     389                'value' => $accountValue
    375390            )
    376391        );
     
    400415    {
    401416        $is_pickup = false;
    402        
     417
    403418        //check order containing physical products, then create shipping address
    404419        // if order contains only virtual & downloadable products shipping address is not required.
    405         if (WC_Zipmoney_Order_Compatibility::has_shipping_address($order)){
    406                  $order_shipping = new OrderShipping(
    407                         array(
    408                         'address' => $this->_create_shipping_address($order),
    409                         'pickup' => $is_pickup
    410                     )
    411                 );
    412             }
    413             else{
    414                 $is_pickup = true;
    415                 $order_shipping = new OrderShipping(
    416                     array(
    417                         'pickup' => $is_pickup
    418                     )
    419                 );
    420             }
    421         $website_abbr = substr(sanitize_key( get_bloginfo( 'name' ) ), 0, 3);
     420        if (WC_Zipmoney_Order_Compatibility::has_shipping_address($order)) {
     421            $order_shipping = new OrderShipping(
     422                array(
     423                    'address' => $this->_create_shipping_address($order),
     424                    'pickup' => $is_pickup
     425                )
     426            );
     427        } else {
     428            $is_pickup = true;
     429            $order_shipping = new OrderShipping(
     430                array(
     431                    'pickup' => $is_pickup
     432                )
     433            );
     434        }
     435        $website_abbr = substr(sanitize_key(get_bloginfo('name')), 0, 3);
    422436
    423437        return new ChargeOrder(
    424438            array(
    425                 'reference' =>  strtoupper($website_abbr) ."-". $order_id ."-". strtotime("now"),
     439                'reference' =>  strtoupper($website_abbr) . "-" . $order_id . "-" . strtotime("now"),
    426440                'shipping' => $order_shipping,
    427441                'items' => $this->_get_order_items($order)
     
    429443        );
    430444    }
     445
     446    /**
     447     * save customer in the DB
     448     */
     449    private function _saveToken($customerId, $token)
     450    {
     451        global $wpdb;
     452        $table_name = $wpdb->prefix . 'zip_tokenisation';
     453        $encrypttedToken = WC_Zipmoney_Payment_Gateway_Util::wpcodetips_twoway_encrypt($token, 'e');
     454        $wpdb->insert($table_name, array('customer_id' => $customerId, 'token' => $encrypttedToken));
     455    }
     456
     457    /**
     458     * check the DB for customer token.
     459     * if not in the DB then get it by call token api
     460     */
     461    public function getCustomerToken($checkout_id)
     462    {
     463        global $wpdb;
     464        $current_user = wp_get_current_user();
     465        $uId = $current_user->ID;
     466        $tokenTable = $wpdb->prefix . 'zip_tokenisation';
     467        $result = $wpdb->get_results("SELECT * FROM $tokenTable WHERE `customer_id` = $uId");
     468        foreach ($result as $customerToken) {
     469            $dycrpttedToken = WC_Zipmoney_Payment_Gateway_Util::wpcodetips_twoway_encrypt($customerToken->token, 'd');
     470            return $dycrpttedToken;
     471        }
     472        //get authority
     473        $authority = new Authority(
     474            array(
     475                'type' => 'checkout_id',
     476                'value' => $checkout_id
     477            )
     478        );
     479        $tokenReq = new CreateTokenRequest();
     480        $tokenReq->setAuthority($authority);
     481        $tokenApi = new TokensApi();
     482        $token = $tokenApi->tokensCreate($tokenReq, WC_Zipmoney_Payment_Gateway_Util::get_uuid());
     483        $this->_saveToken($uId, $token->getValue());
     484        return $token->getValue();
     485    }
     486
     487    private function _removeCustomerToken($customerId)
     488    {
     489        global $wpdb;
     490        $table_name = $wpdb->prefix . 'zip_tokenisation';
     491        $wpdb->delete($table_name, array('customer_id' => $customerId));
     492    }
    431493}
  • zipmoney-payments-woocommerce/trunk/includes/api/class-wc-zipmoney-payment-gateway-api-checkout.php

    r2560395 r2776894  
    11<?php
     2
    23use \zipMoney\ApiException;
    34use \zipMoney\Model\CheckoutConfiguration;
     
    67use \zipMoney\Model\OrderShipping;
    78use \zipMoney\Model\Shopper;
     9use \zipMoney\Model\CheckoutFeatures;
     10use \zipMoney\Model\CreateCheckoutRequestFeaturesTokenisation as Tokenisation;
    811
    912class WC_Zipmoney_Payment_Gateway_API_Request_Checkout extends WC_Zipmoney_Payment_Gateway_API_Abstract
     
    9396            )
    9497        );
    95 
    96         return new CreateCheckoutRequest(
    97             array(
    98                 'shopper' => $shopper,
    99                 'order' => $checkout_order,
    100                 'metadata' => $this->_getMetadata(),
    101                 'config' => $checkout_configuration,
    102             )
    103         );
     98        $checkoutReq = new CreateCheckoutRequest();
     99        $checkoutReq->setType("standard")
     100            ->setShopper($shopper)
     101            ->setOrder($checkout_order)
     102            ->setMetadata($this->_getMetadata())
     103            ->setConfig($checkout_configuration);
     104        if ($this->WC_Zipmoney_Payment_Gateway->doTokenisation()) {
     105            $checkoutReq->setFeatures($this->getTokenisationFeature());
     106        }
     107        return $checkoutReq;
     108    }
     109
     110    /**
     111     * get tokenisation feature when tokenisation is enable
     112     */
     113    public function getTokenisationFeature()
     114    {
     115        $feature = new CheckoutFeatures;
     116        $tokenisation = new Tokenisation;
     117        $tokenisation->setRequired(true);
     118        $feature->setTokenisation($tokenisation);
     119
     120        return $feature;
    104121    }
    105122
  • zipmoney-payments-woocommerce/trunk/includes/class-wc-zipmoney-payment-gateway-blocks-support.php

    r2662714 r2776894  
    4848     * @return array
    4949     */
    50     public function get_payment_method_data() {
    51         return [
    52             'title'       => $this->get_setting( 'title' ),
    53             'description' => $this->get_setting( 'description' ),
    54             'supports'    => $this->get_supported_features(),
     50    public function get_payment_method_data()
     51    {
     52        $url = home_url() . "/?p=zipmoneypayment&route=updatesession";
     53        $payment_method_data = [
     54            'title'          => $this->WC_Zipmoney_Payment_Gateway->title,
     55            'description'    => $this->WC_Zipmoney_Payment_Gateway->description,
     56            'supports'       => $this->get_supported_features(),
     57            'tokenisation' => $this->WC_Zipmoney_Payment_Gateway->showSaveAccountInCheckout(),
     58            'savezip' => $this->WC_Zipmoney_Payment_Gateway->customerHasToken(),
     59            'sessionUrl' => $url,
    5560        ];
     61
     62        return $payment_method_data;
    5663    }
    5764
  • zipmoney-payments-woocommerce/trunk/includes/class-wc-zipmoney-payment-gateway-config.php

    r2633893 r2776894  
    5353    const CONFIG_SELECT_REGION = 'select_region';
    5454    const CONFIG_CHECK_CREDENTIALS_BTN = 'check_credentials';
     55    const CONFIG_ENABLE_TOKENISATION = 'enable_tokenisation';
    5556    /*const PRODUCT_ZIP_MONEY = 'zipMoney';
    5657    const PRODUCT_ZIP_PAY = 'zipPay';*/
     
    123124                $( '.woocommerce_banner_option' ).closest( 'tr' ).hide();
    124125            }
     126            if($('#woocommerce_zipmoney_select_region :selected').val() === 'au'){
     127                $( '.woocommerce_banner_enable' ).closest( 'tr' ).show();
     128                $('.woocommerce_tokenisation_enable_option').closest( 'tr' ).show();
     129                $('.woocommerce_iframe_enable_option').closest( 'tr' ).show();
     130                if($('.woocommerce_banner_enable').prop('checked') == true){
     131                    $( '.woocommerce_banner_option' ).closest( 'tr' ).show();
     132                }else{
     133                    $( '.woocommerce_banner_option' ).closest( 'tr' ).hide();
     134                }
     135            }else{
     136                $( '.woocommerce_banner_enable' ).closest( 'tr' ).hide();
     137                $('.woocommerce_tokenisation_enable_option').closest( 'tr' ).hide();
     138                $('.woocommerce_iframe_enable_option').closest( 'tr' ).hide();
     139                $( '.woocommerce_banner_option' ).closest( 'tr' ).hide();
     140            }
    125141           
    126142
     
    142158            });
    143159
     160            $('#woocommerce_zipmoney_select_region').on('change',function(){
     161                //Getting Value
     162                var selValue = $('#woocommerce_zipmoney_select_region :selected').val();
     163                if(selValue === 'au'){
     164                    $( '.woocommerce_banner_enable' ).closest( 'tr' ).show();
     165                    $('.woocommerce_tokenisation_enable_option').closest( 'tr' ).show();
     166                    $('.woocommerce_iframe_enable_option').closest( 'tr' ).show();
     167                    if($('.woocommerce_banner_enable').prop('checked') == true){
     168                        $( '.woocommerce_banner_option' ).closest( 'tr' ).show();
     169                    }else{
     170                        $( '.woocommerce_banner_option' ).closest( 'tr' ).hide();
     171                    }
     172                }else{
     173                    $( '.woocommerce_banner_enable' ).closest( 'tr' ).hide();
     174                    $('.woocommerce_tokenisation_enable_option').closest( 'tr' ).hide();
     175                    $('.woocommerce_iframe_enable_option').closest( 'tr' ).hide();
     176                    $( '.woocommerce_banner_option' ).closest( 'tr' ).hide();
     177                }
     178            });
     179
    144180            $( '.woocommerce_banner_enable' ).change( function( event ) {
    145181                var checked = $( event.target ).is( ':checked' );
     
    210246                'class' => 'check_private_key',
    211247                'desc_tip'          => true,
     248            ),
     249            self::CONFIG_SELECT_REGION => array(
     250                'title'     => __('Widget Region', 'zippayment'),
     251                'type' => 'select',
     252                'desc_tip' => __('Select Region to show proper zip widget in product, cart and checkout page', 'zippayment'),
     253                'default' => self::REGION_AU,
     254                'options' => array(
     255                    self::REGION_AU => 'Australia',
     256                    self::REGION_CA => 'Canada',
     257                    self::REGION_MX => 'Mexico',
     258                    self::REGION_NZ => 'New Zealand',
     259                    self::REGION_SG => 'Singapore',
     260                    self::REGION_ZA => 'South Africa',
     261                    self::REGION_AE => 'United Arab Emirates',
     262                    self::REGION_GB => 'United Kingdom',
     263                    self::REGION_US => 'United States',
     264                )
     265            ),
     266            self::CONFIG_ENABLE_TOKENISATION => array(
     267                'title' => __('Tokenisation', 'zippayment'),
     268                'label' => __('Enable Tokenisation', 'zippayment'),
     269                'class' => 'woocommerce_tokenisation_enable_option',
     270                'type' => 'checkbox',
     271                'description' => __('Tokenisation allows a seamless one-click checkout experience for returning Zip customers, removing the need to redirect and complete a Zip login after their first purchase. (Australia only)', 'zippayment'),
     272                'default' => 'no'
    212273            ),
    213274            self::CONFIG_CHARGE_CAPTURE => array(
     
    239300                'title' => __('In-context checkout', 'zippayment'),
    240301                'label' => __('Enable in-context checkout flow', 'zippayment'),
     302                'class' => 'woocommerce_iframe_enable_option',
    241303                'type' => 'checkbox',
    242304                'desc_tip' => __('Enable to offer your customers an iframe checkout experience without being redirected away from your website. But this feature only work for AU region. Other region customer will redirect to zip for payment.', 'zippayment'),
    243                 'description' => __('Iframe zip checkout only work for AU region. Other region customer will redirect to zip for payment. ', 'zippayment'),
     305                'description' => __('Iframe Zip checkout will only work for merchants based in Australia”', 'zippayment'),
    244306                'default' => 'no'
    245307            ),
     
    255317                'desc_tip' => __('Set the maximum shopping cart value that Zip will be available for use.', 'zippayment'),
    256318                'default' => 1500
    257             ),
    258             self::CONFIG_SELECT_REGION => array(
    259                 'title'     => __('Widget Region', 'zippayment'),
    260                 'type' => 'select',
    261                 'desc_tip' => __('Select Region to show proper zip widget in product, cart and checkout page', 'zippayment'),
    262                 'default' => self::REGION_AU,
    263                 'options' => array(
    264                     self::REGION_AU => 'Australia',
    265                     self::REGION_CA => 'Canada',
    266                     self::REGION_MX => 'Mexico',
    267                     self::REGION_NZ => 'New Zealand',
    268                     self::REGION_SG => 'Singapore',
    269                     self::REGION_ZA => 'South Africa',
    270                     self::REGION_AE => 'United Arab Emirates',
    271                     self::REGION_GB => 'United Kingdom',
    272                     self::REGION_US => 'United States',         
    273                 )
    274319            ),
    275320            self::CONFIG_DISPLAY_WIDGET_MODE => array(
     
    287332                'label' => __('Display on product page', 'zippayment'),
    288333                'type' => 'checkbox',
    289                 'desc_tip' => __('Enable to display the Zip widget below the add to cart button on the product page.', 'zippayment'),
     334                'desc_tip' => __('The product widget will break down the price of the item and display a minimum weekly repayment or divide the price by 4 and show the customer an equal price breakdown', 'zippayment'),
    290335                'default' => 'yes'
    291336            ),
     
    293338                'label' => __('Display on cart page', 'zippayment'),
    294339                'type' => 'checkbox',
    295                 'desc_tip' => __('Enable to display the Zip widget below the checkout button on the cart page.', 'zippayment'),
     340                'desc_tip' => __('The cart widget will break down the price of the item and display a minimum weekly repayment or divide the price by 4 and show the customer an equal price breakdown', 'zippayment'),
    296341                'default' => 'yes'
    297342            ),
     
    299344                'title' => __('Marketing taglines', 'zippayment'),
    300345                'label' => __('Display on product page', 'zippayment'),
    301                 'desc_tip' => __('Enable to display the Zip tagline widget below the price on the product page.', 'zippayment'),
     346                'desc_tip' => __('The tagline does not show any price breakdown or minimum repayments. A tagline will show a static message of "Own it now, pay later."', 'zippayment'),
    302347                'type' => 'checkbox',
    303348                'default' => 'no'
     
    305350            self::CONFIG_DISPLAY_TAGLINE_CART => array(
    306351                'label' => __('Display on cart page', 'zippayment'),
    307                 'desc_tip' => __('Enable to display the Zip tagline widget below the total price on the cart page.', 'zippayment'),
     352                'desc_tip' => __('The tagline does not show any price breakdown or minimum repayments. A tagline will show a static message of "Own it now, pay later".', 'zippayment'),
    308353                'type' => 'checkbox',
    309354                'default' => 'no'
  • zipmoney-payments-woocommerce/trunk/includes/class-wc-zipmoney-payment-gateway-util.php

    r2476029 r2776894  
    554554        WC()->session->set('zip_shipping_details', $zip_shipping_details);
    555555    }
     556
     557    // encrypt and decrypt token
     558    public static function wpcodetips_twoway_encrypt($stringToHandle = "", $encryptDecrypt = 'e')
     559    {
     560        // Set secret keys
     561        require_once plugin_dir_path(__FILE__) . '/class-wc-zipmoney-payment-gateway.php';
     562        $WC_Zipmoney_Payment_Gateway = new WC_Zipmoney_Payment_Gateway();
     563        $WC_Zipmoney_Payment_Gateway_Config = new WC_Zipmoney_Payment_Gateway_Config($WC_Zipmoney_Payment_Gateway);
     564        $secret_key = $WC_Zipmoney_Payment_Gateway_Config->get_merchant_public_key(); // Change this!
     565        $secret_iv = $WC_Zipmoney_Payment_Gateway_Config->get_merchant_private_key(); // Change this!
     566        $key = hash('sha256', $secret_key);
     567        $iv = substr(hash('sha256', $secret_iv), 0, 16);
     568        // Check whether encryption or decryption
     569        if ($encryptDecrypt == 'e') {
     570            // We are encrypting
     571            $output = base64_encode(openssl_encrypt($stringToHandle, "AES-256-CBC", $key, 0, $iv));
     572        } else if ($encryptDecrypt == 'd') {
     573            // We are decrypting
     574            $output = openssl_decrypt(base64_decode($stringToHandle), "AES-256-CBC", $key, 0, $iv);
     575        }
     576        return $output;
     577    }
    556578}
  • zipmoney-payments-woocommerce/trunk/includes/class-wc-zipmoney-payment-gateway-widget.php

    r2685692 r2776894  
    1111    public function init_hooks()
    1212    {
    13         add_action('woocommerce_before_main_content', array($this, 'render_root_el'));
    14         add_action('woocommerce_before_single_product_summary', array($this, 'render_root_el'));
    15         add_action('woocommerce_before_cart', array($this, 'render_root_el'));
    16         add_action('woocommerce_before_checkout_form', array($this, 'render_root_el'));
     13        add_action('wp_footer', array($this, 'render_root_el'));
    1714
    1815        add_filter('woocommerce_gateway_description', array($this, 'updateMethodDescription'), 10, 2);
     
    2118
    2219        //inject the order button
    23         if($WC_Zipmoney_Payment_Gateway_Config->is_it_iframe_flow()){
     20        if ($WC_Zipmoney_Payment_Gateway_Config->is_it_iframe_flow()) {
    2421            add_filter('woocommerce_order_button_html', array($this, 'order_button'), 10, 2);
    2522        }
    26        
     23
    2724        //use this hook to convert customer address
    2825        add_action('woocommerce_checkout_update_order_review', array('WC_Zipmoney_Payment_Gateway_Util', 'update_customer_details'));
     
    411408    public function updateMethodDescription($description, $id)
    412409    {
    413         if ($id != $this->WC_Zipmoney_Payment_Gateway->id){
     410        if ($id != $this->WC_Zipmoney_Payment_Gateway->id) {
    414411            return $description;
    415412        }
    416 
    417         return '<span zm-widget=\'inline\' zm-asset=\'checkoutdescription\'></span> <a  id="zipmoney-learn-more" class="zip-hover"  zm-widget="popup"  zm-popup-asset="checkoutdialog">Learn More</a>
    418     <script>if(window.$zmJs!==undefined) window.$zmJs._collectWidgetsEl(window.$zmJs);</script>';
     413        $description = '<span zm-widget=\'inline\' zm-asset=\'checkoutdescription\'></span> <a  id="zipmoney-learn-more" class="zip-hover"  zm-widget="popup"  zm-popup-asset="checkoutdialog">Learn More</a>';
     414        // show Save Zip account option in checkout when tokenisation is enable and customer logged in
     415        if ($this->WC_Zipmoney_Payment_Gateway->showSaveAccountInCheckout()) {
     416            $checked = ($this->WC_Zipmoney_Payment_Gateway->customerHasToken()) ? 'checked' : '';
     417            session_status() === PHP_SESSION_ACTIVE ?: session_start();
     418            $_SESSION["saveZipAccount"] = $this->WC_Zipmoney_Payment_Gateway->customerHasToken();
     419            $description .= '<label><input type="checkbox" id="saveZipAccount" ' . $checked . ' onchange="Check(this)" /><span>Save Zip Account for future purchases</span></label>';
     420        }
     421        $description .= '<script>if(window.$zmJs!==undefined) window.$zmJs._collectWidgetsEl(window.$zmJs);</script>';
     422        return $description;
    419423    }
    420424
  • zipmoney-payments-woocommerce/trunk/includes/class-wc-zipmoney-payment-gateway.php

    r2685692 r2776894  
    1212{
    1313    const ADMIN_CSS_VERSION = '1.0';
    14     const FRONT_CSS_VERSION = '1.1';
     14    const FRONT_CSS_VERSION = '1.2';
    1515
    1616    //essential settings
     
    2424    public $description = 'Own the way you pay';
    2525
    26     public $version = '2.3.13';
     26    public $version = '2.3.14';
    2727
    2828    public $supports = array('products', 'refunds');
     
    7878        add_filter('woocommerce_order_get_payment_method_title', array($this, 'zip_order_payment_title'), 10, 2);
    7979        add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
    80     }
    81 
     80        add_action('wp_footer', array($this, 'update_zip_session'));
     81    }
    8282    // when zip private key is not valid then show this error in admin
    8383    public function invalid_key_error_notice($display = false)
     
    317317
    318318    /**
     319     * get tokenisation option status from zip admin setting
     320     */
     321    public function get_tokenisation_status()
     322    {
     323        $this->WC_Zipmoney_Payment_Gateway_Config = new WC_Zipmoney_Payment_Gateway_Config($this);
     324
     325        return $this->WC_Zipmoney_Payment_Gateway_Config->is_bool_config_by_key(WC_Zipmoney_Payment_Gateway_Config::CONFIG_ENABLE_TOKENISATION);
     326    }
     327
     328    /**
    319329     * Check the environment meet the minimum requirement
    320330     */
     
    377387                wp_send_json($result);
    378388                break;
     389            case 'updatesession':
     390                // this route use for setting session for save zip account option wheither it is checked or unchecked
     391                $saveZipaccount = sanitize_text_field($_POST['savezipaccount']);
     392                session_status() === PHP_SESSION_ACTIVE ?: session_start();
     393                $_SESSION["saveZipAccount"] = $saveZipaccount;
     394                $result =  $result = array(
     395                    'code' => 200,
     396                    'message' => 'success',
     397                );
     398                wp_send_json($result);
    379399        }
    380400    }
     
    396416            set_post_type($order_id, 'shop_quote');
    397417
    398             $response = array();
    399 
    400             $response = $checkout_controller->create_checkout($_POST, $order_id);
     418            $checkout = array();
     419
     420            $checkout = $checkout_controller->create_checkout($_POST, $order_id);
    401421        } catch (ApiException $exception) {
    402422            WC_Zipmoney_Payment_Gateway_Util::log($exception->getCode() . $exception->getMessage());
     
    411431            );
    412432        }
    413         if (isset($response['redirect_uri'])) {
    414             return array(
    415                 'result' => $response['result'],
    416                 'checkout_id' => $response['checkout_id'],
    417                 'redirect' => $response['redirect_uri']
     433        if (isset($checkout['redirect_uri'])) {
     434
     435            $response = array(
     436                'result' => $checkout['result'],
     437                'checkout_id' => $checkout['checkout_id'],
     438                'redirect' => $checkout['redirect_uri']
    418439            );
    419         }
    420         wc_add_notice(__('Payment error: ', 'zippayment') . $response['message'], 'error');
     440
     441            if (isset($checkout['token'])) {
     442                $token = $checkout['token'];
     443                $response['token'] = $token;
     444            }
     445            return $response;
     446        }
     447        wc_add_notice(__('Payment error: ', 'zippayment') . $checkout['message'], 'error');
    421448    }
    422449
     
    515542        }
    516543    }
     544    /**
     545     *  check tokenisation is enable, user logged in and currency is AUD
     546     */
     547    public function showSaveAccountInCheckout()
     548    {
     549        $currency = get_option('woocommerce_currency');
     550        if (is_user_logged_in() && $this->get_tokenisation_status() && $currency == CurrencyUtil::CURRENCY_AUD) {
     551            return true;
     552        }
     553        return false;
     554    }
     555
     556    /**
     557     * check tokenisation is enable, user logged in and currency is AUD
     558     * as well as checking saveZipAccount is checked or not
     559     */
     560    public function doTokenisation()
     561    {
     562        session_status() === PHP_SESSION_ACTIVE ?: session_start();
     563        if (isset($_SESSION['saveZipAccount']) && filter_var($_SESSION['saveZipAccount'], FILTER_VALIDATE_BOOLEAN) && $this->showSaveAccountInCheckout()) {
     564            return true;
     565        }
     566        return false;
     567    }
     568
     569    /**
     570     * check customer has token
     571     */
     572    public function customerHasToken()
     573    {
     574        global $wpdb;
     575        $current_user = wp_get_current_user();
     576        $uid = $current_user->ID;
     577        $tokenTable = $wpdb->prefix . 'zip_tokenisation';
     578        $result = $wpdb->get_results("SELECT * FROM $tokenTable WHERE `customer_id` = $uid");
     579        foreach ($result as $customerToken) {
     580            return $customerToken->token;
     581        }
     582        return false;
     583    }
     584    /**
     585     * update session when customer check or uncheck Save Zip account in checkout page
     586     */
     587    public function update_zip_session()
     588    {
     589        $url = home_url();
     590?>
     591
     592        <script type="text/javascript">
     593            function Check(value) {
     594                let formData = new FormData();
     595                var url = '<?php echo $url . "/?p=zipmoneypayment&route=updatesession"; ?>';
     596                formData.append("savezipaccount", value.checked);
     597                const requestOptions = {
     598                    method: "POST",
     599                    body: formData
     600                };
     601                fetch(url, requestOptions)
     602                    .then(response => response.json());
     603            };
     604        </script>
     605<?php
     606    }
    517607}
  • zipmoney-payments-woocommerce/trunk/includes/controller/class-wc-zipmoney-payment-charge-controller.php

    r2560395 r2776894  
    4444
    4545                    //Once the result is approved, change the post_type from "shop_quote" to "shop_order"
    46                     //$order_id = WC()->session->get('_post_id');
    47                     $order_id = get_option($checkoutId);
     46                    if ($this->WC_Zipmoney_Payment_Gateway->doTokenisation()) {
     47                        $order_id = wc_get_order_id_by_order_key(wc_clean(wp_unslash($options['key'])));
     48                    }
     49
     50                    if (!$order_id) {
     51                        $order_id = get_option($checkoutId);
     52                    }
    4853                    // AU SMI adding prefix but lightbox redirect will not have prefix
    4954                    if (!$order_id) {
    5055                        $order_id = get_option('au-' . $checkoutId);
    51                         if($order_id){
    52                             $checkoutId = 'au-'.$checkoutId;
     56                        if ($order_id) {
     57                            $checkoutId = 'au-' . $checkoutId;
    5358                        }
    5459                    }
     
    6368                            WC()->session,
    6469                            $checkoutId,
     70                            $order_id,
    6571                            $this->WC_Zipmoney_Payment_Gateway_Config->get_merchant_private_key()
    6672                        );
     
    7278                            //wc_add_notice('Your zip payment successful, thank you.', 'success');
    7379                        } else {
     80                            $result['redirect_url'] = $this->wc_get_checkout_url();
    7481                            $result['content'] = $response['message'];
    7582                            $result['title'] = 'Error';
    76                             wc_add_notice(__("An error occurred while processing payment","zippayment"), 'error');
     83                            wc_add_notice(__("An error occurred while processing payment", "zippayment"), 'error');
    7784                        }
    7885                    } else {
     
    8087                        $result['content'] = 'Could not find the order, please try again later.';
    8188                        $result['title'] = 'Error';
    82                         wc_add_notice(__("Could not find the order, please try again later.","zippament"), 'error');
     89                        wc_add_notice(__("Could not find the order, please try again later.", "zippament"), 'error');
    8390                    }
    8491                    break;
     
    8693                    $result['title'] = 'The payment is in referred state';
    8794                    $result['content'] = 'Your application is currently under review by zipMoney and will be processed very shortly. You can contact the customer care at [email protected] for any enquiries.';
    88                     wc_add_notice(__('Payment pending, your application is currently under review and will be processed shortly.',"zippayment"), 'success');
     95                    wc_add_notice(__('Payment pending, your application is currently under review and will be processed shortly.', "zippayment"), 'success');
    8996                    WC()->cart->empty_cart();
    9097                    break;
     
    93100                    $result['content'] = 'Your application has been declined by zipMoney. Please contact zipMoney for further information.';
    94101                    $result['redirect_url'] = $this->wc_get_checkout_url();
    95                     wc_add_notice(__('Your application has been declined. Please contact Zip Co for further information.',"zippayment"), 'error');
     102                    wc_add_notice(__('Your application has been declined. Please contact Zip Co for further information.', "zippayment"), 'error');
    96103                    //remove the wp_option
    97104                    delete_option($checkoutId);
     
    100107                    $result['title'] = 'The checkout has been cancelled';
    101108                    $result['content'] = 'The checkout has been cancelled.';
    102                     wc_add_notice(__('The payment has been cancelled.',"zippayment"), 'error');
     109                    wc_add_notice(__('The payment has been cancelled.', "zippayment"), 'error');
    103110                    $result['redirect_url'] = $this->wc_get_checkout_url();
    104111                    //remove the wp_option
  • zipmoney-payments-woocommerce/trunk/includes/controller/class-wc-zipmoney-payment-checkout-controller.php

    r2560395 r2776894  
    2424            new CheckoutsApi()
    2525        );
     26        $redirect_url = WC_Zipmoney_Payment_Gateway_Util::get_complete_endpoint_url();
     27        $user = wp_get_current_user();
     28        if ($this->WC_Zipmoney_Payment_Gateway->doTokenisation()) {
     29            if ($this->WC_Zipmoney_Payment_Gateway->customerHasToken()) {
     30                WC_Zipmoney_Payment_Gateway_Util::log('customerHasToken');
     31                $order       = wc_get_order($order_id);
     32                $order_key   = $order->get_order_key();
     33                $redirect_url .= "&result=approved&token=true&checkoutId=checkoutId&key=" . $order_key;
     34                return array(
     35                    'redirect_uri' => $redirect_url,
     36                    'message' => 'Redirecting to charge.',
     37                    'result' => 'success',
     38                    'checkout_id' => 'checkoutId',
     39                    'token' => true,
     40                );
     41            }
     42        } else {
     43            if ($this->WC_Zipmoney_Payment_Gateway->showSaveAccountInCheckout()) {
     44                $this->_removeCustomerToken($user->ID);
     45            }
     46        }
    2647
    2748        $checkout_response = $WC_Zipmoney_Payment_Gateway_API_Request_Checkout->create_checkout(
    2849            WC()->session,
    29             WC_Zipmoney_Payment_Gateway_Util::get_complete_endpoint_url(),
     50            $redirect_url,
    3051            $this->WC_Zipmoney_Payment_Gateway_Config->get_merchant_private_key(),
    3152            $order_id
     
    5172        }
    5273        return array(
    53             'message' => __("An error occurred while getting the redirect url from Zip.","zippayment"),
     74            'message' => __("An error occurred while getting the redirect url from Zip.", "zippayment"),
    5475            'result' => 'failure'
    5576        );
    5677    }
     78
     79    private function _removeCustomerToken($customerId)
     80    {
     81        global $wpdb;
     82        $table_name = $wpdb->prefix . 'zip_tokenisation';
     83        $wpdb->delete($table_name, array('customer_id' => $customerId));
     84    }
    5785}
  • zipmoney-payments-woocommerce/trunk/includes/view/frontend/order_button.php

    r2464696 r2776894  
    55<script src="https://static.zipmoney.com.au/checkout/checkout-v1.js"></script>
    66<script type="text/javascript">
    7 (function($){
    8    $(document).ready(function(){
    9     //your code
     7    (function($) {
     8        $(document).ready(function() {
     9            //your code
    1010
    11         $('#place_order').on('click', function(e){
    12             var zipMoneyErrorDiv = $('#zipMoneyErrorDiv');
    13             var zipMoneyInfoDiv = $('#zipMoneyInfoDiv');
    14             zipMoneyErrorDiv.hide();
    15             zipMoneyInfoDiv.hide();
     11            $('#place_order').on('click', function(e) {
     12                var zipMoneyErrorDiv = $('#zipMoneyErrorDiv');
     13                var zipMoneyInfoDiv = $('#zipMoneyInfoDiv');
     14                zipMoneyErrorDiv.hide();
     15                zipMoneyInfoDiv.hide();
    1616
    17             var payment_method = $('form[name="checkout"] input[name="payment_method"]:checked').val();
     17                var payment_method = $('form[name="checkout"] input[name="payment_method"]:checked').val();
    1818
    19             var checkoutId = null; //log the checkoutId. if the user close the iframe, it will make an ajax call to remove the record in
     19                var checkoutId = null; //log the checkoutId. if the user close the iframe, it will make an ajax call to remove the record in
    2020
    21             if (payment_method == 'zipmoney') {
     21                if (payment_method == 'zipmoney') {
    2222
    23                 Zip.Checkout.init({
    24                     redirect: <?php echo $is_iframe_checkout ? 0 : 1?>,
    25                     checkoutUri: '<?php echo WC_Zipmoney_Payment_Gateway_Util::get_checkout_endpoint_url();?>',
    26                     redirectUri: '<?php echo WC_Zipmoney_Payment_Gateway_Util::get_complete_endpoint_url()?>',
    27                     onCheckout: function(resolve, reject, args) {
    28                         var errorDiv = $('#zipMoneyErrorDiv');
    29                         errorDiv.hide();
     23                    Zip.Checkout.init({
     24                        redirect: <?php echo $is_iframe_checkout ? 0 : 1 ?>,
     25                        checkoutUri: '<?php echo WC_Zipmoney_Payment_Gateway_Util::get_checkout_endpoint_url(); ?>',
     26                        redirectUri: '<?php echo WC_Zipmoney_Payment_Gateway_Util::get_complete_endpoint_url() ?>',
     27                        onCheckout: function(resolve, reject, args) {
     28                            var errorDiv = $('#zipMoneyErrorDiv');
     29                            errorDiv.hide();
    3030
    31                         $.ajax({
    32                             type: 'POST',
    33                             url: '<?php echo WC_Zipmoney_Payment_Gateway_Util::get_wc_checkout_url()?>',
    34                             data: $('form.checkout').serialize(),
    35                             dataType: 'json',
    36                             success: function (result) {
    37                                 console.log('successfully triggered');
    38                                // console.log("test ". result);
     31                            $.ajax({
     32                                type: 'POST',
     33                                url: '<?php echo WC_Zipmoney_Payment_Gateway_Util::get_wc_checkout_url() ?>',
     34                                data: $('form.checkout').serialize(),
     35                                dataType: 'json',
     36                                success: function(result) {
     37                                    console.log('successfully triggered');
     38                                    // console.log("test ". result);
    3939
    40                                 if(result.checkout_id){
    41                                     checkoutId = result.checkout_id;
    42                                 }
    43 
    44                                 if(result.redirect){
    45                                     //if the checkout is successful
    46                                     console.log('resolved');
    47                                     resolve({
    48                                         data: {redirect_uri: result.redirect}
    49                                     });
    50                                 } else {
    51                                     //console.log('reject');
    52                                     errorDiv.html(result.messages);
    53                                     errorDiv.show();
    54                                     //scroll up to show the error
    55                                     $('html, body').animate({
    56                                         scrollTop: ( $('form.checkout').offset().top - 200)
    57                                     }, 1000);
     40                                    if (result.checkout_id) {
     41                                        checkoutId = result.checkout_id;
     42                                    }
     43                                    if (result.token === true) {
     44                                        $('div.zip-overlay').css('display', 'block');
     45                                        window.location.href = result.redirect;
     46                                        return;
     47                                    }
     48                                    if (result.redirect) {
     49                                        //if the checkout is successful
     50                                        console.log('resolved');
     51                                        resolve({
     52                                            data: {
     53                                                redirect_uri: result.redirect
     54                                            }
     55                                        });
     56                                    } else {
     57                                        //console.log('reject');
     58                                        errorDiv.html(result.messages);
     59                                        errorDiv.show();
     60                                        //scroll up to show the error
     61                                        $('html, body').animate({
     62                                            scrollTop: ($('form.checkout').offset().top - 200)
     63                                        }, 1000);
     64                                        reject(result);
     65                                    }
     66                                },
     67                                error: function(jqXHR, textStatus, errorThrown) {
     68                                    //console.log('error triggered');
     69                                    //console.log(errorThrown);
    5870                                    reject(result);
    5971                                }
    60                             },
    61                             error: function (jqXHR, textStatus, errorThrown) {
    62                                 //console.log('error triggered');
    63                                 //console.log(errorThrown);
    64                                 reject(result);
     72                            });
     73                        },
     74                        onComplete: function(response) {
     75                            //console.log('onComplete is called.');
     76
     77                            //console.log(response);
     78
     79                            if (response.state == "approved" || response.state == "referred") {
     80                                //show the redirect block
     81                                $('div.zip-overlay').css('display', 'block');
     82
     83                                location.href = "<?php echo WC_Zipmoney_Payment_Gateway_Util::get_complete_endpoint_url(); ?>&result=" +
     84                                    response.state + "&checkoutId=" + response.checkoutId;
     85
     86                                //show the over lay
     87                            } else if ((response.state == 'cancelled' || response.state == 'declined') && checkoutId) {
     88                                //clear the wp_options
     89                                //  console.log('clear options. ' + checkoutId);
     90                                $.post('<?php echo WC_Zipmoney_Payment_Gateway_Util::get_clear_options_url() ?>', {
     91                                    checkout_id: checkoutId
     92                                });
    6593                            }
    66                         });
    67                     },
    68                     onComplete: function (response) {
    69                         //console.log('onComplete is called.');
     94                        },
     95                        onError: function(response) {
     96                            //console.log('onError is called.');
     97                            var errorMessage = "An error occurred while redirect to Zip.";
     98                            var message = $(response.detail.messages).text();
     99                            if (typeof message != 'undefined' && message != null && message.length > 0) {
     100                                message = message.trim();
     101                                message = message.replace(/\s+/g, ' ');
     102                                message = message.replace(/\./g, '.\n');
     103                                errorMessage = message;
     104                            }
     105                            alert(errorMessage);
     106                        }
    70107
    71                         //console.log(response);
     108                    });
    72109
    73                         if (response.state == "approved" || response.state == "referred") {
    74                             //show the redirect block
    75                             $('div.zip-overlay').css('display', 'block');
     110                    e.preventDefault();
     111                }
     112            });
    76113
    77                             location.href = "<?php echo WC_Zipmoney_Payment_Gateway_Util::get_complete_endpoint_url();?>&result=" +
    78                                 response.state + "&checkoutId=" + response.checkoutId;
    79 
    80                             //show the over lay
    81                         } else if((response.state == 'cancelled' || response.state == 'declined') && checkoutId){
    82                             //clear the wp_options
    83                           //  console.log('clear options. ' + checkoutId);
    84                             $.post('<?php echo WC_Zipmoney_Payment_Gateway_Util::get_clear_options_url()?>', {checkout_id:checkoutId});
    85                         }
    86                     },
    87                     onError: function(response){
    88                         //console.log('onError is called.');
    89                         var errorMessage = "An error occurred while redirect to Zip.";
    90                         var message = $(response.detail.messages).text();
    91                         if (typeof message != 'undefined' && message != null && message.length > 0) {
    92                             message = message.trim();
    93                             message = message.replace(/\s+/g, ' ');
    94                             message = message.replace(/\./g, '.\n');
    95                             errorMessage = message;
    96                         }
    97                         alert(errorMessage);
    98                     }
    99 
    100                 });
    101 
    102                 e.preventDefault();
    103             }
    104114        });
    105115
    106      });
    107        
    108 })(window.jQuery || window.$);
    109 
     116    })(window.jQuery || window.$);
    110117</script>
  • zipmoney-payments-woocommerce/trunk/vendor/zipmoney/merchantapi-php/lib/Api/ChargesApi.php

    r2283719 r2776894  
    163163                    $e->setResponseObject($data);
    164164                    break;
     165                case 403:
     166                    $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\zipMoney\Model\ErrorResponse', $e->getResponseHeaders());
     167                    $e->setResponseObject($data);
     168                    break;
    165169                case 409:
    166170                    $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\zipMoney\Model\ErrorResponse', $e->getResponseHeaders());
  • zipmoney-payments-woocommerce/trunk/zipmoney-payment-gateway.php

    r2685692 r2776894  
    77 * Give your customers the power to pay later, interest free and watch your sales grow.
    88 * Take advantage of our fast-growing customer base, proven revenue uplift, fast and simple integration.
    9  * Version:           2.3.13
     9 * Version:           2.3.14
    1010 * Author:            Zip
    1111 * Author URI:        https://www.zip.co/
     
    1414 * Github URI:        https://github.com/zipMoney/woocommerce/
    1515 * WC requires at least: 2.6.13
    16  * WC tested up to: 6.0.0
    17  * @version  2.3.13
     16 * WC tested up to: 6.7.0
     17 * @version  2.3.14
    1818 * @package  Zip
    1919 * @author   Zip
     
    2424    die;
    2525}
     26register_activation_hook(__FILE__, 'plugin_activation');
    2627require_once plugin_dir_path(__FILE__) . 'vendor/autoload.php';
    27 define('WOOCOMMERCE_GATEWAY_ZIPMONEY_VERSION', '2.3.13');
     28define('WOOCOMMERCE_GATEWAY_ZIPMONEY_VERSION', '2.3.14');
    2829define('WOOCOMMERCE_GATEWAY_ZIPMONEY_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
    2930define('WOOCOMMERCE_GATEWAY_ZIPMONEY_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
    30 
    3131/**
    3232 * Add zipMoney gateway class to hook
     
    4040    return $methods;
    4141}
     42
     43/**
     44 * install tokenisation table
     45 */
     46function plugin_activation()
     47{
     48    global $wpdb;
     49    $charset_collate = $wpdb->get_charset_collate();
     50    $table_name = $wpdb->prefix . 'zip_tokenisation';
     51    $customer_table = $wpdb->prefix . 'users';
     52    $sql = "CREATE TABLE `$table_name` (
     53    `id` int(11) NOT NULL AUTO_INCREMENT,
     54    `customer_id` bigint(20) unsigned NOT NULL,
     55    `token` varchar(220) DEFAULT NULL,
     56    PRIMARY KEY(id),
     57    INDEX customer_id(customer_id),
     58    FOREIGN KEY(customer_id) REFERENCES $customer_table(id) ON UPDATE CASCADE ON DELETE CASCADE
     59    ) $charset_collate ;
     60    ";
     61    if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
     62        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
     63        dbDelta($sql);
     64    }
     65}
     66
    4267
    4368/**
Note: See TracChangeset for help on using the changeset viewer.