diff --git a/assets/build/unzer_apple_pay_v2.asset.php b/assets/build/unzer_apple_pay_v2.asset.php new file mode 100644 index 0000000..7068254 --- /dev/null +++ b/assets/build/unzer_apple_pay_v2.asset.php @@ -0,0 +1,4 @@ + array( 'react-jsx-runtime', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities' ), + 'version' => '11275690762e1158d528', +); diff --git a/assets/build/unzer_apple_pay_v2.js b/assets/build/unzer_apple_pay_v2.js new file mode 100644 index 0000000..6c22c1c --- /dev/null +++ b/assets/build/unzer_apple_pay_v2.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.htmlEntities,n=window.wc.wcBlocksRegistry,t=window.ReactJSXRuntime,s=window.wc.wcSettings,o=window.wp.element,i="apple_pay_v2",p=(0,s.getSetting)("unzer_"+i+"_data",{}),c=p.title||i,a=p.id||i,r=p?.description||"",m=p?.publicKey||"",u=p?.locale||"",d=p.paymentComponentId||a+"-payment-component",R=({eventRegistration:e,emitResponse:n})=>{const{onPaymentSetup:s}=e;return(0,o.useEffect)(()=>{const e=s(function(e,n,t,s){return async()=>{try{const n=document.getElementById(e);n||console.error("unzer payment component does not exist: "+e);const o=await n.submit();if(o.submitResponse){if(!0===o.submitResponse.success){const e={};e.unzer_nonce=s.nonce,e["unzer-apple-pay-v2-id"]=o.submitResponse.data.id;const n={type:t?.responseTypes?.SUCCESS,meta:{paymentMethodData:e}};return console.log("submit response: ",o.submitResponse,n),n}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 1"}}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 2"}}catch(e){return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 3"}}}}(d,0,n,p));return e},[s]),(0,t.jsxs)("div",{children:[r&&(0,t.jsx)("p",{children:r}),(0,t.jsx)("unzer-payment",{id:d,publicKey:m,locale:u,children:(0,t.jsx)("unzer-apple-pay",{})})]})};!function(s,o,i){(0,n.registerPaymentMethod)({name:s,label:(0,t.jsx)("div",{children:(0,t.jsx)("span",{className:"wc-block-components-payment-method-label",children:o})}),content:i,edit:i,canMakePayment:()=>!0,ariaLabel:(0,e.decodeEntities)(o),supports:{features:["products"]}})}(a,c,(0,t.jsx)(R,{}))})(); \ No newline at end of file diff --git a/assets/build/unzer_card.asset.php b/assets/build/unzer_card.asset.php new file mode 100644 index 0000000..becffaa --- /dev/null +++ b/assets/build/unzer_card.asset.php @@ -0,0 +1,4 @@ + array( 'react-jsx-runtime', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities' ), + 'version' => '3cff6bed3cc968bbf96f', +); diff --git a/assets/build/unzer_card.js b/assets/build/unzer_card.js new file mode 100644 index 0000000..0080402 --- /dev/null +++ b/assets/build/unzer_card.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.htmlEntities,n=window.wc.wcBlocksRegistry,t=window.ReactJSXRuntime,s=window.wc.wcSettings,o=window.wp.element,c="card",i=(0,s.getSetting)("unzer_card_data",{}),r=i.title||c,a=i.id||c,p=i?.description||"",d=i?.publicKey||"",m=(i?.locale||"")+(new Date).getMilliseconds(),u=i.paymentComponentId||a+"-payment-component",R=({eventRegistration:e,emitResponse:n})=>{const{onPaymentSetup:s}=e;return(0,o.useEffect)(()=>{const e=s(function(e,n,t,s){return async()=>{try{const n=document.getElementById(e);n||console.error("unzer payment component does not exist: "+e);const o=await n.submit();if(o.submitResponse){if(!0===o.submitResponse.success){const e={};e.unzer_nonce=s.nonce,e["unzer-card-id"]=o.submitResponse.data.id;const n={type:t?.responseTypes?.SUCCESS,meta:{paymentMethodData:e}};return console.log("submit response: ",o.submitResponse,n),n}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 1"}}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 2"}}catch(e){return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 3"}}}}(u,0,n,i));return e},[s]),(0,t.jsxs)("div",{children:[p&&(0,t.jsx)("p",{children:p}),(0,t.jsx)("unzer-payment",{id:u,publicKey:d,locale:m,children:(0,t.jsx)("unzer-card",{})})]})};!function(s,o,c){(0,n.registerPaymentMethod)({name:s,label:(0,t.jsx)("div",{children:(0,t.jsx)("span",{className:"wc-block-components-payment-method-label",children:o})}),content:c,edit:c,canMakePayment:()=>!0,ariaLabel:(0,e.decodeEntities)(o),supports:{features:["products"]}})}(a,r,(0,t.jsx)(R,{}))})(); \ No newline at end of file diff --git a/assets/build/unzer_direct_debit.asset.php b/assets/build/unzer_direct_debit.asset.php new file mode 100644 index 0000000..957db10 --- /dev/null +++ b/assets/build/unzer_direct_debit.asset.php @@ -0,0 +1,4 @@ + array( 'react-jsx-runtime', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities' ), + 'version' => '00adb3a0559cdb92af78', +); diff --git a/assets/build/unzer_direct_debit.js b/assets/build/unzer_direct_debit.js new file mode 100644 index 0000000..66316ee --- /dev/null +++ b/assets/build/unzer_direct_debit.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.htmlEntities,t=window.wc.wcBlocksRegistry,n=window.ReactJSXRuntime,s=window.wc.wcSettings,o=window.wp.element,i="direct_debit",c=(0,s.getSetting)("unzer_"+i+"_data",{}),r=c.title||i,a=c.id||i,p=c?.description||"",d=c?.publicKey||"",m=c?.locale||"",u=c.paymentComponentId||a+"-payment-component",R=({eventRegistration:e,emitResponse:t})=>{const{onPaymentSetup:s}=e;return(0,o.useEffect)(()=>{const e=s(function(e,t,n,s){return async()=>{try{const t=document.getElementById(e);t||console.error("unzer payment component does not exist: "+e);const o=await t.submit();if(o.submitResponse){if(!0===o.submitResponse.success){const e={};e.unzer_nonce=s.nonce,e["unzer-direct-debit-id"]=o.submitResponse.data.id;const t={type:n?.responseTypes?.SUCCESS,meta:{paymentMethodData:e}};return console.log("submit response: ",o.submitResponse,t),t}return{type:n?.responseTypes?.ERROR,message:"GENERAL ERROR 1"}}return{type:n?.responseTypes?.ERROR,message:"GENERAL ERROR 2"}}catch(e){return{type:n?.responseTypes?.ERROR,message:"GENERAL ERROR 3"}}}}(u,0,t,c));return e},[s]),(0,n.jsxs)("div",{children:[p&&(0,n.jsx)("p",{children:p}),(0,n.jsx)("unzer-payment",{id:u,publicKey:d,locale:m,children:(0,n.jsx)("unzer-sepa-direct-debit",{})})]})};!function(s,o,i){(0,t.registerPaymentMethod)({name:s,label:(0,n.jsx)("div",{children:(0,n.jsx)("span",{className:"wc-block-components-payment-method-label",children:o})}),content:i,edit:i,canMakePayment:()=>!0,ariaLabel:(0,e.decodeEntities)(o),supports:{features:["products"]}})}(a,r,(0,n.jsx)(R,{}))})(); \ No newline at end of file diff --git a/assets/build/unzer_direct_debit_secured.asset.php b/assets/build/unzer_direct_debit_secured.asset.php new file mode 100644 index 0000000..6ae7c10 --- /dev/null +++ b/assets/build/unzer_direct_debit_secured.asset.php @@ -0,0 +1,4 @@ + array( 'react-jsx-runtime', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities' ), + 'version' => '85a29053323ec96921e4', +); diff --git a/assets/build/unzer_direct_debit_secured.js b/assets/build/unzer_direct_debit_secured.js new file mode 100644 index 0000000..9afa1a7 --- /dev/null +++ b/assets/build/unzer_direct_debit_secured.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.htmlEntities,t=window.wc.wcBlocksRegistry,n=window.ReactJSXRuntime,s=window.wc.wcSettings,o=window.wp.element,i="direct_debit_secured",c=(0,s.getSetting)("unzer_"+i+"_data",{}),r=c.title||i,a=c.id||i,p=c?.description||"",d=c?.publicKey||"",u=c?.locale||"",m=c.paymentComponentId||a+"-payment-component",R=({eventRegistration:e,emitResponse:t})=>{const{onPaymentSetup:s}=e;return(0,o.useEffect)(()=>{const e=s(function(e,t,n,s){return async()=>{try{const t=document.getElementById(e);t||console.error("unzer payment component does not exist: "+e);const o=await t.submit();if(o.submitResponse){if(!0===o.submitResponse.success){const e={};e.unzer_nonce=s.nonce,e["unzer-direct-debit-secured-id"]=o.submitResponse.data.id;const t={type:n?.responseTypes?.SUCCESS,meta:{paymentMethodData:e}};return console.log("submit response: ",o.submitResponse,t),t}return{type:n?.responseTypes?.ERROR,message:"GENERAL ERROR 1"}}return{type:n?.responseTypes?.ERROR,message:"GENERAL ERROR 2"}}catch(e){return{type:n?.responseTypes?.ERROR,message:"GENERAL ERROR 3"}}}}(m,0,t,c));return e},[s]),(0,n.jsxs)("div",{children:[p&&(0,n.jsx)("p",{children:p}),(0,n.jsx)("unzer-payment",{id:m,publicKey:d,locale:u,children:(0,n.jsx)("unzer-paylater-direct-debit",{})})]})};!function(s,o,i){(0,t.registerPaymentMethod)({name:s,label:(0,n.jsx)("div",{children:(0,n.jsx)("span",{className:"wc-block-components-payment-method-label",children:o})}),content:i,edit:i,canMakePayment:()=>!0,ariaLabel:(0,e.decodeEntities)(o),supports:{features:["products"]}})}(a,r,(0,n.jsx)(R,{}))})(); \ No newline at end of file diff --git a/assets/build/unzer_global.asset.php b/assets/build/unzer_global.asset.php new file mode 100644 index 0000000..046d159 --- /dev/null +++ b/assets/build/unzer_global.asset.php @@ -0,0 +1,4 @@ + array( 'wp-data' ), + 'version' => '726a0e254157077b8bec', +); diff --git a/assets/build/unzer_global.js b/assets/build/unzer_global.js new file mode 100644 index 0000000..9127424 --- /dev/null +++ b/assets/build/unzer_global.js @@ -0,0 +1 @@ +(()=>{"use strict";const t=window.wp.data;window.unzerCurrentPaymentMethod="",window.unzerCurrentAmount=0,(0,t.subscribe)(()=>{const e=(0,t.select)(window.wc.wcBlocksData.CART_STORE_KEY),n=(0,t.select)(window.wc.wcBlocksData.PAYMENT_STORE_KEY),o=e.getCartData();let a=!1;window.unzerCurrentPaymentMethod!==n.getActivePaymentMethod()&&(a=!0),a||window.unzerCurrentAmount===o.totals.total_price||(a=!0),a&&(console.log("payment method changed to: "+n.getActivePaymentMethod()),window.unzerCurrentPaymentMethod=n.getActivePaymentMethod(),window.unzerCurrentAmount=o.totals.total_price,function(t,e){console.info("updatePaymentMethodData for "+t);const n=window.wc.wcSettings.getSetting(t+"_data",{});console.log(n,e),setTimeout(async()=>{const o=document.getElementById(n.paymentComponentId);o&&Promise.all([customElements.whenDefined("unzer-payment")]).then(()=>{try{const a=new FormData;a.append("data",JSON.stringify(e)),a.append("payment_method",t),a.append("unzer_nonce",n.nonce),fetch(n.getCustomerDataUrl,{method:"POST",body:a}).then(t=>t.json()).then(t=>{const n=t.customer;if(console.log("set customer data",n),n&&o.setCustomerData(n),t.publicKey!==o.publicKey&&(o.publicKey=t.publicKey,o.initOnFirstUpdate()),o.setBasketData){o.setBasketData({amount:e.totals.total_price/100,currencyType:e.totals.currency_code,country:e.billingAddress.country});const t=document.getElementById("unzer-paylater-installment-component");t&&t.reloadPlansWithRetainedData&&(t.updateDataFromStore(),console.log(t.basketDetails),t.onDataReady())}})}catch(t){console.error(t)}})},100)}(window.unzerCurrentPaymentMethod,o))},"wc/store/cart")})(); \ No newline at end of file diff --git a/assets/build/unzer_google_pay.asset.php b/assets/build/unzer_google_pay.asset.php new file mode 100644 index 0000000..5540647 --- /dev/null +++ b/assets/build/unzer_google_pay.asset.php @@ -0,0 +1,4 @@ + array( 'react-jsx-runtime', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities' ), + 'version' => 'f61e770ae45bf7883391', +); diff --git a/assets/build/unzer_google_pay.js b/assets/build/unzer_google_pay.js new file mode 100644 index 0000000..0725272 --- /dev/null +++ b/assets/build/unzer_google_pay.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.htmlEntities,n=window.wc.wcBlocksRegistry,t=window.ReactJSXRuntime,s=window.wc.wcSettings,o=window.wp.element,i="google_pay",c=(0,s.getSetting)("unzer_"+i+"_data",{}),r=c.title||i,a=c.id||i,p=c?.description||"",m=c?.publicKey||"",u=c?.locale||"",d=c.paymentComponentId||a+"-payment-component",R=({eventRegistration:e,emitResponse:n})=>{const{onPaymentSetup:s}=e;return(0,o.useEffect)(()=>{const e=s(function(e,n,t,s){return async()=>{try{const n=document.getElementById(e);n||console.error("unzer payment component does not exist: "+e);const o=await n.submit();if(o.submitResponse){if(!0===o.submitResponse.success){const e={};e.unzer_nonce=s.nonce,e["unzer-google-pay-id"]=o.submitResponse.data.id;const n={type:t?.responseTypes?.SUCCESS,meta:{paymentMethodData:e}};return console.log("submit response: ",o.submitResponse,n),n}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 1"}}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 2"}}catch(e){return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 3"}}}}(d,0,n,c));return e},[s]),(0,t.jsxs)("div",{children:[p&&(0,t.jsx)("p",{children:p}),(0,t.jsx)("unzer-payment",{id:d,publicKey:m,locale:u,children:(0,t.jsx)("unzer-google-pay",{})})]})};!function(s,o,i){(0,n.registerPaymentMethod)({name:s,label:(0,t.jsx)("div",{children:(0,t.jsx)("span",{className:"wc-block-components-payment-method-label",children:o})}),content:i,edit:i,canMakePayment:()=>!0,ariaLabel:(0,e.decodeEntities)(o),supports:{features:["products"]}})}(a,r,(0,t.jsx)(R,{}))})(); \ No newline at end of file diff --git a/assets/build/unzer_installment.asset.php b/assets/build/unzer_installment.asset.php new file mode 100644 index 0000000..4722795 --- /dev/null +++ b/assets/build/unzer_installment.asset.php @@ -0,0 +1,4 @@ + array( 'react-jsx-runtime', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities' ), + 'version' => '60224e45e2089f765739', +); diff --git a/assets/build/unzer_installment.js b/assets/build/unzer_installment.js new file mode 100644 index 0000000..286bf0f --- /dev/null +++ b/assets/build/unzer_installment.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.htmlEntities,n=window.wc.wcBlocksRegistry,t=window.ReactJSXRuntime,s=window.wc.wcSettings,o=window.wp.element,i="installment",c=(0,s.getSetting)("unzer_"+i+"_data",{}),a=c.title||i,r=c.id||i,p=c?.description||"",m=c?.publicKey||"",l=c?.locale||"",u=c.paymentComponentId||r+"-payment-component",d=({eventRegistration:e,emitResponse:n})=>{const{onPaymentSetup:s}=e;return(0,o.useEffect)(()=>{const e=s(function(e,n,t,s){return async()=>{try{const n=document.getElementById(e);n||console.error("unzer payment component does not exist: "+e);const o=await n.submit();if(o.submitResponse){if(!0===o.submitResponse.success){const e={};e.unzer_nonce=s.nonce,e["unzer-installment-id"]=o.submitResponse.data.id;const n={type:t?.responseTypes?.SUCCESS,meta:{paymentMethodData:e}};return console.log("submit response: ",o.submitResponse,n),n}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 1"}}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 2"}}catch(e){return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 3"}}}}(u,0,n,c));return e},[s]),(0,t.jsxs)("div",{children:[p&&(0,t.jsx)("p",{children:p}),(0,t.jsx)("unzer-payment",{id:u,publicKey:m,locale:l,children:(0,t.jsx)("unzer-paylater-installment",{id:"unzer-paylater-installment-component"})})]})};!function(s,o,i){(0,n.registerPaymentMethod)({name:s,label:(0,t.jsx)("div",{children:(0,t.jsx)("span",{className:"wc-block-components-payment-method-label",children:o})}),content:i,edit:i,canMakePayment:()=>!0,ariaLabel:(0,e.decodeEntities)(o),supports:{features:["products"]}})}(r,a,(0,t.jsx)(d,{}))})(); \ No newline at end of file diff --git a/assets/build/unzer_invoice.asset.php b/assets/build/unzer_invoice.asset.php new file mode 100644 index 0000000..e31cbbd --- /dev/null +++ b/assets/build/unzer_invoice.asset.php @@ -0,0 +1,4 @@ + array( 'react-jsx-runtime', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities' ), + 'version' => '09fccfb7c08f267db209', +); diff --git a/assets/build/unzer_invoice.js b/assets/build/unzer_invoice.js new file mode 100644 index 0000000..a027d8c --- /dev/null +++ b/assets/build/unzer_invoice.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.htmlEntities,n=window.wc.wcBlocksRegistry,t=window.ReactJSXRuntime,s=window.wc.wcSettings,o=window.wp.element,i="invoice",c=(0,s.getSetting)("unzer_"+i+"_data",{}),r=c.title||i,a=c.id||i,p=c?.description||"",m=c?.publicKey||"",u=c?.locale||"",d=c.paymentComponentId||a+"-payment-component",R=({eventRegistration:e,emitResponse:n})=>{const{onPaymentSetup:s}=e;return(0,o.useEffect)(()=>{const e=s(function(e,n,t,s){return async()=>{try{const n=document.getElementById(e);n||console.error("unzer payment component does not exist: "+e);const o=await n.submit();if(o.submitResponse){if(!0===o.submitResponse.success){const e={};e.unzer_nonce=s.nonce,e["unzer-invoice-id"]=o.submitResponse.data.id;const n={type:t?.responseTypes?.SUCCESS,meta:{paymentMethodData:e}};return console.log("submit response: ",o.submitResponse,n),n}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 1"}}return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 2"}}catch(e){return{type:t?.responseTypes?.ERROR,message:"GENERAL ERROR 3"}}}}(d,0,n,c));return e},[s]),(0,t.jsxs)("div",{children:[p&&(0,t.jsx)("p",{children:p}),(0,t.jsx)("unzer-payment",{id:d,publicKey:m,locale:u,children:(0,t.jsx)("unzer-paylater-invoice",{})})]})};!function(s,o,i){(0,n.registerPaymentMethod)({name:s,label:(0,t.jsx)("div",{children:(0,t.jsx)("span",{className:"wc-block-components-payment-method-label",children:o})}),content:i,edit:i,canMakePayment:()=>!0,ariaLabel:(0,e.decodeEntities)(o),supports:{features:["products"]}})}(a,r,(0,t.jsx)(R,{}))})(); \ No newline at end of file diff --git a/assets/build/unzer_open_banking.asset.php b/assets/build/unzer_open_banking.asset.php new file mode 100644 index 0000000..999cf91 --- /dev/null +++ b/assets/build/unzer_open_banking.asset.php @@ -0,0 +1,4 @@ + array( 'react-jsx-runtime', 'wc-blocks-registry', 'wp-html-entities' ), + 'version' => '659fc40d4c203c7a7228', +); diff --git a/assets/build/unzer_open_banking.js b/assets/build/unzer_open_banking.js new file mode 100644 index 0000000..b82ad7b --- /dev/null +++ b/assets/build/unzer_open_banking.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.htmlEntities,n=window.wc.wcBlocksRegistry,t=window.ReactJSXRuntime,i="open_banking",c=window.wc.wcSettings.getSetting("unzer_"+i+"_data",{}),s=c.title||i,a=c.id||i,o=c?.description||"",d=c?.publicKey||"",l=c?.locale||"",p=c.paymentComponentId||a+"-payment-component",r=()=>(0,t.jsxs)("div",{children:[o&&(0,t.jsx)("p",{children:o}),(0,t.jsx)("unzer-payment",{id:p,publicKey:d,locale:l,children:(0,t.jsx)("unzer-open-banking",{})})]});!function(i,c,s){(0,n.registerPaymentMethod)({name:i,label:(0,t.jsx)("div",{children:(0,t.jsx)("span",{className:"wc-block-components-payment-method-label",children:c})}),content:s,edit:s,canMakePayment:()=>!0,ariaLabel:(0,e.decodeEntities)(c),supports:{features:["products"]}})}(a,s,(0,t.jsx)(r,{}))})(); \ No newline at end of file diff --git a/assets/build/unzer_simple.asset.php b/assets/build/unzer_simple.asset.php new file mode 100644 index 0000000..854eda9 --- /dev/null +++ b/assets/build/unzer_simple.asset.php @@ -0,0 +1,4 @@ + array( 'react-jsx-runtime', 'wc-blocks-registry', 'wc-settings', 'wp-html-entities' ), + 'version' => 'aa971fc6a6cdf5615f0c', +); diff --git a/assets/build/unzer_simple.js b/assets/build/unzer_simple.js new file mode 100644 index 0000000..557a514 --- /dev/null +++ b/assets/build/unzer_simple.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.htmlEntities,t=window.wc.wcBlocksRegistry,n=window.ReactJSXRuntime,i=window.wc.wcSettings;function c(c){const a=(0,i.getSetting)("unzer_"+c+"_data",{}),s=a.title||c,o=a.id||c,d=a?.description||"",r=()=>(0,n.jsx)("div",{children:d&&(0,n.jsx)("p",{children:d})});!function(i,c,a){(0,t.registerPaymentMethod)({name:i,label:(0,n.jsx)("div",{children:(0,n.jsx)("span",{className:"wc-block-components-payment-method-label",children:c})}),content:a,edit:a,canMakePayment:()=>!0,ariaLabel:(0,e.decodeEntities)(c),supports:{features:["products"]}})}(o,s,(0,n.jsx)(r,{}))}const a=["alipay","bancontact","eps","ideal","klarna","postfinance_card","postfinance_efinance","prepayment","przelewy24","twint","wechatpay","wero"];for(const e of a)c(e)})(); \ No newline at end of file diff --git a/assets/css/admin-order-view.css b/assets/css/admin-order-view.css new file mode 100644 index 0000000..1c766cf --- /dev/null +++ b/assets/css/admin-order-view.css @@ -0,0 +1,194 @@ +/* Header row with status */ +.unzer-header-row { + display: flex; + align-items: center; + gap: 12px; + margin-bottom: 12px; +} + +.unzer-payment-id { + font-weight: 600; + font-size: 13px; + color: #1d2327; +} + +/* Status Badge - inline */ +#unzer-status-message { + display: inline-block; + border-radius: 3px; + padding: 2px 8px; + font-weight: 500; + font-size: 12px; + text-transform: capitalize; + background: #f0f0f1; + color: #50575e; +} + +#unzer-status-message.empty { + display: none; +} + +#unzer-status-message.unzer-status-chargeback, +#unzer-status-message.unzer-status-canceled { + color: #761919; + background: #eba3a3; +} + +#unzer-status-message.unzer-status-completed, +#unzer-status-message.unzer-status-success { + color: #5b841b; + background: #c6e1c6; +} + +#unzer-status-message.unzer-status-pending { + color: #996800; + background: #fcf9e8; +} + +#unzer-status-message.unzer-status-partly { + color: #2271b1; + background: #f0f6fc; +} + +/* Totals - compact inline layout */ +.unzer-totals-row { + display: flex; + flex-wrap: wrap; + gap: 4px 16px; + font-size: 12px; + margin-bottom: 12px; + padding-bottom: 12px; + border-bottom: 1px solid #f0f0f1; +} + +.unzer-totals-row .unzer-total-item { + display: flex; + gap: 4px; +} + +.unzer-totals-row .unzer-total-label { + color: #50575e; +} + +.unzer-totals-row .unzer-total-value { + font-weight: 600; + font-variant-numeric: tabular-nums; +} + +/* Payment Instructions */ +.unzer-instructions { + font-size: 12px; + margin-bottom: 12px; + padding: 8px; + background: #fcf9e8; + border-left: 3px solid #dba617; +} + +/* Capture Action - inline */ +.unzer-capture-row { + display: flex; + align-items: center; + gap: 8px; + margin-bottom: 12px; +} + +.unzer-capture-row:empty { + display: none; +} + +.unzer-capture-row .button.is-loading { + pointer-events: none; + opacity: 0.7; +} + +.unzer-capture-row .button.is-loading::after { + content: ""; + display: inline-block; + width: 10px; + height: 10px; + margin-left: 6px; + border: 2px solid currentColor; + border-right-color: transparent; + border-radius: 50%; + animation: unzer-spin 0.6s linear infinite; + vertical-align: middle; +} + +@keyframes unzer-spin { + to { transform: rotate(360deg); } +} + +#unzer-capture-amount-input { + width: 90px; + padding: 2px 6px; + border: 1px solid #8c8f94; + border-radius: 3px; + font-size: 12px; +} + +#unzer-capture-amount-input:focus { + border-color: #2271b1; + box-shadow: 0 0 0 1px #2271b1; + outline: none; +} + +/* Transactions Table - compact */ +#unzer-transactions { + width: 100%; + border-collapse: collapse; + font-size: 12px; + margin-bottom: 12px; +} + +#unzer-transactions thead th { + text-align: left; + padding: 6px 8px 6px 0; + font-weight: 600; + font-size: 11px; + color: #50575e; + text-transform: uppercase; + letter-spacing: 0.3px; + border-bottom: 1px solid #c3c4c7; +} + +#unzer-transactions tbody td { + padding: 6px 8px 6px 0; + vertical-align: middle; +} + +#unzer-transactions tbody tr.unzer-row-error { + color: #d63638; +} + +#unzer-transactions tbody tr.unzer-row-pending { + color: #a7aaad; +} + +#unzer-transactions tbody tr.unzer-row-success { + color: #1d2327; +} + +/* Debug Section - minimal */ +.unzer-debug-section { + margin-top: 8px; +} + +.unzer-debug-section .button { + font-size: 11px; + padding: 0 8px; + min-height: 24px; + line-height: 22px; +} + +#unzer-debug { + display: none; + margin-top: 8px; + padding: 8px; + background: #f6f7f7; + border: 1px solid #c3c4c7; + border-radius: 3px; + font-size: 10px; + line-height: 1.4; + overflow-x: auto; + max-height: 300px; +} \ No newline at end of file diff --git a/assets/css/checkout.css b/assets/css/checkout.css index fbff863..557b3f6 100644 --- a/assets/css/checkout.css +++ b/assets/css/checkout.css @@ -38,4 +38,8 @@ apple-pay-button { } .apple-pay-button-black { -apple-pay-button-style: black; +} + +.unzer-payment-instrument-new-form{ + display: none; } \ No newline at end of file diff --git a/assets/js/account.js b/assets/js/account.js new file mode 100644 index 0000000..9d15b52 --- /dev/null +++ b/assets/js/account.js @@ -0,0 +1,33 @@ +document.addEventListener( + 'DOMContentLoaded', + function () { + document.querySelectorAll( '.unzer-delete-instrument' ).forEach( + function ( el ) { + el.addEventListener( + 'click', + function ( e ) { + e.preventDefault(); + const instrumentId = this.getAttribute( 'data-instrument-id' ); + const deleteUrl = this.getAttribute( 'data-delete-url' ); + const nonce = this.getAttribute( 'data-nonce' ); + + fetch( + deleteUrl, + { + method: 'POST', + body: 'instrument=' + encodeURIComponent( instrumentId ) + '&unzer_nonce=' + encodeURIComponent( nonce ), + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ).then( + function () { + location.reload(); + } + ); + } + ); + } + ); + } +); diff --git a/assets/js/admin_apple_pay.js b/assets/js/admin_apple_pay.js deleted file mode 100644 index ea32719..0000000 --- a/assets/js/admin_apple_pay.js +++ /dev/null @@ -1,70 +0,0 @@ -document.addEventListener( - 'DOMContentLoaded', - function () { - document.querySelectorAll( '.apple-pay-remove-key' ).forEach( - function (el) { - el.addEventListener( - 'click', - function (e) { - e.preventDefault(); - const key = el.getAttribute( 'data-key' ); - const formData = new FormData(); - formData.append( 'key', key ); - formData.append( 'unzer_nonce', el.getAttribute( 'data-nonce' ) ); - fetch( - el.href, - { - method: 'POST', - body: formData - } - ) - .then( - function (response) { - return response.json() - } - ) - .then( - function (data) { - if (data.success) { - document.getElementById( 'unzer_apple_pay_' + key + '_preview' ).remove(); - el.remove(); - } - } - ); - } - ); - } - ); - - if (unzerApplePay && unzerApplePay.validationUrl) { - fetch( unzerApplePay.validationUrl ) - .then( - function (response) { - return response.json() - } - ) - .then( - function (data) { - for (const key in data.status) { - const container = document.getElementById( key + '_status' ); - if (container) { - const statusIndicator = container.querySelector( '.unzer-status-circle' ); - const message = container.querySelector( '.unzer-status-text' ); - - if (data.status[key] === "0") { - statusIndicator.classList.remove( 'success' ); - statusIndicator.classList.add( 'error' ); - } else { - statusIndicator.classList.remove( 'error' ); - statusIndicator.classList.add( 'success' ); - } - if (typeof data.messages[key] !== 'undefined') { - message.innerHTML = data.messages[key]; - } - } - } - } - ); - } - } -); \ No newline at end of file diff --git a/assets/js/checkout.js b/assets/js/checkout.js index 6ba13b1..5abcbda 100755 --- a/assets/js/checkout.js +++ b/assets/js/checkout.js @@ -1,111 +1,53 @@ -const UnzerConfig = { - getPublicKey() { - return unzer_parameters.publicKey || ''; - }, - getLocale() { - return unzer_parameters.locale || navigator.language || navigator.userLanguage || null; - }, - getPublicKeyForPayLater( isB2B, currency ) { - if (currency === 'EUR') { - return isB2B ? unzer_parameters.publicKey_eur_b2b : unzer_parameters.publicKey_eur_b2c; - } else if (currency === 'CHF') { - return isB2B ? unzer_parameters.publicKey_chf_b2b : unzer_parameters.publicKey_chf_b2c; - } - return null; - }, - getPublicKeyForInstallment( currency ) { - if (currency === 'EUR') { - return unzer_parameters.publicKey_installment_eur_b2c; - } else if (currency === 'CHF') { - return unzer_parameters.publicKey_installment_chf_b2c; - } - return null; - }, - getPublicKeyForDirectDebitSecured() { - return unzer_parameters.publicKey_directdebitsecured_eur_b2c; - } -} - const UnzerManager = { - instance: null, currency: null, country: null, instancePayLaterB2B: null, instancePayLaterB2C: null, instanceInstallments: null, - b2bState: false, initTimeout: null, init() { if (UnzerManager.initTimeout) { clearTimeout( UnzerManager.initTimeout ); } - UnzerManager.initTimeout = setTimeout( function () { UnzerManager.currency = unzer_parameters.currency; - UnzerManager.instance = UnzerManager.instance || new unzer( UnzerConfig.getPublicKey(), {locale: UnzerConfig.getLocale()} ); - UnzerManager.b2bState = UnzerManager.isB2B(); - UnzerManager.checkCountry(); - // separate instances for invoice/paylater + b2b/b2c - if (UnzerConfig.getPublicKeyForPayLater( true, UnzerManager.currency )) { - UnzerManager.instancePayLaterB2B = UnzerManager.instancePayLaterB2B || new unzer( - UnzerConfig.getPublicKeyForPayLater( true, UnzerManager.currency ), - { - locale: UnzerConfig.getLocale(), - showNotify: false - } - ); - } - if (UnzerConfig.getPublicKeyForPayLater( false, UnzerManager.currency )) { - UnzerManager.instancePayLaterB2C = UnzerManager.instancePayLaterB2C || new unzer( - UnzerConfig.getPublicKeyForPayLater( false, UnzerManager.currency ), - { - locale: UnzerConfig.getLocale(), - showNotify: false - } - ); - } - if (UnzerConfig.getPublicKeyForInstallment( UnzerManager.currency )) { - UnzerManager.instanceInstallments = UnzerManager.instanceInstallments || new unzer( - UnzerConfig.getPublicKeyForInstallment( UnzerManager.currency ), - { - locale: UnzerConfig.getLocale(), - showNotify: false - } - ); - } - if (UnzerConfig.getPublicKeyForDirectDebitSecured()) { - UnzerManager.instanceDirectDebitSecured = UnzerManager.instanceDirectDebitSecured || new unzer( - UnzerConfig.getPublicKeyForDirectDebitSecured(), - { - locale: UnzerConfig.getLocale(), - showNotify: false - } - ); - } - - document.addEventListener( - 'unzer_country_changed', - function () { - UnzerManager.toggleDirectDebitSecuredDisplay(); - UnzerManager.toggleInstallmentDisplay(); - } - ); UnzerManager.initCard(); UnzerManager.initDirectDebit(); UnzerManager.initDirectDebitSecured(); UnzerManager.initInstallment(); - UnzerManager.initIdeal(); UnzerManager.initInvoice(); UnzerManager.initApplePay(); - UnzerManager.initApplePayV2(); UnzerManager.initGooglePay(); UnzerManager.initSavedPaymentInstruments(); }, - 500 + 10 ); }, + async submitPaymentElement( unzerPaymentElement ) { + const response = await unzerPaymentElement.submit(); + console.log( JSON.stringify( response ) ); + if (response.submitResponse) { + if (response.submitResponse.success === true) { + const result = { + paymentTypeId: response.submitResponse.data.id, + threatMetrixId: response.threatMetrixId || null, + }; + if (response.customerResponse && response.customerResponse.success) { + result.customerId = response.customerResponse.data.id; + } + return result; + } else { + UnzerManager.error( 'GENERAL ERROR' ); + return null; + } + } else { + UnzerManager.error( 'EXCEPTIONAL ERROR' ); + return null; + } + }, + initSavedPaymentInstruments() { const updateFunction = function () { const containers = document.querySelectorAll( '.unzer-saved-payment-instruments-container' ); @@ -135,52 +77,10 @@ const UnzerManager = { }, initCard() { - const cardForm = document.getElementById( 'unzer-card-form' ); - if ( ! cardForm) { - return; - } - if (cardForm.getAttribute( 'is-init' )) { - return; - } - cardForm.setAttribute( 'is-init', true ); - const cardFormId = cardForm.getAttribute( 'data-form-id' ); - - // Create an Unzer instance with your public key - - const cardInstance = UnzerManager.instance.Card(); - cardInstance.create( - 'holder', - { - containerId: 'unzer-card-form-holder-' + cardFormId, - onlyIframe: false - } - ); - cardInstance.create( - 'number', - { - containerId: 'unzer-card-form-number-' + cardFormId, - onlyIframe: false - } - ); - cardInstance.create( - 'expiry', - { - containerId: 'unzer-card-form-expiry-' + cardFormId, - onlyIframe: false - } - ); - cardInstance.create( - 'cvc', - { - containerId: 'unzer-card-form-cvc-' + cardFormId, - onlyIframe: false - } - ); - document.getElementById( 'unzer-card-id' ).value = ''; jQuery( document.body ).on( 'checkout_error', function () { - // document.getElementById('unzer-card-id').value = ''; + document.getElementById( 'unzer-card-id' ).value = ''; } ); jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_card' ); @@ -191,53 +91,18 @@ const UnzerManager = { if (selectedSavedCard && selectedSavedCard.value) { return true; } - if (document.getElementById( 'unzer-card-id' ).value) { - return true; - } - cardInstance.createResource() - .then( - function (result) { - document.getElementById( 'unzer-card-id' ).value = result.id; - document.getElementById( 'unzer-card-form' ).innerHTML = '
' + result.cardHolder + '
' + result.number + '
' + result.expiryDate + '
'; - UnzerManager.getCheckoutForm().trigger( 'submit' ); - } - ) - .catch( - function (error) { - console.warn( error ); - UnzerManager.error( error.customerMessage || error.message ); - } - ) - return false; + return UnzerManager.handleSubmit( 'unzer-card-id', 'unzer-card-payment-component' ); } ); }, initDirectDebit() { - const form = document.getElementById( 'unzer-direct-debit-form' ); - if ( ! form) { - return; - } - if (form.getAttribute( 'is-init' )) { - return; - } - form.setAttribute( 'is-init', true ); - const formId = form.getAttribute( 'data-form-id' ); - // Create an Unzer instance with your public key - - const directDebitInstance = UnzerManager.instance.SepaDirectDebit(); - - directDebitInstance.create( - 'sepa-direct-debit', - { - containerId: 'unzer-direct-debit-iban-' + formId - } - ); - document.getElementById( 'unzer-direct-debit-id' ).value = ''; jQuery( document.body ).on( 'checkout_error', function () { - document.getElementById( 'unzer-direct-debit-id' ).value = ''; + if (document.getElementById( 'unzer-direct-debit-id' )) { + document.getElementById( 'unzer-direct-debit-id' ).value = ''; + } } ); jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_direct_debit' ); @@ -248,259 +113,48 @@ const UnzerManager = { if (selectedSavedCard && selectedSavedCard.value) { return true; } - const sepaMandateCheckbox = document.getElementById( 'unzer-accept-sepa-mandate-checkbox' ); - if (sepaMandateCheckbox && ! sepaMandateCheckbox.checked) { - UnzerManager.error( unzer_i18n.errorSepaMandate || 'Please accept the SEPA mandate' ); - return false; - } - - if (document.getElementById( 'unzer-direct-debit-id' ).value) { - return true; - } - directDebitInstance.createResource() - .then( - function (result) { - document.getElementById( 'unzer-direct-debit-id' ).value = result.id; - UnzerManager.getCheckoutForm().trigger( 'submit' ); - } - ) - .catch( - function (error) { - console.warn( error ); - UnzerManager.error( error.customerMessage || error.message ); - } - ) - return false; + return UnzerManager.handleSubmit( 'unzer-direct-debit-id', 'unzer-sepa-payment-component' ); } ); }, initDirectDebitSecured() { - const form = document.getElementById( 'unzer-direct-debit-secured-form' ); - if ( ! form) { - return; - } - if (form.getAttribute( 'is-init' )) { - return; - } - if ( ! UnzerManager.instanceDirectDebitSecured) { - return; - } - form.setAttribute( 'is-init', true ); - const formId = form.getAttribute( 'data-form-id' ); - UnzerManager.toggleDirectDebitSecuredDisplay(); - - const directDebitSecuredInstance = UnzerManager.instanceDirectDebitSecured.PaylaterDirectDebit(); - directDebitSecuredInstance.create( - 'paylater-direct-debit', - { - containerId: 'unzer-direct-debit-secured-form-ui-' + formId - } - ); - document.getElementById( 'unzer-direct-debit-secured-id' ).value = ''; - jQuery( document.body ).on( - 'checkout_error', - function () { - document.getElementById( 'unzer-direct-debit-secured-id' ).value = ''; - } - ); - jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_direct_debit_secured' ); - jQuery( '.woocommerce-checkout' ).on( - 'checkout_place_order_unzer_direct_debit_secured', - function () { - if ( ! document.getElementById( 'unzer-direct-debit-secured-dob' ).value) { - UnzerManager.error( unzer_i18n.errorDob || 'Please enter your date fo birth' ); - return false; - } - if (document.getElementById( 'unzer-direct-debit-secured-id' ).value) { - return true; - } - directDebitSecuredInstance.createResource() - .then( - function (result) { - document.getElementById( 'unzer-direct-debit-secured-id' ).value = result.id; - UnzerManager.getCheckoutForm().trigger( 'submit' ); - } - ) - .catch( - function (error) { - console.warn( error ); - UnzerManager.error( error.customerMessage || error.message ); - } - ) - return false; - } + UnzerManager._setCustomerDataToPaymentComponent( '#unzer-paylater-direct-debit-payment-component' ); + UnzerManager.initDefaultPaymentMethod( + 'unzer-direct-debit-secured-id', + 'unzer-paylater-direct-debit-payment-component', + 'unzer_direct_debit_secured' ); }, initInstallment() { - const form = document.getElementById( 'unzer-installment-form' ); - if ( ! form) { - return; - } - if (form.getAttribute( 'is-init' )) { - return; - } - - const unzerInstance = UnzerManager.instanceInstallments; - UnzerManager.toggleInstallmentDisplay(); - if ( ! unzerInstance) { - return; - } - - - form.setAttribute( 'is-init', true ); - - UnzerManager.checkCountry(); - const installmentInstance = unzerInstance.PaylaterInstallment(); - installmentInstance.create( - { - containerId: 'unzer-installment-fields', - amount: parseFloat( document.getElementById( 'unzer-installment-amount' ).value ), - currency: UnzerManager.currency, - customerType: 'B2C', - country: UnzerManager.country - } - ); - - const installmentCountryChangedHandler = function () { - const isInstallmentAvailable = UnzerManager.toggleInstallmentDisplay(); - if (isInstallmentAvailable) { - const fetchPlansPromise = installmentInstance.fetchPlans( - { - country: UnzerManager.country - } - ); - fetchPlansPromise - .then( - function (data) { - } - ) - .catch( - function (error) { - } - ); - } - } - document.addEventListener( 'unzer_country_changed', installmentCountryChangedHandler ); - - document.getElementById( 'unzer-installment-id' ).value = ''; - jQuery( document.body ).on( - 'checkout_error', - function () { - document.getElementById( 'unzer-installment-id' ).value = ''; - } - ); - jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_installment' ); - jQuery( '.woocommerce-checkout' ).on( - 'checkout_place_order_unzer_installment', - function () { - if (document.getElementById( 'unzer-installment-id' ).value) { - return true; - } - if ( ! document.getElementById( 'unzer-installment-dob' ).value) { - UnzerManager.error( unzer_i18n.errorDob || 'Please enter your date fo birth' ); - return false; + UnzerManager._setCustomerDataToPaymentComponent( '#unzer-paylater-installment-payment-component' ); + const unzerPaymentElement = document.getElementById( 'unzer-paylater-installment-payment-component' ); + if (unzerPaymentElement && unzerPaymentElement.setBasketData) { + unzerPaymentElement.setBasketData( + { + amount: parseFloat( document.getElementById( 'unzer-installment-amount' ).value ), + currencyType: UnzerManager.currency, + country: UnzerManager.getCountry() } - installmentInstance.createResource() - .then( - function (result) { - document.getElementById( 'unzer-installment-id' ).value = result.id; - UnzerManager.getCheckoutForm().trigger( 'submit' ); - } - ) - .catch( - function (error) { - console.warn( error ); - UnzerManager.error( error.customerMessage || error.message ); - } - ) - return false; - } - ); - }, - - toggleInstallmentDisplay() { - const paymentMethodContainer = document.querySelector( '.wc_payment_method.payment_method_unzer_installment' ); - if ( ! paymentMethodContainer) { - return false; - } - - if ( ! UnzerManager.instanceInstallments || UnzerManager.isB2B() || ['DE', 'AT', 'CH'].indexOf( UnzerManager.country ) === -1) { - paymentMethodContainer.style.display = 'none'; - // uncheck radio button - document.getElementById( 'payment_method_unzer_installment' ).checked = false; - return false; - } else { - paymentMethodContainer.style.display = ''; - return true; - } - }, - - toggleDirectDebitSecuredDisplay() { - const paymentMethodContainer = document.querySelector( '.wc_payment_method.payment_method_unzer_direct_debit_secured' ); - if ( ! paymentMethodContainer) { - return false; - } - - if (UnzerManager.isB2B() || ['DE', 'AT'].indexOf( UnzerManager.country ) === -1) { - paymentMethodContainer.style.display = 'none'; - // uncheck radio button - document.getElementById( 'payment_method_unzer_direct_debit_secured' ).checked = false; - return false; - } else { - paymentMethodContainer.style.display = ''; - return true; + ); } + UnzerManager.initDefaultPaymentMethod( + 'unzer-installment-id', + 'unzer-paylater-installment-payment-component', + 'unzer_installment' + ); }, - rerenderInvoice() { - const form = document.getElementById( 'unzer-invoice-form' ); - if ( ! form) { - return; - } - form.removeAttribute( 'is-init' ); - form.querySelector( '#unzer-invoice-fields' ).innerHTML = ''; - UnzerManager.initInvoice(); - }, initInvoice() { - const form = document.getElementById( 'unzer-invoice-form' ); - if ( ! form) { - return; - } - - if (form.getAttribute( 'is-init' )) { - return; - } - - let unzerInstance = null; - if (UnzerManager.isB2B()) { - unzerInstance = UnzerManager.instancePayLaterB2B; - } else { - unzerInstance = UnzerManager.instancePayLaterB2C; - } - if ( ! unzerInstance) { - document.querySelector( '.wc_payment_method.payment_method_unzer_invoice' ).style.display = 'none'; - // uncheck radio button - document.getElementById( 'payment_method_unzer_invoice' ).checked = false; - return; - } - document.querySelector( '.wc_payment_method.payment_method_unzer_invoice' ).style.display = ''; - form.setAttribute( 'is-init', true ); - - const invoiceInstance = unzerInstance.PaylaterInvoice(); - invoiceInstance.create( - { - containerId: 'unzer-invoice-fields', - customerType: 'B2C', - } - ) - document.getElementById( 'unzer-invoice-id' ).value = ''; + UnzerManager._setCustomerDataToPaymentComponent( '#unzer-paylater-invoice-payment-component' ); jQuery( document.body ).on( 'checkout_error', function () { - document.getElementById( 'unzer-invoice-id' ).value = ''; + if (document.getElementById( 'unzer-invoice-id' )) { + document.getElementById( 'unzer-invoice-id' ).value = ''; + } } ); jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_invoice' ); @@ -510,322 +164,23 @@ const UnzerManager = { if (document.getElementById( 'unzer-invoice-id' ).value) { return true; } - if (UnzerManager.isB2B() && ! document.getElementById( 'unzer-invoice-company-type' ).value) { - UnzerManager.error( unzer_i18n.errorCompanyType || 'Please enter your company type' ); - return false; - } - if ( ! UnzerManager.isB2B() || (UnzerManager.isB2B() && document.getElementById( 'unzer-invoice-company-type' ).value === 'sole')) { - if ( ! document.getElementById( 'unzer-invoice-dob' ).value) { - UnzerManager.error( unzer_i18n.errorDob || 'Please enter your date of birth' ); - return false; - } - } - invoiceInstance.createResource() - .then( - function (result) { - document.getElementById( 'unzer-invoice-id' ).value = result.id; - UnzerManager.getCheckoutForm().trigger( 'submit' ); - } - ) - .catch( - function (error) { - console.warn( error ); - UnzerManager.error( error.customerMessage || error.message ); - } - ) - return false; - } - ); - }, - - initIdeal() { - if ( ! document.getElementById( 'unzer-ideal-form' )) { - return; - } - if (document.getElementById( 'unzer-ideal-form' ).getAttribute( 'is-init' )) { - return; - } - document.getElementById( 'unzer-ideal-form' ).setAttribute( 'is-init', true ); - - // Create an Unzer instance with your public key - - const idealInstance = UnzerManager.instance.Ideal(); - - idealInstance.create( - 'ideal', - { - containerId: 'unzer-ideal' - } - ); - idealInstance.addEventListener( - 'change', - function () { - document.getElementById( 'unzer-ideal-id' ).value = ''; - } - ); - document.getElementById( 'unzer-ideal-id' ).value = ''; - jQuery( document.body ).on( - 'checkout_error', - function () { - document.getElementById( 'unzer-ideal-id' ).value = ''; - } - ); - jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_ideal' ); - jQuery( '.woocommerce-checkout' ).on( - 'checkout_place_order_unzer_ideal', - function () { - if (document.getElementById( 'unzer-ideal-id' ).value) { - return true; - } - idealInstance.createResource() - .then( - function (result) { - document.getElementById( 'unzer-ideal-id' ).value = result.id; - UnzerManager.getCheckoutForm().trigger( 'submit' ); - } - ) - .catch( - function (error) { - console.warn( error ); - UnzerManager.error( error.customerMessage || error.message ); - } - ) - return false; - } - ); - }, - - initApplePay() { - if ( ! document.getElementById( 'unzer-apple-pay-id' )) { - return; - } - const applePayInstance = UnzerManager.instance.ApplePay(); - window.api = applePayInstance; - - jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_apple_pay' ); - jQuery( '.woocommerce-checkout' ).on( - 'checkout_place_order_unzer_apple_pay', - function () { - // from customer submit - if (window.doNotStartApplePaySession) { - window.doNotStartApplePaySession = false; - return true; - } - console.log( 'start ap session' ); - UnzerManager.startApplePaySession(); - return true; - } - ); - - const unzerApplePayProcessingAction = function (msg) { - console.log( 'msg: ' + msg ); - if (msg && msg.indexOf( '' ) !== -1) { - console.log( 'begind ap session' ); - UnzerManager.beginApplePaySession(); - } - } - - jQuery( document.body ).on( - 'checkout_error', - function (e, msg) { - console.log( 'checkout_error:', msg ); - unzerApplePayProcessingAction( msg ); - } - ); - - // for plugin CheckoutWC - window.addEventListener( - 'cfw-checkout-failed-before-error-message', - function (event) { - if (typeof event.detail.response.messages === 'undefined') { - return; - } - unzerApplePayProcessingAction( event.detail.response.messages ); - } - ); - - }, - - initApplePayV2() { - if ( ! document.getElementById( 'unzer-apple-pay-v2-id' )) { - return; - } - window.unzerApplePayV2Session = null; - - jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_apple_pay_v2' ); - jQuery( '.woocommerce-checkout' ).on( - 'checkout_place_order_unzer_apple_pay_v2', - function () { - if (window.doNotStartApplePayV2Session) { - window.doNotStartApplePayV2Session = false; - return true; - } - UnzerManager.initApplePayV2Session(); - return true; - } - ); - - const unzerApplePayV2ProcessingAction = function (msg) { - if (msg && msg.indexOf( '' ) !== -1) { - if (window.unzerApplePayV2Session) { - window.unzerApplePayV2Session.begin(); - } else { - console.error( 'Apple Pay V2: Session not initialized' ); - UnzerManager.error( unzer_parameters.generic_error_message ); - } - } else { - if (window.unzerApplePayV2Session) { - window.unzerApplePayV2Session.abort(); - window.unzerApplePayV2Session = null; - } - } - } - - jQuery( document.body ).on( - 'checkout_error', - function (e, msg) { - unzerApplePayV2ProcessingAction( msg ); - } - ); - - // for plugin CheckoutWC - window.addEventListener( - 'cfw-checkout-failed-before-error-message', - function (event) { - if (typeof event.detail.response.messages === 'undefined') { - return; - } - unzerApplePayV2ProcessingAction( event.detail.response.messages ); + return UnzerManager.handleSubmit( 'unzer-invoice-id', 'unzer-paylater-invoice-payment-component' ); } ); - - }, - - initApplePayV2Session() { - const unzerApplePayV2Instance = UnzerManager.instance.ApplePay(); - - const applePayV2PaymentRequest = { - countryCode: unzer_parameters.store_country, - currencyCode: UnzerManager.currency, - supportedNetworks: ['VISA', 'MASTERCARD'], - merchantCapabilities: ['supports3DS'], - total: { - label: unzer_parameters.store_name, - amount: parseFloat( document.getElementById( 'unzer-apple-pay-v2-amount' ).value ) - } - }; - - window.unzerApplePayV2Session = unzerApplePayV2Instance.initApplePaySession( applePayV2PaymentRequest ); - window.unzerApplePayV2Session.onpaymentauthorized = function (event) { - let paymentData = event.payment.token.paymentData; - unzerApplePayV2Instance.createResource( paymentData ) - .then( - function (createdResource) { - document.getElementById( 'unzer-apple-pay-v2-id' ).value = createdResource.id; - window.doNotStartApplePayV2Session = true; - UnzerManager.getCheckoutForm().trigger( 'submit' ); - setTimeout( - function () { - window.doNotStartApplePayV2Session = false; - }, - 500 - ); - } - ) - .catch( - function (error) { - UnzerManager.error( error.customerMessage || error.message || unzer_parameters.generic_error_message ); - console.log( error ); - } - ) - } - - - }, - - startApplePaySession() { - const unzerApplePayInstance = UnzerManager.instance.ApplePay(); - let applePayPaymentRequest = { - countryCode: unzer_parameters.store_country, - currencyCode: UnzerManager.currency, - supportedNetworks: ['visa', 'masterCard'], - merchantCapabilities: ['supports3DS'], - total: { - label: unzer_parameters.store_name, - amount: parseFloat( document.getElementById( 'unzer-apple-pay-amount' ).value ) - } - }; - - window.apsession = new window.ApplePaySession( 6, applePayPaymentRequest ); - - window.apsession.onvalidatemerchant = function (event) { - try { - jQuery.post( - unzer_parameters.apple_pay_merchant_validation_url, - { - validation_url: event.validationURL, - unzer_nonce: document.getElementById( 'unzer-apple-pay-nonce' ).value - }, - function (data) { - window.apsession.completeMerchantValidation( JSON.parse( data.response ) ); - } - ); - } catch (e) { - window.apsession.abort(); - UnzerManager.error( unzer_parameters.generic_error_message ); - } - } - - window.apsession.onpaymentauthorized = function (event) { - let paymentData = event.payment.token.paymentData; - unzerApplePayInstance.createResource( paymentData ) - .then( - function (createdResource) { - document.getElementById( 'unzer-apple-pay-id' ).value = createdResource.id; - window.apsession.completePayment( {status: window.ApplePaySession.STATUS_SUCCESS} ); - window.doNotStartApplePaySession = true; - UnzerManager.getCheckoutForm().trigger( 'submit' ); - setTimeout( - function () { - window.doNotStartApplePaySession = false; - }, - 500 - ); - } - ) - .catch( - function (error) { - window.apsession.abort(); - UnzerManager.error( error.customerMessage || error.message || unzer_parameters.generic_error_message ); - console.log( error ); - } - ) - } - }, - - - beginApplePaySession() { - window.apsession.begin() }, initGooglePay() { - if ( ! document.getElementById( 'unzer-google-pay-id' )) { - return; - } - if (document.getElementById( 'unzer-google-pay-id' ).getAttribute( 'is-init' )) { - return; - } - document.getElementById( 'unzer-google-pay-id' ).setAttribute( 'is-init', true ); const options = unzer_parameters.google_pay_options; if ( ! options) { return; } UnzerManager.createGooglePayButtonContainer(); - const googlePayInstance = UnzerManager.instance.Googlepay(); - const paymentDataRequestObject = googlePayInstance.initPaymentDataRequestObject( - { + const unzerPaymentElement = document.getElementById( 'unzer-google-pay-payment-component' ); + if (unzerPaymentElement && unzerPaymentElement.setGooglePayData) { + + const paymentDataRequestObject = { gatewayMerchantId: options.gatewayMerchantId, merchantInfo: options.merchantInfo, transactionInfo: { @@ -837,38 +192,28 @@ const UnzerManager = { buttonOptions: options.buttonOptions, allowedCardNetworks: options.allowedCardNetworks, allowCreditCards: options.allowCreditCards, - allowPrepaidCards: options.allowPrepaidCards, - onPaymentAuthorizedCallback: function (paymentData) { - return googlePayInstance.createResource( paymentData ) - .then( - function (result) { - document.getElementById( 'unzer-google-pay-id' ).value = result.id; - UnzerManager.getCheckoutForm().trigger( 'submit' ); - return { - status: 'success' - } - } - ) - .catch( - function (error) { - const errorMessage = error.customerMessage || error.message || 'Error'; - UnzerManager.error( errorMessage ); - return { - status: 'error', - message: errorMessage || 'Unexpected error' - } - } - ) - } - } - ); - googlePayInstance.create( - { - containerId: 'unzer_google_pay_place_order', - }, - paymentDataRequestObject - ); + allowPrepaidCards: options.allowPrepaidCards + }; + // for some reason this does not get applied without timeout? + setTimeout( + function () { + unzerPaymentElement.setGooglePayData( paymentDataRequestObject ); + }, + 100 + ); + + const unzerCheckout = document.getElementById( 'unzer-google-pay-checkout-component' ); + unzerCheckout.onPaymentSubmit = function (response) { + if (response.submitResponse && response.submitResponse.success) { + document.getElementById( 'unzer-google-pay-id' ).value = response.submitResponse.data.id; + UnzerManager.getCheckoutForm().trigger( 'submit' ); + } else { + UnzerManager.error( unzer_parameters.generic_error_message ); + console.log( 'ERROR', response ); + } + }; + } jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_google_pay' ); jQuery( '.woocommerce-checkout' ).on( 'checkout_place_order_unzer_google_pay', @@ -882,25 +227,133 @@ const UnzerManager = { ); }, + initApplePay() { + UnzerManager.createApplePayButtonContainer(); + const unzerPaymentElement = document.getElementById( 'unzer-apple-pay-payment-component' ); + if (unzerPaymentElement && unzerPaymentElement.setApplePayData) { + const applePayPaymentRequest = { + countryCode: unzer_parameters.store_country, + currencyCode: UnzerManager.currency, + supportedNetworks: ['visa', 'masterCard'], + merchantCapabilities: ['supports3DS'], + total: { + label: unzer_parameters.store_name, + amount: parseFloat( document.getElementById( 'unzer-apple-pay-v2-amount' ).value ) + } + }; + // for some reason this does not get applied without timeout? + setTimeout( + function () { + unzerPaymentElement.setApplePayData( applePayPaymentRequest ); + }, + 100 + ); + const unzerCheckout = document.getElementById( 'unzer-apple-pay-checkout-component' ); + unzerCheckout.onPaymentSubmit = function (response) { + if (response.submitResponse && response.submitResponse.data && response.submitResponse.data.id && response.submitResponse.data.id.indexOf( 'apple' ) === -1) { + return + } + if (response.submitResponse && response.submitResponse.success) { + document.getElementById( 'unzer-apple-pay-v2-id' ).value = response.submitResponse.data.id; + UnzerManager.getCheckoutForm().trigger( 'submit' ); + } else { + UnzerManager.error( unzer_parameters.generic_error_message ); + console.log( 'ERROR', response ); + } + }; + } + jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_unzer_apple_pay_v2' ); + jQuery( '.woocommerce-checkout' ).on( + 'checkout_place_order_unzer_apple_pay_v2', + function () { + if (document.getElementById( 'unzer-apple-pay-v2-id' ).value) { + return true; + } + console.error( 'Apple Pay: Checkout triggered without payment data.' ); + UnzerManager.error( unzer_parameters.generic_error_message ); + } + ); + }, + createGooglePayButtonContainer() { + const isGooglePay = UnzerManager.getSelectedPaymentMethod() === 'unzer_google_pay'; const placeOrderButton = document.querySelector( '#place_order' ); - if (placeOrderButton) { + const googlePayHtml = document.querySelector( '.unzer-google-pay-ui-template' ); + + if ( ! isGooglePay) { + let googlePayButton = document.getElementById( 'unzer_google_pay_place_order' ); + if (googlePayButton) { + googlePayButton.remove(); + } + return; + } + + + if (placeOrderButton && googlePayHtml) { let googlePayButton = document.getElementById( 'unzer_google_pay_place_order' ); if ( ! googlePayButton) { googlePayButton = document.createElement( 'div' ); googlePayButton.id = 'unzer_google_pay_place_order'; googlePayButton.style.display = 'none'; + googlePayButton.innerHTML = googlePayHtml.innerHTML; placeOrderButton.parentNode.appendChild( googlePayButton ); - } else { - googlePayButton.innerHTML = ''; } } else { console.warn( 'placeOrderButton not found for Google Pay Button' ); } }, + createApplePayButtonContainer() { + const isApplePay = UnzerManager.getSelectedPaymentMethod() === 'unzer_apple_pay_v2'; + const placeOrderButton = document.querySelector( '#place_order' ); + const applePayHtml = document.querySelector( '.unzer-apple-pay-ui-template' ); + + if ( ! isApplePay) { + let applePayButton = document.getElementById( 'unzer_apple_pay_v2_place_order' ); + if (applePayButton) { + applePayButton.remove(); + } + return; + } + + if (placeOrderButton && applePayHtml) { + let applePayButton = document.getElementById( 'unzer_apple_pay_v2_place_order' ); + if ( ! applePayButton) { + applePayButton = document.createElement( 'div' ); + applePayButton.id = 'unzer_apple_pay_v2_place_order'; + applePayButton.style.display = 'none'; + applePayButton.innerHTML = applePayHtml.innerHTML; + placeOrderButton.parentNode.appendChild( applePayButton ); + } + } else { + console.warn( 'placeOrderButton not found for Apple Pay Button' ); + } + }, + getCheckoutForm() { - return jQuery( 'form.woocommerce-checkout' ); + return jQuery( 'form.woocommerce-checkout, form#order_review' ); + }, + + showLoading() { + const $checkoutForm = UnzerManager.getCheckoutForm(); + if ($checkoutForm) { + $checkoutForm.block( + { + message: null, + overlayCSS: { + background: '#fff', + opacity: 0.6 + } + } + ); + } + }, + + hideLoading() { + const $checkoutForm = UnzerManager.getCheckoutForm(); + if ($checkoutForm) { + $checkoutForm.removeClass( 'processing' ).unblock(); + } }, error( message ) { @@ -927,18 +380,10 @@ const UnzerManager = { return (companyNameInput && companyNameInput.value !== ''); }, - checkCountry() { + getCountry() { const countryInput = document.getElementById( 'billing_country' ); let value = null; - if (countryInput) { - value = countryInput.value; - } - if (value !== UnzerManager.country) { - UnzerManager.country = value; - // trigger event - const event = new CustomEvent( 'unzer_country_changed', {detail: {country: value}} ); - document.dispatchEvent( event ); - } + return countryInput ? countryInput.value : null }, customDebug( data ) { if ( ! document.getElementById( 'unzer_debug' )) { @@ -959,6 +404,122 @@ const UnzerManager = { document.body.appendChild( debug ); } document.getElementById( 'unzer_debug' ).innerHTML += "\n\n" + JSON.stringify( data, null, 2 ); + }, + + getSelectedPaymentMethod(){ + const selectedRadio = document.querySelector( 'input[name="payment_method"]:checked' ); + if ( ! selectedRadio) { + return null; + } + return selectedRadio.value; + }, + renderCurrentPaymentMethod() { + const method = UnzerManager.getSelectedPaymentMethod(); + document.querySelectorAll( '.unzer-ui-container' ).forEach( + function (el) { + el.innerHTML = ''; + } + ); + + const currentBox = document.querySelector( 'div.payment_box.payment_method_' + method ); + if ( ! currentBox) { + return; + } + const unzerUiTemplate = currentBox.querySelector( '.unzer-ui-template' ); + if ( ! unzerUiTemplate) { + return; + } + + const thisContainer = currentBox.querySelector( '.unzer-ui-container' ); + if (thisContainer.querySelector( 'unzer-payment' )) { + // already there + return; + } + + thisContainer.innerHTML = unzerUiTemplate.innerHTML; + }, + initDefaultPaymentMethod( paymentTypeIdInputFieldId, unzerUiPaymentElementId, paymentMethodName ) { + jQuery( document.body ).on( + 'checkout_error', + function () { + const inputField = document.getElementById( paymentTypeIdInputFieldId ); + if (inputField) { + inputField.value = ''; + } + } + ); + jQuery( '.woocommerce-checkout' ).off( 'checkout_place_order_' + paymentMethodName ); + jQuery( '.woocommerce-checkout' ).on( + 'checkout_place_order_' + paymentMethodName, + function () { + return UnzerManager.handleSubmit( paymentTypeIdInputFieldId, unzerUiPaymentElementId ); + } + ); + }, + handleSubmit( inputFieldId, unzerUiPaymentElementId ) { + if (document.getElementById( inputFieldId ).value) { + return true; + } + const unzerUiPaymentElement = document.getElementById( unzerUiPaymentElementId ); + UnzerManager.showLoading(); + UnzerManager.submitPaymentElement( unzerUiPaymentElement ).then( + function (submitResult) { + UnzerManager.hideLoading(); + if (submitResult) { + document.getElementById( inputFieldId ).value = submitResult.paymentTypeId; + const inputFieldsIdBase = inputFieldId.substring( 0, inputFieldId.length - 2 ); + console.log( inputFieldsIdBase ); + if (submitResult.threatMetrixId) { + const riskIdField = document.getElementById( inputFieldsIdBase + 'risk-id' ); + if (riskIdField) { + riskIdField.value = submitResult.threatMetrixId; + } + } + if (submitResult.customerId) { + const customerIdField = document.getElementById( inputFieldsIdBase + 'customer-id' ); + if (customerIdField) { + customerIdField.value = submitResult.customerId; + } + } + UnzerManager.getCheckoutForm().trigger( 'submit' ); + } + + } + ).catch( + (error) => { + console.error( error ); + UnzerManager.hideLoading(); + } + ); + + + return false; + }, + supportsApplePay() { + return window.ApplePaySession && window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion( 6 ); + }, + _setCustomerDataToPaymentComponent( selector ) { + const paymentElement = document.querySelector( selector ); + if (paymentElement) { + Promise.all( [customElements.whenDefined( 'unzer-payment' )] ).then( + () => { + try { + const customerData = JSON.parse( atob( paymentElement.getAttribute( 'data-customer' ) ) ); + console.log( + 'set customer data', + customerData + ); + if (customerData) { + paymentElement.setCustomerData( + customerData + ); + } + } catch (e) { + console.error( e ); + } + } + ); + } } } @@ -975,99 +536,68 @@ jQuery( 'updated_checkout', function () { UnzerManager.init(); - UnzerManager.checkCountry(); + UnzerManager.renderCurrentPaymentMethod(); } ); - setInterval( - function () { - if (UnzerManager.b2bState !== UnzerManager.isB2B()) { - UnzerManager.b2bState = UnzerManager.isB2B(); - UnzerManager.rerenderInvoice(); - UnzerManager.toggleInstallmentDisplay(); - UnzerManager.toggleDirectDebitSecuredDisplay(); + if (jQuery( document.body ).hasClass( 'woocommerce-order-pay' )) { + const $form = jQuery( '#order_review' ); + jQuery( document.body ).on( + 'payment_method_selected', + function () { + UnzerManager.init(); + UnzerManager.renderCurrentPaymentMethod(); } + ); - UnzerManager.checkCountry(); - - const companyTypeInputContainer = document.getElementById( 'unzer-invoice-company-type-container' ); - const birthdate_form = document.getElementById( 'unzer-checkout-dob-row' ); - const birthdate = document.getElementById( 'unzer-invoice-dob' ); - if (birthdate_form && birthdate) { - if (companyTypeInputContainer) { - companyTypeInputContainer.style.display = UnzerManager.isB2B() ? 'block' : 'none'; - if (UnzerManager.isB2B()) { - if (document.getElementById( 'unzer-invoice-company-type' ).value === "sole") { - birthdate_form.style.display = "block"; - birthdate.setAttribute( "required", "required" ); - birthdate.name = "unzer-invoice-dob"; - } else { - birthdate_form.style.display = "none"; - birthdate.removeAttribute( "required" ); - birthdate.name = ""; - } - } else { - birthdate_form.style.display = "block"; - birthdate.setAttribute( "required", "required" ); - birthdate.name = "unzer-invoice-dob"; + jQuery( $form ).on( + 'submit', + function (e) { + const selectedPaymentMethod = $form.find( '[name="payment_method"]:checked' ).val(); + if (selectedPaymentMethod.substring( 0, 6 ) === 'unzer_') { + const returnValue = jQuery( '.woocommerce-checkout' ).triggerHandler( 'checkout_place_order_' + selectedPaymentMethod ); + if (returnValue === false) { + e.preventDefault(); } - } else { - birthdate_form.style.display = "block"; - birthdate.setAttribute( "required", "required" ); - birthdate.name = "unzer-invoice-dob"; } } + ); + } + jQuery( '#billing_company' ).on( + 'keyup', + function () { + if (UnzerManager.billingCompanyTimeout) { + clearTimeout( UnzerManager.billingCompanyTimeout ); + } + UnzerManager.billingCompanyTimeout = setTimeout( + function () { + jQuery( 'form.checkout' ).trigger( 'update' ); + }, + 1000 + ); + + } + ); + + setInterval( + function () { const placeOrderButton = document.querySelector( '#place_order' ); let showPlaceOrderButton = true; - const applePayContainer = document.querySelector( '.payment_method_unzer_apple_pay' ); + const applePayContainer = document.querySelector( '.payment_method_unzer_apple_pay_v2' ); if (applePayContainer) { - if (window.ApplePaySession && window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion( 6 )) { - applePayContainer.style.display = ''; - - if (placeOrderButton) { - let applePayButton = document.getElementById( 'unzer_apple_pay_place_order' ); - if ( ! applePayButton) { - applePayButton = document.createElement( 'div' ); - applePayButton.id = 'unzer_apple_pay_place_order'; - placeOrderButton.parentNode.appendChild( applePayButton ); - applePayButton.innerHTML = ''; - } - - if (document.getElementById( 'payment_method_unzer_apple_pay' ).checked) { - applePayButton.style.display = ''; - showPlaceOrderButton = false; - } else { - applePayButton.style.display = 'none'; - } - } - } else { + const applePayButton = document.getElementById( 'unzer_apple_pay_v2_place_order' ); + if ( ! UnzerManager.supportsApplePay()) { applePayContainer.style.display = 'none'; } - } - - const applePayV2Container = document.querySelector( '.payment_method_unzer_apple_pay_v2' ); - if (applePayV2Container) { - if (window.ApplePaySession && window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion( 6 )) { - if (placeOrderButton) { - let applePayV2Button = document.getElementById( 'unzer_apple_pay_v2_place_order' ); - if ( ! applePayV2Button) { - applePayV2Button = document.createElement( 'div' ); - applePayV2Button.id = 'unzer_apple_pay_v2_place_order'; - placeOrderButton.parentNode.appendChild( applePayV2Button ); - applePayV2Button.innerHTML = '
'; - } - - if (document.getElementById( 'payment_method_unzer_apple_pay_v2' ).checked) { - applePayV2Button.style.display = ''; - showPlaceOrderButton = false; - } else { - applePayV2Button.style.display = 'none'; - } + if (applePayButton && placeOrderButton) { + if (document.getElementById( 'payment_method_unzer_apple_pay_v2' ).checked && UnzerManager.supportsApplePay()) { + applePayButton.style.display = ''; + showPlaceOrderButton = false; + } else { + applePayButton.style.display = 'none'; } - } else { - applePayV2Container.style.display = 'none'; } } @@ -1082,10 +612,12 @@ jQuery( } } - if (showPlaceOrderButton) { - placeOrderButton.style.display = ''; - } else { - placeOrderButton.style.display = 'none'; + if (placeOrderButton) { + if (showPlaceOrderButton) { + placeOrderButton.style.display = ''; + } else { + placeOrderButton.style.display = 'none'; + } } }, 500 diff --git a/assets/src/payment_methods/unzer_apple_pay_v2.jsx b/assets/src/payment_methods/unzer_apple_pay_v2.jsx new file mode 100644 index 0000000..e64b764 --- /dev/null +++ b/assets/src/payment_methods/unzer_apple_pay_v2.jsx @@ -0,0 +1,37 @@ +import unzerRegisterMethod from "../util/register-method"; +import {getSetting} from '@woocommerce/settings' +import { useEffect, useState } from '@wordpress/element' +import onPaymentSetupFactory from "../util/on-payment-setup-factory"; + +const nameInSnakeCase = 'apple_pay_v2'; +const settings = getSetting('unzer_' + nameInSnakeCase + '_data', {}) +const gatewayTitle = settings.title || nameInSnakeCase; +const gatewayName = settings.id || nameInSnakeCase; +const gatewayDescription = settings?.description || '' +const publicKey = settings?.publicKey || ''; +const locale = settings?.locale || ''; +const paymentComponentId = settings.paymentComponentId || (gatewayName + '-payment-component'); + + +const PaymentContent = ({eventRegistration, emitResponse}) => { + const {onPaymentSetup} = eventRegistration; + useEffect(() => { + const unsubscribe = onPaymentSetup(onPaymentSetupFactory(paymentComponentId, 'unzer-apple-pay-v2-id', emitResponse, settings)); + return unsubscribe + }, [onPaymentSetup]) + + return ( +
+ {gatewayDescription &&

{gatewayDescription}

} + + + +
+ ) +} + +unzerRegisterMethod(gatewayName, gatewayTitle, ); diff --git a/assets/src/payment_methods/unzer_card.jsx b/assets/src/payment_methods/unzer_card.jsx new file mode 100644 index 0000000..11848fe --- /dev/null +++ b/assets/src/payment_methods/unzer_card.jsx @@ -0,0 +1,37 @@ +import unzerRegisterMethod from "../util/register-method"; +import {getSetting} from '@woocommerce/settings' +import { useEffect, useState } from '@wordpress/element' +import onPaymentSetupFactory from "../util/on-payment-setup-factory"; + +const nameInSnakeCase = 'card'; +const settings = getSetting('unzer_' + nameInSnakeCase + '_data', {}) +const gatewayTitle = settings.title || nameInSnakeCase; +const gatewayName = settings.id || nameInSnakeCase; +const gatewayDescription = settings?.description || '' +const publicKey = settings?.publicKey || '' ; +const locale = (settings?.locale || '') + (new Date()).getMilliseconds(); +const paymentComponentId = settings.paymentComponentId || (gatewayName + '-payment-component'); + +const PaymentContent = ({eventRegistration, emitResponse}) => { + const {onPaymentSetup} = eventRegistration; + useEffect(() => { + const unsubscribe = onPaymentSetup(onPaymentSetupFactory(paymentComponentId, 'unzer-card-id', emitResponse, settings)); + return unsubscribe + }, [onPaymentSetup]) + + return ( +
+ {gatewayDescription &&

{gatewayDescription}

} + + + +
+ ) +} + + +unzerRegisterMethod(gatewayName, gatewayTitle, ); diff --git a/assets/src/payment_methods/unzer_direct_debit.jsx b/assets/src/payment_methods/unzer_direct_debit.jsx new file mode 100644 index 0000000..609b2b8 --- /dev/null +++ b/assets/src/payment_methods/unzer_direct_debit.jsx @@ -0,0 +1,37 @@ +import unzerRegisterMethod from "../util/register-method"; +import {getSetting} from '@woocommerce/settings' +import { useEffect, useState } from '@wordpress/element' +import onPaymentSetupFactory from "../util/on-payment-setup-factory"; + +const nameInSnakeCase = 'direct_debit'; +const settings = getSetting('unzer_' + nameInSnakeCase + '_data', {}) +const gatewayTitle = settings.title || nameInSnakeCase; +const gatewayName = settings.id || nameInSnakeCase; +const gatewayDescription = settings?.description || '' +const publicKey = settings?.publicKey || ''; +const locale = settings?.locale || ''; +const paymentComponentId = settings.paymentComponentId || (gatewayName + '-payment-component'); + +const PaymentContent = ({eventRegistration, emitResponse}) => { + const {onPaymentSetup} = eventRegistration; + useEffect(() => { + const unsubscribe = onPaymentSetup(onPaymentSetupFactory(paymentComponentId, 'unzer-direct-debit-id', emitResponse, settings)); + return unsubscribe + }, [onPaymentSetup]) + + return ( +
+ {gatewayDescription &&

{gatewayDescription}

} + + + +
+ ) +} + + +unzerRegisterMethod(gatewayName, gatewayTitle, ); diff --git a/assets/src/payment_methods/unzer_direct_debit_secured.jsx b/assets/src/payment_methods/unzer_direct_debit_secured.jsx new file mode 100644 index 0000000..5160d75 --- /dev/null +++ b/assets/src/payment_methods/unzer_direct_debit_secured.jsx @@ -0,0 +1,36 @@ +import unzerRegisterMethod from "../util/register-method"; +import {getSetting} from '@woocommerce/settings' +import { useEffect, useState } from '@wordpress/element' +import onPaymentSetupFactory from "../util/on-payment-setup-factory"; + +const nameInSnakeCase = 'direct_debit_secured'; +const settings = getSetting('unzer_' + nameInSnakeCase + '_data', {}) +const gatewayTitle = settings.title || nameInSnakeCase; +const gatewayName = settings.id || nameInSnakeCase; +const gatewayDescription = settings?.description || '' +const publicKey = settings?.publicKey || ''; +const locale = settings?.locale || ''; +const paymentComponentId = settings.paymentComponentId || (gatewayName + '-payment-component'); + +const PaymentContent = ({eventRegistration, emitResponse}) => { + const {onPaymentSetup} = eventRegistration; + useEffect(() => { + const unsubscribe = onPaymentSetup(onPaymentSetupFactory(paymentComponentId, 'unzer-direct-debit-secured-id', emitResponse, settings)); + return unsubscribe + }, [onPaymentSetup]) + + return ( +
+ {gatewayDescription &&

{gatewayDescription}

} + + + +
+ ) +} + +unzerRegisterMethod(gatewayName, gatewayTitle, ); diff --git a/assets/src/payment_methods/unzer_google_pay.jsx b/assets/src/payment_methods/unzer_google_pay.jsx new file mode 100644 index 0000000..7857dd4 --- /dev/null +++ b/assets/src/payment_methods/unzer_google_pay.jsx @@ -0,0 +1,36 @@ +import unzerRegisterMethod from "../util/register-method"; +import {getSetting} from '@woocommerce/settings' +import { useEffect, useState } from '@wordpress/element' +import onPaymentSetupFactory from "../util/on-payment-setup-factory"; + +const nameInSnakeCase = 'google_pay'; +const settings = getSetting('unzer_' + nameInSnakeCase + '_data', {}) +const gatewayTitle = settings.title || nameInSnakeCase; +const gatewayName = settings.id || nameInSnakeCase; +const gatewayDescription = settings?.description || '' +const publicKey = settings?.publicKey || ''; +const locale = settings?.locale || ''; +const paymentComponentId = settings.paymentComponentId || (gatewayName + '-payment-component'); + +const PaymentContent = ({eventRegistration, emitResponse}) => { + const {onPaymentSetup} = eventRegistration; + useEffect(() => { + const unsubscribe = onPaymentSetup(onPaymentSetupFactory(paymentComponentId, 'unzer-google-pay-id', emitResponse, settings)); + return unsubscribe + }, [onPaymentSetup]) + + return ( +
+ {gatewayDescription &&

{gatewayDescription}

} + + + +
+ ) +} + +unzerRegisterMethod(gatewayName, gatewayTitle, ); diff --git a/assets/src/payment_methods/unzer_installment.jsx b/assets/src/payment_methods/unzer_installment.jsx new file mode 100644 index 0000000..52b3316 --- /dev/null +++ b/assets/src/payment_methods/unzer_installment.jsx @@ -0,0 +1,36 @@ +import unzerRegisterMethod from "../util/register-method"; +import {getSetting} from '@woocommerce/settings' +import { useEffect, useState } from '@wordpress/element' +import onPaymentSetupFactory from "../util/on-payment-setup-factory"; + +const nameInSnakeCase = 'installment'; +const settings = getSetting('unzer_' + nameInSnakeCase + '_data', {}) +const gatewayTitle = settings.title || nameInSnakeCase; +const gatewayName = settings.id || nameInSnakeCase; +const gatewayDescription = settings?.description || '' +const publicKey = settings?.publicKey || ''; +const locale = settings?.locale || ''; +const paymentComponentId = settings.paymentComponentId || (gatewayName + '-payment-component'); + +const PaymentContent = ({eventRegistration, emitResponse}) => { + const {onPaymentSetup} = eventRegistration; + useEffect(() => { + const unsubscribe = onPaymentSetup(onPaymentSetupFactory(paymentComponentId, 'unzer-installment-id', emitResponse, settings)); + return unsubscribe + }, [onPaymentSetup]) + + return ( +
+ {gatewayDescription &&

{gatewayDescription}

} + + + +
+ ) +} + +unzerRegisterMethod(gatewayName, gatewayTitle, ); diff --git a/assets/src/payment_methods/unzer_invoice.jsx b/assets/src/payment_methods/unzer_invoice.jsx new file mode 100644 index 0000000..3f3cb2a --- /dev/null +++ b/assets/src/payment_methods/unzer_invoice.jsx @@ -0,0 +1,36 @@ +import unzerRegisterMethod from "../util/register-method"; +import {getSetting} from '@woocommerce/settings' +import { useEffect, useState } from '@wordpress/element' +import onPaymentSetupFactory from "../util/on-payment-setup-factory"; + +const nameInSnakeCase = 'invoice'; +const settings = getSetting('unzer_' + nameInSnakeCase + '_data', {}) +const gatewayTitle = settings.title || nameInSnakeCase; +const gatewayName = settings.id || nameInSnakeCase; +const gatewayDescription = settings?.description || '' +const publicKey = settings?.publicKey || ''; +const locale = settings?.locale || ''; +const paymentComponentId = settings.paymentComponentId || (gatewayName + '-payment-component'); + +const PaymentContent = ({eventRegistration, emitResponse}) => { + const {onPaymentSetup} = eventRegistration; + useEffect(() => { + const unsubscribe = onPaymentSetup(onPaymentSetupFactory(paymentComponentId, 'unzer-invoice-id', emitResponse, settings)); + return unsubscribe + }, [onPaymentSetup]) + + return ( +
+ {gatewayDescription &&

{gatewayDescription}

} + + + +
+ ) +} + +unzerRegisterMethod(gatewayName, gatewayTitle, ); diff --git a/assets/src/payment_methods/unzer_open_banking.jsx b/assets/src/payment_methods/unzer_open_banking.jsx new file mode 100644 index 0000000..28e8738 --- /dev/null +++ b/assets/src/payment_methods/unzer_open_banking.jsx @@ -0,0 +1,27 @@ +import unzerRegisterMethod from "../util/register-method"; + +const nameInSnakeCase = 'open_banking'; +const settings = window.wc.wcSettings.getSetting('unzer_' + nameInSnakeCase + '_data', {}) +const gatewayTitle = settings.title || nameInSnakeCase; +const gatewayName = settings.id || nameInSnakeCase; +const gatewayDescription = settings?.description || '' +const publicKey = settings?.publicKey || ''; +const locale = settings?.locale || ''; +const paymentComponentId = settings.paymentComponentId || (gatewayName + '-payment-component'); + +const PaymentContent = () => { + return ( +
+ {gatewayDescription &&

{gatewayDescription}

} + + + +
+ ) +} +unzerRegisterMethod(gatewayName, gatewayTitle, ); + diff --git a/assets/src/unzer_global.jsx b/assets/src/unzer_global.jsx new file mode 100644 index 0000000..08dd815 --- /dev/null +++ b/assets/src/unzer_global.jsx @@ -0,0 +1,135 @@ +import {select, subscribe} from '@wordpress/data'; + +window.unzerCurrentPaymentMethod = ''; +window.unzerCurrentAmount = 0; +const updatePaymentMethodData = function (longNameInSnakeCase, cartData) { + console.info('updatePaymentMethodData for ' + longNameInSnakeCase); + const settings = window.wc.wcSettings.getSetting(longNameInSnakeCase + '_data', {}) + console.log(settings, cartData); + setTimeout(async () => { + const paymentComponent = document.getElementById(settings.paymentComponentId); + if (paymentComponent) { + Promise.all([customElements.whenDefined('unzer-payment')]).then( + () => { + try { + const data = new FormData(); + data.append('data', JSON.stringify(cartData)); + data.append('payment_method', longNameInSnakeCase); + data.append('unzer_nonce', settings.nonce); + fetch(settings.getCustomerDataUrl, { + method: 'POST', + body: data + + }).then((response) => response.json()) + .then((responseData)=>{ + const customerData = responseData.customer; + console.log( + 'set customer data', + customerData + ); + if (customerData) { + paymentComponent.setCustomerData( + customerData + ); + } + + if(responseData.publicKey !== paymentComponent.publicKey) { + paymentComponent.publicKey = responseData.publicKey; + paymentComponent.initOnFirstUpdate(); + } + + if (paymentComponent.setBasketData) { + paymentComponent.setBasketData( + { + amount: cartData.totals.total_price/100, + currencyType: cartData.totals.currency_code, + country: cartData.billingAddress.country + } + ); + const installmentComponent = document.getElementById('unzer-paylater-installment-component'); + if (installmentComponent && installmentComponent.reloadPlansWithRetainedData) { + installmentComponent.updateDataFromStore(); + console.log(installmentComponent.basketDetails); + installmentComponent.onDataReady(); + } + } + + + }); + + } catch (e) { + console.error(e); + } + } + ); + + } + }, 100 + ) + +} +subscribe(() => { + const cartStore = select(window.wc.wcBlocksData.CART_STORE_KEY); + const paymentStore = select(window.wc.wcBlocksData.PAYMENT_STORE_KEY); + const cartData = cartStore.getCartData(); + let hasChanged = false; + if (window.unzerCurrentPaymentMethod !== paymentStore.getActivePaymentMethod()) { +hasChanged = true; + } + + if(!hasChanged && window.unzerCurrentAmount !== cartData.totals.total_price){ + hasChanged = true; + } + if(hasChanged) { + console.log('payment method changed to: ' + paymentStore.getActivePaymentMethod()); + window.unzerCurrentPaymentMethod = paymentStore.getActivePaymentMethod(); + window.unzerCurrentAmount = cartData.totals.total_price; + updatePaymentMethodData(window.unzerCurrentPaymentMethod, cartData); + } +}, 'wc/store/cart'); + + +// +// const paymentMethodUpdateCallbacks = function (shortNameInSnakeCase) { +// const settings = window.wc.wcSettings.getSetting('unzer_' + shortNameInSnakeCase + '_data', {}) +// console.log(shortNameInSnakeCase, settings); +// const {checkoutStore} = window.wc.wcBlocksData; +// console.log('checkoutStore', checkoutStore); +// const paymentComponent = document.getElementById(settings.paymentComponentId); +// if (paymentComponent) { +// console.log('PPPCCCCC', paymentComponent); +// } +// +// +// } +// +// //we actually don't need this any more, but keep it in case a use case pops up +// const unzerIsPaymentMethodAllowed = (shortNameInSnakeCase, arg) => { +// console.log(arg); +// paymentMethodUpdateCallbacks(shortNameInSnakeCase); +// // console.log(shortNameInSnakeCase); +// // console.trace(); +// // const settings = window.wc.wcSettings.getSetting('unzer_' + shortNameInSnakeCase + '_data', {}) +// // const currency = arg.cart.cartTotals.currency_code; +// // const country = arg.billingAddress.country; +// // if(settings.allowedCountries){ +// // if(!settings.allowedCountries.includes(country)){ +// // return false; +// // } +// // } +// // if(settings.allowedCurrencies){ +// // if(!settings.allowedCurrencies.includes(currency)){ +// // return false; +// // } +// // } +// return true; +// }; +// +// const callbackCollection = {}; +// for (const simpleMethod of simpleMethods) { +// callbackCollection['unzer_' + simpleMethod] = (arg) => { +// return unzerIsPaymentMethodAllowed(simpleMethod, arg); +// } +// } +// console.log(callbackCollection); +// registerPaymentMethodExtensionCallbacks('unzer-payments', callbackCollection); \ No newline at end of file diff --git a/assets/src/unzer_simple.jsx b/assets/src/unzer_simple.jsx new file mode 100644 index 0000000..0f71a69 --- /dev/null +++ b/assets/src/unzer_simple.jsx @@ -0,0 +1,6 @@ +import unzerRegisterSimpleMethod from './util/register-simple-method'; +import simpleMethods from './util/simple-methods'; + +for(const simpleMethod of simpleMethods) { + unzerRegisterSimpleMethod(simpleMethod); +} \ No newline at end of file diff --git a/assets/src/util/on-payment-setup-factory.jsx b/assets/src/util/on-payment-setup-factory.jsx new file mode 100644 index 0000000..970d8cc --- /dev/null +++ b/assets/src/util/on-payment-setup-factory.jsx @@ -0,0 +1,49 @@ +export default function onPaymentSetupFactory(paymentComponentId, paymentTypeIdFieldName, emitResponse, settings) { + + return async () => { + try { + const unzerPaymentComponent = document.getElementById(paymentComponentId) + if(!unzerPaymentComponent) { + console.error('unzer payment component does not exist: ' + paymentComponentId); + } + const response = await unzerPaymentComponent.submit(); + if (response.submitResponse) { + if (response.submitResponse.success === true) { + const paymentMethodData = {}; + paymentMethodData['unzer_nonce'] = settings.nonce; + paymentMethodData[paymentTypeIdFieldName] = response.submitResponse.data.id; + + const returnValue = { + type: emitResponse?.responseTypes?.SUCCESS, + meta: { + paymentMethodData + } + }; + console.log( + 'submit response: ', + response.submitResponse, + returnValue + ); + + return returnValue; + } else { + return { + type: emitResponse?.responseTypes?.ERROR, + message: 'GENERAL ERROR 1' + } + } + } else { + return { + type: emitResponse?.responseTypes?.ERROR, + message: 'GENERAL ERROR 2' + } + } + } catch (err) { + return { + type: emitResponse?.responseTypes?.ERROR, + message: 'GENERAL ERROR 3' + } + } + + } +} \ No newline at end of file diff --git a/assets/src/util/register-method.jsx b/assets/src/util/register-method.jsx new file mode 100644 index 0000000..67c4a7a --- /dev/null +++ b/assets/src/util/register-method.jsx @@ -0,0 +1,23 @@ +import {decodeEntities} from "@wordpress/html-entities"; +import { registerPaymentMethod } from '@woocommerce/blocks-registry' + +export default function unzerRegisterMethod(gatewayName, gatewayTitle, component) { + registerPaymentMethod({ + name: gatewayName, + label: ( +
+ + {gatewayTitle} + +
+ ), + content: component, + edit: component, + canMakePayment: () => true, + ariaLabel: decodeEntities(gatewayTitle), + supports: { + features: ['products'], + } + }) +} + diff --git a/assets/src/util/register-simple-method.jsx b/assets/src/util/register-simple-method.jsx new file mode 100644 index 0000000..a5881c6 --- /dev/null +++ b/assets/src/util/register-simple-method.jsx @@ -0,0 +1,18 @@ +import unzerRegisterMethod from "./register-method"; +import { getSetting } from '@woocommerce/settings' + +export default function unzerRegisterSimpleMethod(nameInSnakeCase) { + const settings = getSetting('unzer_' + nameInSnakeCase + '_data', {}) + const gatewayTitle = settings.title || nameInSnakeCase; + const gatewayName = settings.id || nameInSnakeCase; + const gatewayDescription = settings?.description || '' + + const PaymentContent = () => { + return ( +
+ {gatewayDescription &&

{gatewayDescription}

} +
+ ) + } + unzerRegisterMethod(gatewayName, gatewayTitle, ); +} diff --git a/assets/src/util/simple-methods.jsx b/assets/src/util/simple-methods.jsx new file mode 100644 index 0000000..d8683b9 --- /dev/null +++ b/assets/src/util/simple-methods.jsx @@ -0,0 +1,14 @@ +export default [ + 'alipay', + 'bancontact', + 'eps', + 'ideal', + 'klarna', + 'postfinance_card', + 'postfinance_efinance', + 'prepayment', + 'przelewy24', + 'twint', + 'wechatpay', + 'wero', +]; \ No newline at end of file diff --git a/composer.json b/composer.json index 7f94826..dd12526 100755 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "require": { "unzerdev/php-sdk": "^3.11.0", - "php": ">=7.1" + "php": ">=7.4" } } diff --git a/composer.lock b/composer.lock index a316c6f..f7260a8 100755 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3998a02ec0d3b5f4ebeba79ca1fd845d", + "content-hash": "5094b2717872fd63393770f20e2ba3c1", "packages": [ { "name": "unzerdev/php-sdk", - "version": "3.11.0", + "version": "3.13.1", "source": { "type": "git", "url": "https://github.com/unzerdev/php-sdk.git", - "reference": "274650b6120b8665c8867627210cd8adab65406b" + "reference": "0a26d70b33185d52e49b06cb500a6e01bb6f1087" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/unzerdev/php-sdk/zipball/274650b6120b8665c8867627210cd8adab65406b", - "reference": "274650b6120b8665c8867627210cd8adab65406b", + "url": "https://api.github.com/repos/unzerdev/php-sdk/zipball/0a26d70b33185d52e49b06cb500a6e01bb6f1087", + "reference": "0a26d70b33185d52e49b06cb500a6e01bb6f1087", "shasum": "" }, "require": { @@ -45,20 +45,20 @@ "description": "This is the php sdk to connect to the Unzer rest API.", "support": { "email": "support@unzer.com", - "source": "https://github.com/unzerdev/php-sdk/tree/3.11.0" + "source": "https://github.com/unzerdev/php-sdk/tree/3.13.1" }, - "time": "2024-12-04T08:14:47+00:00" + "time": "2025-09-23T14:21:50+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=7.1" }, - "platform-dev": [], + "platform-dev": {}, "plugin-api-version": "2.6.0" } diff --git a/html/admin/apple-pay-settings.php b/html/admin/apple-pay-settings.php deleted file mode 100644 index 536c5ae..0000000 --- a/html/admin/apple-pay-settings.php +++ /dev/null @@ -1,107 +0,0 @@ -api_request_url( AdminController::APPLE_PAY_REMOVE_KEY_ROUTE_SLUG ); -$validationUrl = WC()->api_request_url( AdminController::APPLE_PAY_VALIDATE_CREDENTIALS_ROUTE_SLUG ); - -wp_enqueue_style( 'unzer_admin_css', UNZER_PLUGIN_URL . '/assets/css/admin.css', array(), UNZER_VERSION ); -wp_enqueue_script( 'unzer_admin_apple_pay_js', UNZER_PLUGIN_URL . '/assets/js/admin_apple_pay.js', array(), UNZER_VERSION, array( 'in_footer' => false ) ); -wp_localize_script( - 'unzer_admin_apple_pay_js', - 'unzerApplePay', - array( - 'validationUrl' => $validationUrl, - ) -); - - -?> -
- - - - - - - - - - - - - - - - - - - - -
- - -
- -
-
- -
- ' . esc_html( get_option( 'unzer_apple_pay_payment_certificate_id' ) ) . ''; - echo ''; - } - ?> -
- - - -
- -
- ' . esc_html( get_option( 'unzer_apple_pay_payment_key_id' ) ) . ''; - echo ''; - } - ?> -
- - -
- -
-
- -
- ' . esc_html( substr( get_option( 'unzer_apple_pay_merchant_id_certificate' ), 0, 50 ) ) . '...'; - echo ''; - } - ?> -
- - -
- -
-
- -
- ' . esc_html( substr( get_option( 'unzer_apple_pay_merchant_id_key' ), 0, 50 ) ) . '...'; - echo ''; - } - ?> -
diff --git a/html/admin/transactions.php b/html/admin/transactions.php index 0ec15f6..54a822e 100755 --- a/html/admin/transactions.php +++ b/html/admin/transactions.php @@ -16,10 +16,13 @@ return; } $paymentShortId = $order->get_meta( Main::ORDER_META_KEY_PAYMENT_SHORT_ID, true ); - +wp_enqueue_style( 'unzer_admin_order_view_css', UNZER_PLUGIN_URL . '/assets/css/admin-order-view.css', array(), UNZER_VERSION ); ?> -
+
+ + +
get_meta( \UnzerPayments\Main::ORDER_META_KEY_PAYMENT_INSTRUCTIONS, true ); @@ -31,21 +34,16 @@ $paymentInstructions = str_replace( '#!trpst#/trp-gettext#!trpen#', '', $paymentInstructions ); } ?> -

-
+
-

-
- - - -
-

- - +
+
+ +
+ @@ -54,17 +52,13 @@ - - - +
-
- - +
+ + - +

 
api_request_url( AdminController::GET_ORDER_TRANSACTIONS_ROUTE_SLUG ); @@ -86,10 +80,9 @@ function unzerRefreshData() { if (data.transactions) { let tHtml = ''; for (const transaction of data.transactions) { - let color = transaction.status === 'error' ? '#cc0000' : '#000000'; - color = transaction.status === 'pending' ? '#bbb' : color; + const rowClass = transaction.status === 'error' ? 'unzer-row-error' : (transaction.status === 'pending' ? 'unzer-row-pending' : 'unzer-row-success'); tHtml += ` - + ${transaction.time} ${transaction.type} ${transaction.id} @@ -101,24 +94,25 @@ function unzerRefreshData() { document.getElementById('unzer-transactions-body').innerHTML = tHtml; } - document.getElementById('unzer-status-message').innerHTML = data.status === 'chargeback' ? '
CHARGEBACK!
' : ''; - - let captureAction = ''; - if (data.remainingPlain && data.paymentMethod !== 'unzer_prepayment') { - captureAction = '
' + - '' + const orderStatusMessageContainer = document.getElementById('unzer-status-message'); + orderStatusMessageContainer.innerHTML = ''+data.status+''; + orderStatusMessageContainer.className = "unzer-status-"+data.status; - } - let amountHtml = ` - : ${data.amount} - : ${data.charged} - : ${data.cancelled} - : ${data.remaining} - ${captureAction} - `; + const totalsHtml = ` + : ${data.amount} + : ${data.charged} + : ${data.cancelled} + : ${data.remaining} + `; + document.getElementById('unzer-totals-row').innerHTML = totalsHtml; - document.getElementById('unzer-sums-body').innerHTML = amountHtml; + let captureHtml = ''; + if (data.remainingPlain && data.paymentMethod !== 'unzer_prepayment' && data.status !== 'canceled') { + captureHtml = ` + `; + } + document.getElementById('unzer-capture-row').innerHTML = captureHtml; if (data.raw) { document.getElementById('unzer-debug').innerHTML = data.raw; } @@ -132,6 +126,10 @@ function unzerRefreshData() { unzerRefreshData(); function unzerCaptureOrder(orderId, amount, nonce) { + const btn = document.getElementById('unzer-capture-btn'); + if (btn) { + btn.classList.add('is-loading'); + } const formData = new FormData(); formData.append('order_id', orderId); formData.append('amount', amount); @@ -143,13 +141,14 @@ function unzerCaptureOrder(orderId, amount, nonce) { .then(data => { if (data.error) { alert(data.error); + if (btn) { + btn.classList.remove('is-loading'); + } } unzerRefreshData(); - }) - + }); } true ) ); -wp_add_inline_script( 'unzer_admin_webhook_management_js', $script ); - +wp_add_inline_script( 'unzer_admin_webhook_management_js', $script ); \ No newline at end of file diff --git a/includes/Main.php b/includes/Main.php index 359d896..a2a6d3d 100755 --- a/includes/Main.php +++ b/includes/Main.php @@ -2,42 +2,41 @@ namespace UnzerPayments; +use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; use UnzerPayments\Controllers\AccountController; use UnzerPayments\Controllers\AdminController; use UnzerPayments\Controllers\CheckoutController; use UnzerPayments\Controllers\WebhookController; use UnzerPayments\Gateways\AbstractGateway; use UnzerPayments\Gateways\Alipay; -use UnzerPayments\Gateways\ApplePay; -use UnzerPayments\gateways\ApplePayV2; +use UnzerPayments\Gateways\ApplePayV2; use UnzerPayments\Gateways\Bancontact; use UnzerPayments\Gateways\Card; use UnzerPayments\Gateways\DirectDebit; use UnzerPayments\Gateways\DirectDebitSecured; use UnzerPayments\Gateways\Eps; -use UnzerPayments\gateways\GooglePay; +use UnzerPayments\Gateways\GooglePay; use UnzerPayments\Gateways\Ideal; use UnzerPayments\Gateways\Installment; use UnzerPayments\Gateways\Invoice; -use UnzerPayments\gateways\OpenBanking; +use UnzerPayments\Gateways\Klarna; +use UnzerPayments\Gateways\OpenBanking; use UnzerPayments\Gateways\Paypal; use UnzerPayments\Gateways\PostFinanceCard; use UnzerPayments\Gateways\PostFinanceEfinance; use UnzerPayments\Gateways\Prepayment; use UnzerPayments\Gateways\Przelewy24; -use UnzerPayments\Gateways\Sofort; -use UnzerPayments\gateways\Twint; +use UnzerPayments\Gateways\Twint; use UnzerPayments\Gateways\WeChatPay; -use UnzerPayments\SdkExtension\Resource\ApplePayCertificate; -use UnzerPayments\SdkExtension\Resource\ApplePayPrivateKey; -use UnzerPayments\SdkExtension\Services\AppleKeyService; +use UnzerPayments\Gateways\Wero; use UnzerPayments\Services\DashboardService; use UnzerPayments\Services\OrderService; -use UnzerPayments\Services\PaymentService; +use WC_Payment_Gateway; class Main { + public static $instance; const ORDER_META_KEY_AUTHORIZATION_ID = 'unzer_authorization_id'; const ORDER_META_KEY_CHARGE_ID = 'unzer_charge_id'; @@ -54,7 +53,6 @@ class Main { self::ORDER_META_KEY_PAYMENT_SHORT_ID, self::ORDER_META_KEY_PAYMENT_INSTRUCTIONS, self::ORDER_META_KEY_CANCELLATION_ID, - self::ORDER_META_KEY_DATE_OF_BIRTH, ); const USER_META_KEY_PAYMENT_INSTRUMENTS = 'payment_instruments'; @@ -82,13 +80,11 @@ public function registerEvents(): void { add_action( 'woocommerce_api_' . AdminController::WEBHOOK_MANAGEMENT_ROUTE_SLUG, array( new AdminController(), 'webhookManagement' ) ); add_action( 'woocommerce_api_' . AdminController::KEY_VALIDATION_ROUTE_SLUG, array( new AdminController(), 'validateKeypair' ) ); add_action( 'woocommerce_api_' . AdminController::NOTIFICATION_SLUG, array( new AdminController(), 'handleNotification' ) ); - add_action( 'woocommerce_api_' . AdminController::APPLE_PAY_REMOVE_KEY_ROUTE_SLUG, array( new AdminController(), 'applePayRemoveKey' ) ); - add_action( 'woocommerce_api_' . AdminController::APPLE_PAY_VALIDATE_CREDENTIALS_ROUTE_SLUG, array( new AdminController(), 'applePayValidateCredentials' ) ); add_action( 'woocommerce_api_' . AbstractGateway::CONFIRMATION_ROUTE_SLUG, array( new CheckoutController(), 'confirm' ) ); add_action( 'woocommerce_api_' . WebhookController::WEBHOOK_ROUTE_SLUG, array( new WebhookController(), 'receiveWebhook' ) ); add_action( 'woocommerce_api_' . AccountController::DELETE_PAYMENT_INSTRUMENT_URL_SLUG, array( new AccountController(), 'deletePaymentInstrument' ) ); - add_action( 'woocommerce_api_' . CheckoutController::APPLE_PAY_MERCHANT_VALIDATION_ROUTE_SLUG, array( new CheckoutController(), 'validateApplePayMerchant' ) ); + add_action( 'woocommerce_api_' . CheckoutController::GET_UNZER_CUSTOMER_SLUG, array( new CheckoutController(), 'getUnzerCustomerData' ) ); add_filter( 'plugin_action_links_' . plugin_basename( UNZER_PLUGIN_PATH . 'unzer-payments.php' ), array( $this, 'addPluginSettingsLink' ) ); add_action( 'add_meta_boxes', array( $this, 'addMetaBoxes' ), 40 ); add_action( 'woocommerce_settings_checkout', array( AdminController::class, 'renderGlobalSettingsStart' ) ); @@ -100,10 +96,11 @@ public function registerEvents(): void { add_action( 'woocommerce_update_options_payment_gateways_unzer_card', array( $this, 'savePaymentMethodSettingsCard' ) ); add_action( 'woocommerce_update_options_payment_gateways_unzer_paypal', array( $this, 'savePaymentMethodSettingsPaypal' ) ); add_action( 'woocommerce_update_options_payment_gateways_unzer_direct_debit', array( $this, 'savePaymentMethodSettingsDirectDebit' ) ); - add_action( 'woocommerce_update_options_payment_gateways_unzer_apple_pay', array( $this, 'savePaymentMethodSettingsApplePay' ) ); add_action( 'woocommerce_update_options_payment_gateways_unzer_apple_pay_v2', array( $this, 'savePaymentMethodSettingsApplePayV2' ) ); add_action( 'woocommerce_update_options_checkout_unzer_general', array( $this, 'saveGeneralSettings' ) ); add_action( 'admin_notices', array( new DashboardService(), 'showNotifications' ) ); + // add_action( 'woocommerce_blocks_loaded', array( $this, 'addCheckoutBlocks' ) ); + add_action( 'before_woocommerce_pay_form', array( $this, 'orderPayPaymentMethod' ), 20, 4 ); add_action( 'admin_enqueue_scripts', function () { @@ -245,48 +242,6 @@ public function savePaymentMethodSettingsApplePayV2(): void { ( new DashboardService() )->addError( 'apple_pay_id_file' ); } } - public function savePaymentMethodSettingsApplePay(): void { - if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'woocommerce-settings' ) ) { - return; - } - if ( ! empty( $_FILES['unzer_apple_pay_payment_processing_certificate']['tmp_name'] ) && ! empty( $_FILES['unzer_apple_pay_payment_processing_key']['tmp_name'] ) ) { - $client = ( new PaymentService() )->getUnzerManager(); - $certificate = file_get_contents( sanitize_url( $_FILES['unzer_apple_pay_payment_processing_certificate']['tmp_name'] ) ); - $key = file_get_contents( sanitize_url( $_FILES['unzer_apple_pay_payment_processing_key']['tmp_name'] ) ); - - if ( extension_loaded( 'openssl' ) && ! openssl_x509_parse( $certificate ) ) { - throw new \Exception( 'Invalid Payment Processing certificate given' ); - } - - $privateKeyResource = new ApplePayPrivateKey(); - $privateKeyResource->setCertificate( $key ); - $client->getResourceService()->createResource( $privateKeyResource->setParentResource( $client ) ); - /** @var string $privateKeyId */ - $privateKeyId = $privateKeyResource->getId(); - update_option( 'unzer_apple_pay_payment_key_id', $privateKeyId ); - $certificateResource = new ApplePayCertificate(); - $certificateResource->setCertificate( $certificate ); - $certificateResource->setPrivateKey( $privateKeyId ); - $client->getResourceService()->createResource( $certificateResource->setParentResource( $client ) ); - - $certificateService = new AppleKeyService( $client ); - $activateSuccess = $certificateService->activateCertificate( $certificateResource->getId() ); - if ( ! $activateSuccess ) { - throw new \Exception( 'Could not activate Apple Pay certificate' ); - } - update_option( 'unzer_apple_pay_payment_certificate_id', $certificateResource->getId() ); - } - - if ( ! empty( $_FILES['unzer_apple_pay_merchant_id_certificate']['tmp_name'] ) ) { - $certificate = file_get_contents( sanitize_url( $_FILES['unzer_apple_pay_merchant_id_certificate']['tmp_name'] ) ); - update_option( 'unzer_apple_pay_merchant_id_certificate', $certificate ); - } - - if ( ! empty( $_FILES['unzer_apple_pay_merchant_id_key']['tmp_name'] ) ) { - $certificate = file_get_contents( sanitize_url( $_FILES['unzer_apple_pay_merchant_id_key']['tmp_name'] ) ); - update_option( 'unzer_apple_pay_merchant_id_key', $certificate ); - } - } public function setMetaProtected( $protected, $meta_key, $meta_type ) { if ( in_array( $meta_key, self::ORDER_META_KEYS ) ) { @@ -397,10 +352,7 @@ public function getPaymentGateways(): array { WeChatPay::GATEWAY_ID => WeChatPay::class, Alipay::GATEWAY_ID => Alipay::class, Eps::GATEWAY_ID => Eps::class, - // Giropay::GATEWAY_ID => Giropay::class, - Sofort::GATEWAY_ID => Sofort::class, - // Klarna::GATEWAY_ID => Klarna::class, - // Pis::GATEWAY_ID => Pis::class, + Klarna::GATEWAY_ID => Klarna::class, DirectDebit::GATEWAY_ID => DirectDebit::class, DirectDebitSecured::GATEWAY_ID => DirectDebitSecured::class, Invoice::GATEWAY_ID => Invoice::class, @@ -409,11 +361,11 @@ public function getPaymentGateways(): array { Ideal::GATEWAY_ID => Ideal::class, PostFinanceEfinance::GATEWAY_ID => PostFinanceEfinance::class, PostFinanceCard::GATEWAY_ID => PostFinanceCard::class, - ApplePay::GATEWAY_ID => ApplePay::class, ApplePayV2::GATEWAY_ID => ApplePayV2::class, GooglePay::GATEWAY_ID => GooglePay::class, Twint::GATEWAY_ID => Twint::class, OpenBanking::GATEWAY_ID => OpenBanking::class, + Wero::GATEWAY_ID => Wero::class, ); } @@ -424,4 +376,39 @@ public function getPaymentGateway( $key ): ?AbstractGateway { } return null; } + + public function addCheckoutBlocks() { + if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) { + add_action( + 'woocommerce_blocks_payment_method_type_registration', + function ( PaymentMethodRegistry $payment_method_registry ) { + foreach ( $this->getPaymentGateways() as $gatewayClass ) { + if ( defined( $gatewayClass . '::BLOCK_CLASS' ) ) { + $blockClass = constant( $gatewayClass . '::BLOCK_CLASS' ); + if ( class_exists( $blockClass ) ) { + $payment_method_registry->register( new $blockClass() ); + } + } + } + } + ); + } + } + + public function orderPayPaymentMethod( $order, $order_button_text, $available_gateways ) { + $paymentMethod = (string) $order->get_payment_method(); + if ( AbstractGateway::isUnzerPaymentMethod( $paymentMethod ) ) { + $isSelectedGatewayActive = false; + /** @var WC_Payment_Gateway $gateway */ + foreach ( $available_gateways as $gateway ) { + if ( $gateway->id === $paymentMethod ) { + $isSelectedGatewayActive = true; + break; + } + } + foreach ( $available_gateways as $gateway ) { + $gateway->chosen = ( $gateway->id === $paymentMethod ); + } + } + } } diff --git a/includes/Util.php b/includes/Util.php index 56af8a8..29a7c0a 100644 --- a/includes/Util.php +++ b/includes/Util.php @@ -51,15 +51,7 @@ public static function getNonceField( $doPrint = true, string $action = '' ) { } } - public static function getDobFromPost(): ?string { - return self::getNonceCheckedPostValue( 'unzer-dob' ); - } - - public static function getCompanyTypeFromPost(): ?string { - return self::getNonceCheckedPostValue( 'unzer-invoice-company-type' ); - } - - public static function getNonceCheckedPostValue( string $key ): ?string { + public static function getNonceCheckedPostValue( string $key, $skipSanitize = false ): ?string { if ( ! empty( $_POST[ $key ] ) ) { // our own nonce: if ( isset( $_POST[ self::NONCE_NAME ] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ self::NONCE_NAME ] ) ), self::NONCE_NAME ) ) { @@ -67,12 +59,24 @@ public static function getNonceCheckedPostValue( string $key ): ?string { } // woocommerce nonce: if ( isset( $_POST['security'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['security'] ) ), 'update-order-review' ) ) { - return sanitize_text_field( wp_unslash( $_POST[ $key ] ) ); + $value = wp_unslash( $_POST[ $key ] ); + return $skipSanitize ? $value : sanitize_text_field( $value ); } } return null; } + public static function getNonceCheckedBillingData(): array { + $postData = self::getNonceCheckedPostValue( 'post_data', true ); + if ( ! empty( $postData ) ) { + parse_str( $postData, $params ); + $params = array_map( 'sanitize_text_field', $params ); + return $params; + } + return array(); + } + + public static function escape_array_html( $data ) { if ( is_array( $data ) ) { foreach ( $data as $key => $value ) { diff --git a/includes/controllers/AccountController.php b/includes/controllers/AccountController.php old mode 100755 new mode 100644 index 91878f6..4e50701 --- a/includes/controllers/AccountController.php +++ b/includes/controllers/AccountController.php @@ -33,12 +33,15 @@ public function deletePaymentInstrument() { } public function accountPaymentInstruments() { - $gateways = array( + $gateways = array( Card::class, Paypal::class, DirectDebit::class, ); - $html = ''; + $html = ''; + $deleteUrl = WC()->api_request_url( self::DELETE_PAYMENT_INSTRUMENT_URL_SLUG ); + $nonce = Util::getNonce(); + foreach ( $gateways as $gateway ) { /** @var Card|Paypal|DirectDebit $gatewayObject */ $gatewayObject = new $gateway(); @@ -46,23 +49,31 @@ public function accountPaymentInstruments() { if ( $savedInstruments && $gatewayObject->isSaveInstruments() ) { $html .= '
' . $gatewayObject->get_title() . '
'; } } if ( $html ) { - $html = '

' . __( 'Your saved payment means', 'unzer-payments' ) . '

' . $html; + wp_enqueue_script( 'unzer_account_js', UNZER_PLUGIN_URL . '/assets/js/account.js', array(), UNZER_VERSION, array( 'in_footer' => true ) ); + $html = '

' . esc_html__( 'Your saved payment means', 'unzer-payments' ) . '

' . $html; } - echo wp_kses_post( $html ); + echo wp_kses( + $html, + array( + 'h2' => array(), + 'div' => array( 'class' => array() ), + 'b' => array(), + 'ul' => array(), + 'li' => array(), + 'a' => array( + 'href' => array(), + 'class' => array(), + 'data-instrument-id' => array(), + 'data-delete-url' => array(), + 'data-nonce' => array(), + ), + ) + ); } } diff --git a/includes/controllers/AdminController.php b/includes/controllers/AdminController.php old mode 100755 new mode 100644 index fc3a578..ca5e850 --- a/includes/controllers/AdminController.php +++ b/includes/controllers/AdminController.php @@ -3,13 +3,10 @@ namespace UnzerPayments\Controllers; use Exception; -use UnzerPayments\Gateways\ApplePay; use UnzerPayments\Gateways\DirectDebitSecured; use UnzerPayments\Gateways\Installment; use UnzerPayments\Gateways\Invoice; use UnzerPayments\Main; -use UnzerPayments\SdkExtension\Resource\ApplePayCertificate; -use UnzerPayments\SdkExtension\Resource\ApplePayPrivateKey; use UnzerPayments\Services\DashboardService; use UnzerPayments\Services\PaymentService; use UnzerPayments\Services\WebhookManagementService; @@ -23,13 +20,12 @@ class AdminController { - const GET_ORDER_TRANSACTIONS_ROUTE_SLUG = 'admin_unzer_get_order_transactions'; - const CHARGE_ROUTE_SLUG = 'admin_unzer_charge'; - const WEBHOOK_MANAGEMENT_ROUTE_SLUG = 'admin_unzer_webhooks'; - const KEY_VALIDATION_ROUTE_SLUG = 'admin_unzer_key_validation'; - const NOTIFICATION_SLUG = 'admin_unzer_notification'; - const APPLE_PAY_REMOVE_KEY_ROUTE_SLUG = 'admin_unzer_apple_pay_remove_key'; - const APPLE_PAY_VALIDATE_CREDENTIALS_ROUTE_SLUG = 'admin_unzer_apple_pay_validate_credentials'; + + const GET_ORDER_TRANSACTIONS_ROUTE_SLUG = 'admin_unzer_get_order_transactions'; + const CHARGE_ROUTE_SLUG = 'admin_unzer_charge'; + const WEBHOOK_MANAGEMENT_ROUTE_SLUG = 'admin_unzer_webhooks'; + const KEY_VALIDATION_ROUTE_SLUG = 'admin_unzer_key_validation'; + const NOTIFICATION_SLUG = 'admin_unzer_notification'; public function getOrderTransactions() { try { @@ -241,126 +237,6 @@ public function validateKeypair() { } } - public function applePayValidateCredentials() { - $paymentGateway = new ApplePay(); - $status = array( - 'unzer_apple_pay_payment_certificate_id' => 0, - 'unzer_apple_pay_payment_key_id' => 0, - 'unzer_apple_pay_merchant_id_certificate' => 0, - 'unzer_apple_pay_merchant_id_key' => 0, - ); - $messages = array( - 'unzer_apple_pay_payment_certificate_id' => __( 'invalid', 'unzer-payments' ), - 'unzer_apple_pay_payment_key_id' => __( 'invalid', 'unzer-payments' ), - 'unzer_apple_pay_merchant_id_certificate' => __( 'invalid', 'unzer-payments' ), - 'unzer_apple_pay_merchant_id_key' => __( 'invalid', 'unzer-payments' ), - ); - - $client = ( new PaymentService() )->getUnzerManager(); - - if ( get_option( 'unzer_apple_pay_payment_certificate_id' ) ) { - try { - $certificateResource = new ApplePayCertificate(); - $certificateResource->setId( get_option( 'unzer_apple_pay_payment_certificate_id' ) ); - $certificateResource->setParentResource( $client ); - $submittedCertificate = $client->getResourceService()->fetchResource( $certificateResource ); - if ( $submittedCertificate->getId() ) { - if ( $submittedCertificate->getActive() === false ) { - throw new Exception( __( 'The certificate is not active', 'unzer-payments' ) ); - } - $status['unzer_apple_pay_payment_certificate_id'] = 1; - $messages['unzer_apple_pay_payment_certificate_id'] = __( 'valid', 'unzer-payments' ); - } - } catch ( Exception $e ) { - $messages['unzer_apple_pay_payment_certificate_id'] = $e->getMessage(); - } - } - // - // if ( get_option( 'unzer_apple_pay_payment_key_id' ) ) { - // try { - // $keyResource = new ApplePayPrivateKey(); - // $keyResource->setId( get_option( 'unzer_apple_pay_payment_key_id' ) ); - // $keyResource->setParentResource( $client ); - // $submittedKey = $client->getResourceService()->fetchResource( $keyResource ); - // - // if ( $submittedKey->getId() ) { - // if ( ! empty( $submittedCertificate ) && $submittedKey->getParentResource()->getKey() !== $submittedCertificate->getParentResource()->getKey() ) { - // throw new Exception( __( 'The certificate and the key do not match', 'unzer-payments' ) ); - // } - // $status['unzer_apple_pay_payment_key_id'] = 1; - // $messages['unzer_apple_pay_payment_key_id'] = __( 'valid', 'unzer-payments' ); - // } - // } catch ( Exception $e ) { - // $messages['unzer_apple_pay_payment_key_id'] = $e->getMessage(); - // } - // } - - if ( get_option( 'unzer_apple_pay_merchant_id_certificate' ) ) { - try { - $certificate = get_option( 'unzer_apple_pay_merchant_id_certificate' ); - if ( extension_loaded( 'openssl' ) ) { - $certificateData = openssl_x509_parse( $certificate ); - if ( ! is_array( $certificateData ) ) { - throw new Exception( __( 'Unable to read certificate', 'unzer-payments' ) ); - } - if ( $certificateData['subject']['UID'] !== $paymentGateway->get_option( 'merchant_id' ) ) { - throw new Exception( __( 'Certificate does not match merchant id: ', 'unzer-payments' ) . $certificateData['subject']['UID'] ); - } - } elseif ( ! str_starts_with( $certificate, '-----BEGIN CERTIFICATE-----' ) ) { - throw new Exception( __( 'Not a valid certificate', 'unzer-payments' ) ); - } - $status['unzer_apple_pay_merchant_id_certificate'] = 1; - $messages['unzer_apple_pay_merchant_id_certificate'] = __( 'valid', 'unzer-payments' ); - } catch ( Exception $e ) { - $messages['unzer_apple_pay_merchant_id_certificate'] = $e->getMessage(); - } - } - - if ( get_option( 'unzer_apple_pay_merchant_id_key' ) ) { - try { - $key = get_option( 'unzer_apple_pay_merchant_id_key' ); - if ( extension_loaded( 'openssl' ) ) { - $keyIsValid = openssl_x509_check_private_key( $certificate, $key ); - if ( ! $keyIsValid ) { - throw new Exception( __( 'Key does not match certificate', 'unzer-payments' ) ); - } - } elseif ( ! str_starts_with( $certificate, '-----BEGIN PRIVATE KEY-----' ) ) { - throw new Exception( __( 'Not a valid private key', 'unzer-payments' ) ); - } - $status['unzer_apple_pay_merchant_id_key'] = 1; - $messages['unzer_apple_pay_merchant_id_key'] = __( 'valid', 'unzer-payments' ); - } catch ( Exception $e ) { - $messages['unzer_apple_pay_merchant_id_key'] = $e->getMessage(); - } - } - $this->renderJson( - array( - 'status' => $status, - 'messages' => $messages, - ) - ); - } - - public function applePayRemoveKey() { - $key = Util::getNonceCheckedPostValue( 'key' ); - if ( ! empty( $key ) ) { - $key = 'unzer_apple_pay_' . $key; - if ( get_option( $key ) ) { - delete_option( $key ); - $this->renderJson( - array( - 'success' => 1, - ) - ); - } - } - $this->renderJson( - array( - 'success' => 0, - ) - ); - } - public static function renderTransactionTable( $postOrOrderObject ) { $order = ( $postOrOrderObject instanceof WP_Post ) ? wc_get_order( $postOrOrderObject->ID ) : $postOrOrderObject; if ( ! $order || ! ( $order instanceof \WC_Order ) ) { diff --git a/includes/controllers/CheckoutController.php b/includes/controllers/CheckoutController.php old mode 100755 new mode 100644 index 0fa0382..61b8240 --- a/includes/controllers/CheckoutController.php +++ b/includes/controllers/CheckoutController.php @@ -3,22 +3,19 @@ namespace UnzerPayments\Controllers; use Exception; -use UnzerPayments\Gateways\ApplePay; -use UnzerPayments\Gateways\Prepayment; +use UnzerPayments\Gateways\AbstractGateway; use UnzerPayments\Main; +use UnzerPayments\Services\CustomerService; use UnzerPayments\Services\LogService; use UnzerPayments\Services\OrderService; use UnzerPayments\Services\PaymentService; use UnzerPayments\Util; -use UnzerSDK\Adapter\ApplepayAdapter; use UnzerSDK\Constants\PaymentState; -use UnzerSDK\Resources\ExternalResources\ApplepaySession; use WC_Order; class CheckoutController { - - const APPLE_PAY_MERCHANT_VALIDATION_ROUTE_SLUG = 'unzer_apple_pay_merchant_validation'; + const GET_UNZER_CUSTOMER_SLUG = 'get-unzer-customer'; public function confirm() { $logger = ( new LogService() ); @@ -29,6 +26,14 @@ public function confirm() { $orderId = (int) WC()->session->get( 'unzer_confirm_order_id' ); WC()->session->set( 'unzer_confirm_order_id', null ); } + if ( empty( $orderId ) ) { + $logger->debug( 'order id from store_api_draft_order' ); + $orderId = (int) WC()->session->get( 'store_api_draft_order' ); + } + if ( empty( $orderId ) ) { + $logger->debug( 'order id from get query' ); + $orderId = (int) ( $_GET['unzer_confirm_order_id'] ?? 0 ); + } if ( empty( $orderId ) ) { $logger->error( 'empty order id for confirmation endpoint' ); wp_redirect( wc_get_checkout_url() ); @@ -38,6 +43,7 @@ public function confirm() { $unzerPluginManager = Main::getInstance(); $paymentGateway = $unzerPluginManager->getPaymentGateway( $order->get_payment_method() ); if ( ! $paymentGateway ) { + $order->update_status( 'failed' ); $logger->error( 'payment method unknown', $order->get_payment_method() ); wc_add_notice( __( 'Payment error', 'unzer-payments' ), 'error' ); wp_redirect( wc_get_checkout_url() ); @@ -47,6 +53,7 @@ public function confirm() { $transaction = $paymentService->getChargeOrAuthorizationFromOrder( $orderId, $paymentGateway ); if ( ! $transaction ) { + $order->update_status( 'failed' ); $paymentService->removeTransactionMetaData( $orderId ); $logger->error( 'no authorization/charge found', array( 'order' => $orderId ) ); wc_add_notice( __( 'Payment error', 'unzer-payments' ), 'error' ); @@ -64,12 +71,13 @@ public function confirm() { 'reason' => $transaction->getMessage()->getMerchant(), ) ); + $order->update_status( 'failed' ); wc_add_notice( __( 'Payment cancelled', 'unzer-payments' ), 'error' ); wp_redirect( wc_get_checkout_url() ); die; } - if ( method_exists( $paymentGateway, 'isSaveInstruments' ) ) { + if ( method_exists( $paymentGateway, 'maybeSavePaymentInstrument' ) ) { if ( WC()->session->get( 'save_payment_instrument' ) ) { $paymentGateway->maybeSavePaymentInstrument( $transaction->getPayment()->getPaymentType()->getId() ); } @@ -77,6 +85,7 @@ public function confirm() { $orderService = new OrderService(); try { $orderService->processPaymentStatus( $transaction, $order ); + self::clearSessionData(); wp_redirect( $order->get_checkout_order_received_url() ); } catch ( Exception $e ) { $logger->error( @@ -87,6 +96,7 @@ public function confirm() { 'exception' => $e->getMessage(), ) ); + $order->update_status( 'failed' ); wc_add_notice( __( 'Payment error', 'unzer-payments' ), 'error' ); wp_redirect( wc_get_checkout_url() ); } @@ -94,61 +104,43 @@ public function confirm() { die; } + public function getUnzerCustomerData() { + $paymentMethodGatewayId = Util::getNonceCheckedPostValue( 'payment_method' ); + $cartData = json_decode( Util::getNonceCheckedPostValue( 'data' ), true ); + $paymentMethodGateway = Main::getInstance()->getPaymentGateway( $paymentMethodGatewayId ); + $billingData = array(); + foreach ( $cartData['billingAddress'] as $k => $v ) { + $billingData[ 'billing_' . $k ] = $v; + } + $unzerCustomer = ( new CustomerService() )->getCustomerFromData( $paymentMethodGateway, $billingData ); + + $paymentService = new PaymentService(); + $publicKey = $paymentService->getPublicKey( $paymentMethodGateway, ! empty( $billingData['billing_company'] ), $cartData['totals']['currency_code'] ); + + $this->renderJson( + array( + 'customer' => $unzerCustomer->expose(), + 'publicKey' => $publicKey, + ) + ); + } + /** * @param WC_Order $order * @return void */ public static function checkoutSuccess( $order ) { + self::clearSessionData(); ( new OrderService() )->printPaymentInstructionsHtml( $order ); } - public function validateApplePayMerchant() { - $applePayGateway = new ApplePay(); - $applePaySession = new ApplepaySession( - $applePayGateway->get_option( 'merchant_id' ), - get_bloginfo( 'name' ), - isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : get_bloginfo( 'url' ), - ); - $appleAdapter = new ApplepayAdapter(); - - $certificateTempPath = tempnam( sys_get_temp_dir(), 'WpUnzerPayments' ); - $keyTempPath = tempnam( sys_get_temp_dir(), 'WpUnzerPayments' ); - - if ( ! $certificateTempPath || ! $keyTempPath ) { - throw new Exception( 'Error on temporary file creation' ); - } - - file_put_contents( $certificateTempPath, get_option( 'unzer_apple_pay_merchant_id_certificate' ) ); - file_put_contents( $keyTempPath, get_option( 'unzer_apple_pay_merchant_id_key' ) ); - - try { - $appleAdapter->init( $certificateTempPath, $keyTempPath ); - $merchantValidationUrl = urldecode( Util::getNonceCheckedPostValue( 'validation_url' ) ); - try { - $validationResponse = $appleAdapter->validateApplePayMerchant( - $merchantValidationUrl, - $applePaySession - ); - ( new LogService() )->debug( 'apple pay validation response', array( 'response' => $validationResponse ) ); - $this->renderJson( array( 'response' => $validationResponse ) ); - } catch ( Exception $e ) { - ( new LogService() )->error( - 'merchant validation failed', - array( - 'error' => $e->getMessage(), - 'merchantValidationUrl' => $merchantValidationUrl, - ) - ); - } - } finally { - wp_delete_file( $keyTempPath ); - wp_delete_file( $certificateTempPath ); - } - } - protected function renderJson( array $data ) { header( 'Content-Type: application/json' ); echo wp_json_encode( Util::escape_array_html( $data ) ); die; } + + protected static function clearSessionData() { + setcookie( CustomerService::SESSION_KEY_USER_ID, '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN ); + } } diff --git a/includes/controllers/WebhookController.php b/includes/controllers/WebhookController.php old mode 100755 new mode 100644 diff --git a/includes/gateways/AbstractGateway.php b/includes/gateways/AbstractGateway.php old mode 100755 new mode 100644 index 41faea7..ce460bd --- a/includes/gateways/AbstractGateway.php +++ b/includes/gateways/AbstractGateway.php @@ -2,11 +2,9 @@ namespace UnzerPayments\Gateways; -use DateTime; -use Exception; use UnzerPayments\Controllers\AdminController; -use UnzerPayments\Controllers\CheckoutController; use UnzerPayments\Main; +use UnzerPayments\Services\CustomerService; use UnzerPayments\Services\LogService; use UnzerPayments\Services\PaymentService; use UnzerPayments\Util; @@ -24,6 +22,58 @@ abstract class AbstractGateway extends WC_Payment_Gateway { + const ALLOWED_HTML = array( + 'unzer-payment' => array( + 'id' => true, + 'class' => true, + 'locale' => true, + 'publicKey' => true, + 'publickey' => true, + 'data-customer' => true, + 'disableCTP' => true, + 'disablectp' => true, + ), + 'unzer-checkout' => array( + 'id' => true, + 'class' => true, + ), + 'unzer-card' => array( + 'id' => true, + 'class' => true, + ), + 'unzer-apple-pay' => array( + 'id' => true, + 'class' => true, + ), + 'unzer-google-pay' => array( + 'id' => true, + 'class' => true, + ), + 'unzer-sepa-direct-debit' => array( + 'id' => true, + 'class' => true, + ), + 'unzer-paylater-direct-debit' => array( + 'id' => true, + 'class' => true, + ), + 'unzer-paylater-installment' => array( + 'id' => true, + 'class' => true, + ), + 'unzer-paylater-invoice' => array( + 'id' => true, + 'class' => true, + ), + 'unzer-open-banking' => array( + 'id' => true, + 'class' => true, + ), + 'template' => array( + 'id' => true, + 'class' => true, + ), + ); const CONFIRMATION_ROUTE_SLUG = 'unzer-confirm'; const TRANSACTION_TYPE_AUTHORIZE = 'authorize'; @@ -42,8 +92,10 @@ abstract class AbstractGateway extends WC_Payment_Gateway { /** * @var null|array */ - public $allowedCurrencies = null; - public $allowedCountries = null; + public $allowedCurrencies = null; + public $allowedCountries = null; + public $isAllowedForB2B = null; + public $allowedCountryCurrencySets = null; public function __construct() { $this->logger = new LogService(); @@ -60,6 +112,12 @@ public function __construct() { add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); } + protected function get_allowed_html_tags() { + $response = array_merge( wp_kses_allowed_html( 'post' ), self::ALLOWED_HTML ); + $response['input']['checked'] = true; + return $response; + } + public function payment_scripts() { if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { return; @@ -97,17 +155,81 @@ public function is_enabled() { return $this->enabled === 'yes'; } + protected function get_billing_data_from_post(): array { + $postData = Util::getNonceCheckedPostValue( 'post_data' ); + if ( ! empty( $postData ) ) { + parse_str( $postData, $params ); + return $params; + } + return array(); + } + + protected function get_company_from_post() { + $company = Util::getNonceCheckedPostValue( 'company' ); + if ( ! empty( $company ) ) { + return $company; + } + + $postData = Util::getNonceCheckedPostValue( 'post_data' ); + if ( ! empty( $postData ) ) { + parse_str( $postData, $params ); + if ( ! empty( $params['billing_company'] ) ) { + return $params['billing_company']; + } + } + return ''; + } + + protected function getCurrentCountry() { + $country = Util::getNonceCheckedPostValue( 'country' ); + if ( ! empty( $country ) ) { + return $country; + } + if ( WC()->session !== null ) { + $customer = WC()->session->get( 'customer' ); + if ( ! empty( $customer['country'] ) ) { + return $customer['country']; + } + } + return null; + } + public function is_available() { $isAvailable = parent::is_available(); if ( $isAvailable && ! empty( $this->allowedCurrencies ) ) { $isAvailable = in_array( get_woocommerce_currency(), $this->allowedCurrencies ); } if ( $isAvailable && ! empty( $this->allowedCountries ) ) { - $country = Util::getNonceCheckedPostValue( 'country' ); + $country = $this->getCurrentCountry(); if ( ! empty( $country ) && ! in_array( $country, $this->allowedCountries ) ) { $isAvailable = false; } } + if ( $isAvailable && $this->isAllowedForB2B === false ) { + $company = $this->get_company_from_post(); + if ( ! empty( $company ) ) { + $isAvailable = false; + } + } + + if ( $isAvailable && ! empty( $this->allowedCountryCurrencySets ) ) { + $country = $this->getCurrentCountry(); + $currency = get_woocommerce_currency(); + $isFound = false; + foreach ( $this->allowedCountryCurrencySets as $allowedCountryCurrencySet ) { + if ( ! empty( $country ) && $allowedCountryCurrencySet['country'] !== $country ) { + continue; + } + if ( $allowedCountryCurrencySet['currency'] !== $currency ) { + continue; + } + $isFound = true; + break; + } + if ( ! $isFound ) { + $isAvailable = false; + } + } return $isAvailable; } @@ -123,12 +245,17 @@ public function process_payment( $order_id ) { 'result' => 'success', ); $charge = ( new PaymentService() )->performChargeForOrder( $order_id, $this, $this->paymentTypeResource ); + $this->before_payment_redirect( $order_id ); if ( $charge->getPayment()->getRedirectUrl() ) { $return['redirect'] = $charge->getPayment()->getRedirectUrl(); } return $return; } + protected function before_payment_redirect( $order_id ) { + WC()->session->set( 'unzer_confirm_order_id', $order_id ); + } + public function process_refund( $order_id, $amount = null, $reason = '' ) { try { $paymentService = new PaymentService(); @@ -163,8 +290,13 @@ public function process_refund_on_payment( $order_id, $amount = null, $reason = } } - public function get_confirm_url(): string { - return WC()->api_request_url( static::CONFIRMATION_ROUTE_SLUG ); + public function get_confirm_url( $order_id = null ): string { + $url = WC()->api_request_url( static::CONFIRMATION_ROUTE_SLUG ); + if ( $order_id !== null ) { + $separator = strpos( $url, '?' ) === false ? '?' : '&'; + $url .= $separator . 'unzer_confirm_order_id=' . $order_id; + } + return $url; } public function admin_options() { @@ -286,48 +418,19 @@ protected function set_order_transaction_number( $order, $unzerPaymentId ) { $order->save(); } - /** - * @param WC_Order $order - * @return void - * @throws Exception - */ - protected function handleDateOfBirth( $order, $dateOfBirth ) { - $birthDate = new DateTime( $dateOfBirth ); - $maxDate = new DateTime( '-18 years' ); - $minDate = new DateTime( '-120 years' ); - if ( $birthDate >= $maxDate ) { - throw new Exception( esc_html__( 'You have to be at least 18 years old for this payment method', 'unzer-payments' ) ); - } - if ( $birthDate < $minDate ) { - throw new Exception( esc_html__( 'Please check your date of birth', 'unzer-payments' ) ); - } - $order->update_meta_data( Main::ORDER_META_KEY_DATE_OF_BIRTH, gmdate( 'Y-m-d', strtotime( $dateOfBirth ) ) ); - $order->save_meta_data(); - - $user = wp_get_current_user(); - if ( $user->ID ) { - update_user_meta( $user->ID, Main::ORDER_META_KEY_DATE_OF_BIRTH, gmdate( 'Y-m-d', strtotime( $dateOfBirth ) ) ); - } + public function get_checkout_customer_json() { + global $wp; + $orderId = $this->isOrderPay() ? (int) $wp->query_vars['order-pay'] : null; + $customer = ( new CustomerService() )->getCustomerFromSession( $this, $orderId ); + return $customer !== null ? json_encode( $customer->expose() ) : ''; } - protected function getUserBirthDate(): string { - $dob = ''; - $user = wp_get_current_user(); - if ( $user->ID ) { - $dobFromUser = get_user_meta( $user->ID, Main::ORDER_META_KEY_DATE_OF_BIRTH, true ); - if ( $dobFromUser ) { - $dob = gmdate( 'Y-m-d', strtotime( $dobFromUser ) ); - } - } - return $dob; + protected function get_checkout_customer_json_encoded() { + return base64_encode( $this->get_checkout_customer_json() ); } protected function addCheckoutAssets() { - wp_enqueue_script( 'unzer_js', 'https://static.unzer.com/v1/unzer.js', array(), UNZER_VERSION, array( 'in_footer' => false ) ); - wp_enqueue_style( 'unzer_css', 'https://static.unzer.com/v1/unzer.css', array(), UNZER_VERSION ); - wp_enqueue_style( 'woocommerce_unzer_css', UNZER_PLUGIN_URL . '/assets/css/checkout.css', array(), UNZER_VERSION ); - wp_register_script( 'woocommerce_unzer', UNZER_PLUGIN_URL . '/assets/js/checkout.js', array( 'unzer_js', 'jquery' ), UNZER_VERSION, array( 'in_footer' => false ) ); - + global $wp; // TODO replace when minimum WP version is 6.5 (wp_enqueue_script_module) add_filter( 'script_loader_tag', @@ -343,8 +446,16 @@ function ( $tag, $handle, $src ) { 10, 3 ); - wp_enqueue_script( 'unzer_ui_v2_js', 'https://static-v2.unzer.com/v2/ui-components/index.js', array(), UNZER_VERSION, array( 'in_footer' => true ) ); + wp_enqueue_script( 'unzer_ui_v2_js', 'https://static.test.unzer.com/v2/ui-components/index.js', array(), UNZER_VERSION, array( 'in_footer' => true ) ); // https://static-v2.unzer.com/v2/ui-components/index.js + wp_enqueue_style( 'woocommerce_unzer_css', UNZER_PLUGIN_URL . '/assets/css/checkout.css', array(), UNZER_VERSION ); + if ( ( $this instanceof GooglePay ) && empty( $this->get_description() ) ) { + wp_add_inline_style( 'woocommerce_unzer_css', '.payment_box.payment_method_unzer_google_pay{display:none !important;}' ); + } elseif ( ( $this instanceof ApplePayV2 ) && empty( $this->get_description() ) ) { + wp_add_inline_style( 'woocommerce_unzer_css', '.payment_box.payment_method_unzer_apple_pay_v2{display:none !important;}' ); + } + + wp_register_script( 'woocommerce_unzer', UNZER_PLUGIN_URL . '/assets/js/checkout.js', array( 'jquery' ), UNZER_VERSION, array( 'in_footer' => false ) ); // for separate api keys $paylaterGateway = new Invoice(); $installmentGateway = new Installment(); @@ -367,7 +478,7 @@ function ( $tag, $handle, $src ) { 'locale' => get_locale(), 'store_name' => get_bloginfo( 'name' ), 'store_country' => strtoupper( substr( get_option( 'woocommerce_default_country' ), 0, 2 ) ), - 'apple_pay_merchant_validation_url' => WC()->api_request_url( CheckoutController::APPLE_PAY_MERCHANT_VALIDATION_ROUTE_SLUG ), + 'is_order_pay' => self::isOrderPay() ? 'true' : 'false', 'currency' => get_woocommerce_currency(), 'google_pay_options' => array( 'gatewayMerchantId' => $googlePayGateway->get_option( 'channel_id' ), @@ -392,17 +503,19 @@ function ( $tag, $handle, $src ) { 'woocommerce_unzer', 'unzer_i18n', array( - 'errorDob' => __( 'Please enter your date of birth', 'unzer-payments' ), - 'errorCompanyType' => __( 'Please enter your company type', 'unzer-payments' ), 'errorSepaMandate' => __( 'Please accept the SEPA mandate', 'unzer-payments' ), ) ); wp_enqueue_script( 'woocommerce_unzer' ); } - public static function addRiskDataToAuthorization( Authorization $authorization ) { + public static function isOrderPay() { + global $wp; + return ! empty( $wp->query_vars['order-pay'] ); + } + + public static function addRiskDataToAuthorization( Authorization $authorization, ?string $riskId ) { $riskData = new RiskData(); - $riskData->setThreatMetrixId( WC()->session->get( 'unzerThreatMetrixId' ) ); if ( is_user_logged_in() ) { /** @var \WP_User $user */ $user = wp_get_current_user(); @@ -412,28 +525,13 @@ public static function addRiskDataToAuthorization( Authorization $authorization } else { $riskData->setRegistrationLevel( 0 ); } + if ( $riskId !== null ) { + $riskData->setThreatMetrixId( $riskId ); + } $authorization->setRiskData( $riskData ); } - public static function removeRiskDataFromSession() { - WC()->session->set( 'unzerThreatMetrixId', null ); - } - - - protected function threatmetrix_payment_scripts() { - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { - return; - } - - if ( ! $this->is_enabled() ) { - return; - } - - if ( empty( WC()->session->get( 'unzerThreatMetrixId' ) ) ) { - WC()->session->set( 'unzerThreatMetrixId', uniqid( 'unzer_tm_' ) ); - } - wp_enqueue_script( 'unzer_threat_metrix_js', 'https://h.online-metrix.net/fp/tags.js?org_id=363t8kgq&session_id=' . WC()->session->get( 'unzerThreatMetrixId' ), array(), UNZER_VERSION, array( 'in_footer' => false ) ); - - $this->addCheckoutAssets(); + public static function isUnzerPaymentMethod( string $paymentMethodId ) { + return substr( $paymentMethodId, 0, 6 ) === 'unzer_'; } } diff --git a/includes/gateways/Alipay.php b/includes/gateways/Alipay.php old mode 100755 new mode 100644 index e4c8850..706a7f1 --- a/includes/gateways/Alipay.php +++ b/includes/gateways/Alipay.php @@ -2,6 +2,7 @@ namespace UnzerPayments\Gateways; +use UnzerPayments\Gateways\Blocks\AlipayBlock; use UnzerPayments\Services\PaymentService; if ( ! defined( 'ABSPATH' ) ) { @@ -10,7 +11,11 @@ class Alipay extends AbstractGateway { - const GATEWAY_ID = 'unzer_alipay'; + const GATEWAY_ID = 'unzer_alipay'; + const BLOCK_CLASS = AlipayBlock::class; + + public $allowedCountries = array( 'DE', 'AT', 'BE', 'IT', 'ES', 'NL' ); + public $allowedCurrencies = array( 'AUD', 'CAD', 'CHF', 'CNY', 'EUR', 'GBP', 'HKD', 'NZD', 'SGD', 'USD' ); public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\Alipay::class; public $method_title = 'Unzer Alipay'; public $method_description; diff --git a/includes/gateways/ApplePay.php b/includes/gateways/ApplePay.php deleted file mode 100755 index d10ab3a..0000000 --- a/includes/gateways/ApplePay.php +++ /dev/null @@ -1,133 +0,0 @@ -get_description(); - if ( $description ) { - echo wp_kses_post( wpautop( wptexturize( $description ) ) ); - } - ?> - - - - is_enabled() ) { - return; - } - - $this->addCheckoutAssets(); - wp_enqueue_script( 'unzer_apple_pay_js', 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js', array(), UNZER_VERSION, array( 'in_footer' => false ) ); - } - - public function get_form_fields() { - return apply_filters( - 'wc_unzer_settings', - array( - - 'enabled' => array( - 'title' => __( 'Enable/Disable', 'unzer-payments' ), - 'label' => __( 'Enable Unzer Apple Pay', 'unzer-payments' ), - 'type' => 'checkbox', - 'description' => '', - 'default' => 'no', - ), - 'title' => array( - 'title' => __( 'Title', 'unzer-payments' ), - 'type' => 'text', - 'description' => __( 'This controls the title which the user sees during checkout.', 'unzer-payments' ), - 'default' => __( 'Apple Pay', 'unzer-payments' ), - ), - 'description' => array( - 'title' => __( 'Description', 'unzer-payments' ), - 'type' => 'text', - 'description' => __( 'This controls the description which the user sees during checkout.', 'unzer-payments' ), - 'default' => '', - ), - 'transaction_type' => array( - 'title' => __( 'Charge or Authorize', 'unzer-payments' ), - 'label' => '', - 'type' => 'select', - 'description' => __( 'Choose "authorize", if you you want to charge the shopper at a later point of time', 'unzer-payments' ), - 'options' => array( - AbstractGateway::TRANSACTION_TYPE_AUTHORIZE => __( 'authorize', 'unzer-payments' ), - AbstractGateway::TRANSACTION_TYPE_CHARGE => __( 'charge', 'unzer-payments' ), - ), - 'default' => 'charge', - ), - 'merchant_id' => array( - 'title' => __( 'Merchant ID', 'unzer-payments' ), - 'type' => 'text', - 'description' => '', - 'default' => '', - ), - ) - ); - } - - public function process_payment( $order_id ) { - $this->logger->debug( 'start payment for #' . $order_id . ' with ' . self::GATEWAY_ID ); - $return = array( - 'result' => 'success', - ); - - $applePayId = Util::getNonceCheckedPostValue( 'unzer-apple-pay-id' ); - - if ( empty( $applePayId ) ) { - $this->logger->debug( 'apple pay empty id' ); - $return['messages'] = ''; - return $return; - } - if ( $this->get_option( 'transaction_type' ) === AbstractGateway::TRANSACTION_TYPE_AUTHORIZE ) { - $transaction = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, $applePayId ); - } else { - $transaction = ( new PaymentService() )->performChargeForOrder( $order_id, $this, $applePayId ); - } - - $this->logger->debug( 'apple pay charge/authorization for order ' . $order_id, array( $transaction->expose() ) ); - - if ( $transaction->getPayment()->getRedirectUrl() ) { - $return['redirect'] = $transaction->getPayment()->getRedirectUrl(); - } else { - $return['redirect'] = $this->get_confirm_url(); - } - return $return; - } - - public function get_additional_options_html() { - include UNZER_PLUGIN_PATH . 'html/admin/apple-pay-settings.php'; - } -} diff --git a/includes/gateways/ApplePayV2.php b/includes/gateways/ApplePayV2.php index 829415c..b90e875 100644 --- a/includes/gateways/ApplePayV2.php +++ b/includes/gateways/ApplePayV2.php @@ -1,7 +1,8 @@ get_description(); if ( $description ) { echo wp_kses_post( wpautop( wptexturize( $description ) ) ); + } else { + add_action( + 'wp_enqueue_scripts', + function () { + wp_add_inline_style( 'woocommerce_unzer_css', '.payment_box.payment_method_unzer_apple_pay_v2{display:none !important;}' ); + } + ); } - ?> - - - - is_enabled() ) { - return; - } - - $this->addCheckoutAssets(); + Util::getNonceField(); + $form = ' + + + + '; + echo wp_kses( $form, $this->get_allowed_html_tags() ); } public function get_form_fields() { @@ -98,12 +106,6 @@ public function process_payment( $order_id ) { ); $applePayId = Util::getNonceCheckedPostValue( 'unzer-apple-pay-v2-id' ); - - if ( empty( $applePayId ) ) { - $this->logger->debug( 'apple pay empty id', $_POST ); - $return['messages'] = ''; - return $return; - } if ( $this->get_option( 'transaction_type' ) === AbstractGateway::TRANSACTION_TYPE_AUTHORIZE ) { $transaction = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, $applePayId ); } else { @@ -112,10 +114,12 @@ public function process_payment( $order_id ) { $this->logger->debug( 'apple pay charge/authorization for order ' . $order_id, array( $transaction->expose() ) ); + $this->before_payment_redirect( $order_id ); + if ( $transaction->getPayment()->getRedirectUrl() ) { $return['redirect'] = $transaction->getPayment()->getRedirectUrl(); } else { - $return['redirect'] = $this->get_confirm_url(); + $return['redirect'] = $this->get_confirm_url( $order_id ); } return $return; } diff --git a/includes/gateways/Bancontact.php b/includes/gateways/Bancontact.php old mode 100755 new mode 100644 index 8dd61a9..bf0ce83 --- a/includes/gateways/Bancontact.php +++ b/includes/gateways/Bancontact.php @@ -2,6 +2,7 @@ namespace UnzerPayments\Gateways; +use UnzerPayments\Gateways\Blocks\BancontactBlock; use UnzerPayments\Services\PaymentService; if ( ! defined( 'ABSPATH' ) ) { @@ -11,6 +12,9 @@ class Bancontact extends AbstractGateway { const GATEWAY_ID = 'unzer_bancontact'; + const BLOCK_CLASS = BancontactBlock::class; + public $allowedCountries = array( 'BE' ); + public $allowedCurrencies = array( 'EUR' ); public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\Bancontact::class; public $method_title = 'Unzer Bancontact'; public $method_description; diff --git a/includes/gateways/Blocks/AbstractBlock.php b/includes/gateways/Blocks/AbstractBlock.php new file mode 100644 index 0000000..dc8981a --- /dev/null +++ b/includes/gateways/Blocks/AbstractBlock.php @@ -0,0 +1,150 @@ + static::GATEWAY_ID, + 'title' => $gateway->title, + 'description' => $gateway->description, + 'allowedCountries' => $gateway->allowedCountries, + 'allowedCurrencies' => $gateway->allowedCurrencies, + 'publicKey' => $gateway->get_public_key(), + 'locale' => get_locale(), + 'nonce' => Util::getNonce(), + 'paymentComponentId' => str_replace( '_', '-', static::GATEWAY_ID ) . '-payment-component', + 'getCustomerDataUrl' => WC()->api_request_url( CheckoutController::GET_UNZER_CUSTOMER_SLUG ), + ); + } + + public function get_name() { + return $this->name; + } + + public function is_active() { + $gatewayClass = static::GATEWAY_CLASS; + /** @var AbstractGateway $gateway */ + $gateway = new $gatewayClass(); + return $gateway->is_enabled(); + } + + public function get_script_data() { + return $this->get_payment_method_data(); + } + + protected function get_identifier() { + $identifier = 'unzer_simple'; + if ( ! in_array( static::GATEWAY_ID, self::SIMPLE_PAYMENT_METHODS, true ) ) { + $identifier = static::GATEWAY_ID; + } + return $identifier; + } + + public function get_payment_method_script_handles() { + return array( $this->get_identifier() . '-block-checkout' ); + } + + + public function initialize() { + if ( ! $this->should_enqueue_assets() || is_admin() ) { + return; + } + // TODO replace when minimum WP version is 6.5 (wp_enqueue_script_module) + add_filter( + 'script_loader_tag', + function ( $tag, $handle, $src ) { + // if not your script, do nothing and return original $tag + if ( 'unzer_ui_v2_js' !== $handle ) { + return $tag; + } + // change the script tag by adding type="module" and return it. + $tag = ''; + return $tag; + }, + 10, + 3 + ); + wp_enqueue_script( 'unzer_ui_v2_js', 'https://static.test.unzer.com/v2/ui-components/index.js', array(), UNZER_VERSION, array( 'in_footer' => true ) ); // https://static-v2.unzer.com/v2/ui-components/index.js + wp_register_script( 'unzer_global-block-checkout', UNZER_PLUGIN_URL . '/assets/build/unzer_global.js', array( 'wc-blocks-registry' ), UNZER_VERSION, array( 'in_footer' => true ) ); + wp_enqueue_script( 'unzer_global-block-checkout' ); + $this->settings = array( + 'title' => $this->get_setting( 'title' ), + ); + $identifier = $this->get_identifier(); + $script_dependencies_path = UNZER_PLUGIN_PATH . 'assets/build/' . $identifier . '.asset.php'; + $script_url = UNZER_PLUGIN_URL . '/assets/build/' . $identifier . '.js'; + $style_path = UNZER_PLUGIN_PATH . 'assets/build/' . $identifier . '.css'; + $style_url = UNZER_PLUGIN_URL . '/assets/build/' . $identifier . '.css'; + $asset_handle = $identifier . '-block-checkout'; + + $script_dependencies = require $script_dependencies_path; + wp_register_script( $asset_handle, $script_url, $script_dependencies['dependencies'], $script_dependencies['version'], array( 'in_footer' => true ) ); + if ( file_exists( $style_path ) ) { + wp_register_style( $asset_handle, $style_url, array(), UNZER_VERSION ); + } + + wp_set_script_translations( $asset_handle, 'unzer-payments' ); + + wp_enqueue_script( $asset_handle ); + if ( wp_style_is( $asset_handle, 'registered' ) ) { + wp_enqueue_style( $asset_handle ); + } + } + + private function should_enqueue_assets(): bool { + $should_enqueue = ! is_order_received_page() && ! is_checkout_pay_page(); + + $is_cart_block_in_use = class_exists( CartCheckoutUtils::class ) && CartCheckoutUtils::is_cart_block_default(); + $is_checkout_block_in_use = class_exists( CartCheckoutUtils::class ) && CartCheckoutUtils::is_checkout_block_default(); + + return $should_enqueue && ( wp_is_block_theme() || $is_cart_block_in_use || $is_checkout_block_in_use ); + } +} diff --git a/includes/gateways/Blocks/AlipayBlock.php b/includes/gateways/Blocks/AlipayBlock.php new file mode 100644 index 0000000..5568ebc --- /dev/null +++ b/includes/gateways/Blocks/AlipayBlock.php @@ -0,0 +1,16 @@ + -
-
-
- -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
- -
-
-
- '; - echo wp_kses_post( $this->renderSavedInstrumentsSelection( $form ) ); + $form = ' + +
+ '; + echo wp_kses( $this->renderSavedInstrumentsSelection( $form ), $this->get_allowed_html_tags() ); } public function get_form_fields() { @@ -122,6 +110,17 @@ public function get_form_fields() { 'yes' => __( 'Yes', 'unzer-payments' ), ), ), + 'allow_ctp' => array( + 'title' => __( 'Offer Click To Pay', 'unzer-payments' ), + 'label' => __( ' ', 'unzer-payments' ), + 'type' => 'select', + 'description' => '', + 'default' => 'no', + 'options' => array( + 'no' => __( 'No', 'unzer-payments' ), + 'yes' => __( 'Yes', 'unzer-payments' ), + ), + ), /* 'capture_trigger_order_status' => [ 'title' => __('Capture status', 'unzer-payments'), @@ -164,11 +163,11 @@ public function process_payment( $order_id ) { } else { $transaction = ( new PaymentService() )->performChargeForOrder( $order_id, $this, $cardId, $transactionEditorFunction ); } - + $this->before_payment_redirect( $order_id ); if ( $transaction->getPayment()->getRedirectUrl() ) { $return['redirect'] = $transaction->getPayment()->getRedirectUrl(); } elseif ( $transaction->isSuccess() ) { - $return['redirect'] = $this->get_confirm_url(); + $return['redirect'] = $this->get_confirm_url( $order_id ); } return $return; } diff --git a/includes/gateways/DirectDebit.php b/includes/gateways/DirectDebit.php old mode 100755 new mode 100644 index c134120..6b8007d --- a/includes/gateways/DirectDebit.php +++ b/includes/gateways/DirectDebit.php @@ -3,6 +3,7 @@ namespace UnzerPayments\Gateways; use Exception; +use UnzerPayments\Gateways\Blocks\DirectDebitBlock; use UnzerPayments\Services\PaymentService; use UnzerPayments\Traits\SavePaymentInstrumentTrait; use UnzerPayments\Util; @@ -20,6 +21,8 @@ class DirectDebit extends AbstractGateway { public $paymentTypeResource = SepaDirectDebit::class; const GATEWAY_ID = 'unzer_direct_debit'; + const BLOCK_CLASS = DirectDebitBlock::class; + public $allowedCurrencies = array( 'EUR' ); public $method_title = 'Unzer SEPA Direct Debit'; public $method_description; public $title = 'SEPA Direct Debit'; @@ -57,45 +60,23 @@ public function payment_fields() { echo wp_kses_post( wpautop( wptexturize( $description ) ) ); } Util::getNonceField(); - $formId = uniqid(); - $form = ' -
- -
-
-
-
-
-
- -
+ $form = ' + + + +
+ + '; - echo wp_kses_post( $this->renderSavedInstrumentsSelection( $form ) ); - } - - public function payment_scripts() { - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { - return; - } - - if ( ! $this->is_enabled() ) { - return; - } - - $this->addCheckoutAssets(); + echo wp_kses( $this->renderSavedInstrumentsSelection( $form ), $this->get_allowed_html_tags() ); } public function get_form_fields() { @@ -103,32 +84,25 @@ public function get_form_fields() { 'wc_unzer_settings', array( - 'enabled' => array( + 'enabled' => array( 'title' => __( 'Enable/Disable', 'unzer-payments' ), 'label' => __( 'Enable Unzer SEPA Direct Debit Payments', 'unzer-payments' ), 'type' => 'checkbox', 'description' => '', 'default' => 'no', ), - 'title' => array( + 'title' => array( 'title' => __( 'Title', 'unzer-payments' ), 'type' => 'text', 'description' => __( 'This controls the title which the user sees during checkout.', 'unzer-payments' ), 'default' => __( 'SEPA Direct Debit', 'unzer-payments' ), ), - 'description' => array( + 'description' => array( 'title' => __( 'Description', 'unzer-payments' ), 'type' => 'text', 'description' => __( 'This controls the description which the user sees during checkout.', 'unzer-payments' ), 'default' => '', ), - 'sepa_mandate' => array( - 'title' => __( 'Alternative SEPA mandate description', 'unzer-payments' ), - 'type' => 'textarea', - 'description' => __( 'Leave empty to display the default text', 'unzer-payments' ), - 'placeholder' => $this->defaultMandateText, - 'default' => '', - ), AbstractGateway::SETTINGS_KEY_SAVE_INSTRUMENTS => array( 'title' => __( 'Save bank details for registered customers', 'unzer-payments' ), 'label' => __( ' ', 'unzer-payments' ), @@ -168,8 +142,8 @@ public function process_payment( $order_id ) { } else { $this->set_order_transaction_number( wc_get_order( $order_id ), $charge->getPayment()->getId() ); } - WC()->session->set( 'unzer_confirm_order_id', $order_id ); - $return['redirect'] = $this->get_confirm_url(); + $this->before_payment_redirect( $order_id ); + $return['redirect'] = $this->get_confirm_url( $order_id ); return $return; } diff --git a/includes/gateways/DirectDebitSecured.php b/includes/gateways/DirectDebitSecured.php old mode 100755 new mode 100644 index b4b6783..2dbbd84 --- a/includes/gateways/DirectDebitSecured.php +++ b/includes/gateways/DirectDebitSecured.php @@ -3,12 +3,14 @@ namespace UnzerPayments\Gateways; use Exception; +use UnzerPayments\Gateways\Blocks\DirectDebitSecuredBlock; use UnzerPayments\Services\OrderService; use UnzerPayments\Services\PaymentService; use UnzerPayments\Util; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType; use UnzerSDK\Resources\TransactionTypes\Authorization; +use UnzerSDK\Resources\TransactionTypes\Charge; use WC_Order; if ( ! defined( 'ABSPATH' ) ) { @@ -17,13 +19,17 @@ class DirectDebitSecured extends AbstractGateway { - const GATEWAY_ID = 'unzer_direct_debit_secured'; - public $method_title = 'Unzer Direct Debit'; - public $method_description; - public $title = 'Direct Debit'; - public $description = ''; - public $id = self::GATEWAY_ID; + + const GATEWAY_ID = 'unzer_direct_debit_secured'; + const BLOCK_CLASS = DirectDebitSecuredBlock::class; + public $allowedCountries = array( 'AT', 'DE' ); public $allowedCurrencies = array( 'EUR' ); + public $isAllowedForB2B = false; + public $method_title = 'Unzer Direct Debit'; + public $method_description; + public $title = 'Direct Debit'; + public $description = ''; + public $id = self::GATEWAY_ID; public $plugin_id; public $supports = array( 'products', @@ -45,23 +51,25 @@ public function payment_fields() { if ( $description ) { echo wp_kses_post( wpautop( wptexturize( $description ) ) ); } - Util::getNonceField(); - $formId = uniqid(); - ?> - - -
- - -
-
-
-
- threatmetrix_payment_scripts(); + Util::getNonceField(); + $form = ' + + + +
+ + '; + echo wp_kses( $form, $this->get_allowed_html_tags() ); } public function get_form_fields() { @@ -113,24 +121,22 @@ public function get_form_fields() { public function process_payment( $order_id ) { $this->logger->debug( 'start payment for #' . $order_id . ' with ' . self::GATEWAY_ID ); - $order = wc_get_order( $order_id ); - $return = array( + $order = wc_get_order( $order_id ); + $return = array( 'result' => 'success', ); - $dob = Util::getNonceCheckedPostValue( 'unzer-direct-debit-secured-dob' ); - $this->handleDateOfBirth( $order, $dob ); - $_POST['unzer-dob'] = $dob; // for the unified handling in CustomerService and OrderService - $paymentMeanId = Util::getNonceCheckedPostValue( 'unzer-direct-debit-secured-id' ); + $paymentMeanId = Util::getNonceCheckedPostValue( 'unzer-direct-debit-secured-id' ); + $riskId = Util::getNonceCheckedPostValue( 'unzer-direct-debit-secured-risk-id' ); $authorization = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, $paymentMeanId, - function ( Authorization $authorization ) { - AbstractGateway::addRiskDataToAuthorization( $authorization ); + function ( Authorization $authorization ) use ( $riskId ) { + AbstractGateway::addRiskDataToAuthorization( $authorization, $riskId ); } ); - + $this->before_payment_redirect( $order_id ); if ( $authorization->getPayment()->getRedirectUrl() ) { $return['redirect'] = $authorization->getPayment()->getRedirectUrl(); } elseif ( $authorization->isSuccess() ) { @@ -141,9 +147,8 @@ function ( Authorization $authorization ) { // silent catch } WC()->session->set( 'unzer_confirm_order_id', $order_id ); - $return['redirect'] = $this->get_confirm_url(); + $return['redirect'] = $this->get_confirm_url( $order_id ); } - AbstractGateway::removeRiskDataFromSession(); return $return; } @@ -167,6 +172,10 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { public function capture( WC_Order $order, $amount = null ) { } + /** + * @param Charge|Authorization $chargeOrAuthorization + * @return string + */ public function get_payment_information( AbstractTransactionType $chargeOrAuthorization ) { return sprintf( __( "An amount of %1\$s will be deducted from your account using the descriptor '%2\$s' according to the SEPA mandate", 'unzer-payments' ), @@ -174,4 +183,13 @@ public function get_payment_information( AbstractTransactionType $chargeOrAuthor $chargeOrAuthorization->getDescriptor() ); } + + private function get_current_public_key() { + $keyName = 'public_key_eur_b2c'; + $publicKey = $this->get_option( $keyName ); + if ( empty( $publicKey ) ) { + $publicKey = get_option( 'unzer_public_key' ); + } + return $publicKey; + } } diff --git a/includes/gateways/Eps.php b/includes/gateways/Eps.php old mode 100755 new mode 100644 index aa208c1..58e2dca --- a/includes/gateways/Eps.php +++ b/includes/gateways/Eps.php @@ -2,6 +2,7 @@ namespace UnzerPayments\Gateways; +use UnzerPayments\Gateways\Blocks\EpsBlock; use UnzerPayments\Services\PaymentService; use UnzerPayments\Util; @@ -12,6 +13,9 @@ class Eps extends AbstractGateway { const GATEWAY_ID = 'unzer_eps'; + const BLOCK_CLASS = EpsBlock::class; + public $allowedCountries = array( 'AT' ); + public $allowedCurrencies = array( 'EUR' ); public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\EPS::class; public $method_title = 'Unzer EPS'; public $method_description; diff --git a/includes/gateways/Giropay.php b/includes/gateways/Giropay.php deleted file mode 100755 index 192bae7..0000000 --- a/includes/gateways/Giropay.php +++ /dev/null @@ -1,56 +0,0 @@ - array( - 'title' => __( 'Enable/Disable', 'unzer-payments' ), - 'label' => __( 'Enable Unzer Giropay', 'unzer-payments' ), - 'type' => 'checkbox', - 'description' => '', - 'default' => 'no', - ), - 'title' => array( - 'title' => __( 'Title', 'unzer-payments' ), - 'type' => 'text', - 'description' => __( 'This controls the title which the user sees during checkout.', 'unzer-payments' ), - 'default' => __( 'Giropay', 'unzer-payments' ), - ), - 'description' => array( - 'title' => __( 'Description', 'unzer-payments' ), - 'type' => 'text', - 'description' => __( 'This controls the description which the user sees during checkout.', 'unzer-payments' ), - 'default' => '', - ), - ) - ); - } -} diff --git a/includes/gateways/GooglePay.php b/includes/gateways/GooglePay.php index 03ec9fe..aad8762 100644 --- a/includes/gateways/GooglePay.php +++ b/includes/gateways/GooglePay.php @@ -1,7 +1,8 @@ - - - is_enabled() ) { - return; - } - $this->addCheckoutAssets(); - wp_enqueue_script( 'unzer_google_pay_js', 'https://pay.google.com/gp/p/js/pay.js', array(), UNZER_VERSION, array( 'in_footer' => false ) ); + Util::getNonceField(); + $form = ' + + + + '; + echo wp_kses( $form, $this->get_allowed_html_tags() ); } public function get_form_fields() { @@ -211,12 +212,6 @@ public function process_payment( $order_id ) { ); $googlePayId = Util::getNonceCheckedPostValue( 'unzer-google-pay-id' ); - - if ( empty( $googlePayId ) ) { - $this->logger->debug( 'google pay empty id' ); - $return['messages'] = ''; - return $return; - } if ( $this->get_option( 'transaction_type' ) === AbstractGateway::TRANSACTION_TYPE_AUTHORIZE ) { $transaction = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, $googlePayId ); } else { @@ -224,11 +219,11 @@ public function process_payment( $order_id ) { } $this->logger->debug( 'google pay charge/authorization for order ' . $order_id, array( $transaction->expose() ) ); - + $this->before_payment_redirect( $order_id ); if ( $transaction->getPayment()->getRedirectUrl() ) { $return['redirect'] = $transaction->getPayment()->getRedirectUrl(); } else { - $return['redirect'] = $this->get_confirm_url(); + $return['redirect'] = $this->get_confirm_url( $order_id ); } return $return; } diff --git a/includes/gateways/Ideal.php b/includes/gateways/Ideal.php old mode 100755 new mode 100644 index cb45a86..0e7b15f --- a/includes/gateways/Ideal.php +++ b/includes/gateways/Ideal.php @@ -2,8 +2,7 @@ namespace UnzerPayments\Gateways; -use UnzerPayments\Services\PaymentService; -use UnzerPayments\Util; +use UnzerPayments\Gateways\Blocks\IdealBlock; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -11,8 +10,13 @@ class Ideal extends AbstractGateway { - const GATEWAY_ID = 'unzer_ideal'; - public $method_title = 'Unzer iDEAL'; + + const GATEWAY_ID = 'unzer_ideal'; + const BLOCK_CLASS = IdealBlock::class; + public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\Ideal::class; + public $allowedCountries = array( 'NL' ); + public $allowedCurrencies = array( 'EUR' ); + public $method_title = 'Unzer iDEAL'; public $method_description; public $title = 'iDEAL'; public $description = ''; @@ -23,24 +27,6 @@ class Ideal extends AbstractGateway { 'refunds', ); - public function has_fields() { - return true; - } - - public function payment_fields() { - $description = $this->get_description(); - if ( $description ) { - echo wp_kses_post( wpautop( wptexturize( $description ) ) ); - } - Util::getNonceField(); - ?> -
- -
-
- logger->debug( 'start payment for #' . $order_id . ' with ' . self::GATEWAY_ID ); - $return = array( - 'result' => 'success', - ); - $transaction = ( new PaymentService() )->performChargeForOrder( $order_id, $this, Util::getNonceCheckedPostValue( 'unzer-ideal-id' ) ); - if ( $transaction->getPayment()->getRedirectUrl() ) { - $return['redirect'] = $transaction->getPayment()->getRedirectUrl(); - } - return $return; - } } diff --git a/includes/gateways/Installment.php b/includes/gateways/Installment.php old mode 100755 new mode 100644 index 62e7b18..b33d8af --- a/includes/gateways/Installment.php +++ b/includes/gateways/Installment.php @@ -3,12 +3,14 @@ namespace UnzerPayments\Gateways; use Exception; +use UnzerPayments\Gateways\Blocks\InstallmentBlock; use UnzerPayments\Services\OrderService; use UnzerPayments\Services\PaymentService; use UnzerPayments\Util; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType; use UnzerSDK\Resources\TransactionTypes\Authorization; +use UnzerSDK\Resources\TransactionTypes\Charge; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -17,19 +19,21 @@ class Installment extends AbstractGateway { - const GATEWAY_ID = 'unzer_installment'; - public $method_title = 'Unzer Installment'; + const GATEWAY_ID = 'unzer_installment'; + const BLOCK_CLASS = InstallmentBlock::class; + public $allowedCurrencies = array( 'EUR', 'CHF' ); + public $allowedCountries = array( 'AT', 'CH', 'DE' ); + public $isAllowedForB2B = false; + public $method_title = 'Unzer Installment'; public $method_description; public $title = 'Installment'; public $description = ''; public $id = self::GATEWAY_ID; public $plugin_id; - public $supports = array( + public $supports = array( 'products', 'refunds', ); - public $allowedCurrencies = array( 'EUR', 'CHF' ); - public $allowedCountries = array( 'AT', 'CH', 'DE' ); public function __construct() { parent::__construct(); @@ -46,24 +50,34 @@ public function payment_fields() { echo wp_kses_post( wpautop( wptexturize( $description ) ) ); } Util::getNonceField(); - ?> -
- - -
-
- - -
-
-
-
-
- + + + +
+ + '; + echo wp_kses( $form, $this->get_allowed_html_tags() ); } - public function payment_scripts() { - $this->threatmetrix_payment_scripts(); + public function get_current_public_key() { + $currency = get_woocommerce_currency(); + $keyName = 'public_key_' . strtolower( $currency ) . '_b2c'; + $publicKey = $this->get_option( $keyName ); + if ( empty( $publicKey ) ) { + $publicKey = get_option( 'unzer_public_key' ); + } + return $publicKey; } public function get_form_fields() { @@ -154,19 +168,15 @@ public function process_payment( $order_id ) { 'result' => 'success', ); $order = wc_get_order( $order_id ); - - $dob = Util::getNonceCheckedPostValue( 'unzer-installment-dob' ); - $this->handleDateOfBirth( $order, $dob ); - $_POST['unzer-dob'] = $dob; $order->save_meta_data(); - + $riskId = Util::getNonceCheckedPostValue( 'unzer-installment-risk-id' ); try { $authorization = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, Util::getNonceCheckedPostValue( 'unzer-installment-id' ), - function ( Authorization $authorization ) { - AbstractGateway::addRiskDataToAuthorization( $authorization ); + function ( Authorization $authorization ) use ( $riskId ) { + AbstractGateway::addRiskDataToAuthorization( $authorization, $riskId ); } ); } catch ( UnzerApiException $e ) { @@ -175,6 +185,7 @@ function ( Authorization $authorization ) { if ( ! ( $authorization->isPending() || $authorization->isSuccess() ) ) { throw new Exception( esc_html( $authorization->getMessage()->getCustomer() ) ); } + if ( $authorization->isSuccess() ) { $order = wc_get_order( $order_id ); $orderService = new OrderService(); @@ -182,11 +193,14 @@ function ( Authorization $authorization ) { } else { $this->set_order_transaction_number( wc_get_order( $order_id ), $authorization->getPayment()->getId() ); } + $this->before_payment_redirect( $order_id ); $return['redirect'] = $this->get_return_url( wc_get_order( $order_id ) ); - AbstractGateway::removeRiskDataFromSession(); return $return; } - + /** + * @param Charge|Authorization $chargeOrAuthorization + * @return string + */ public function get_payment_information( AbstractTransactionType $chargeOrAuthorization ) { return sprintf( __( diff --git a/includes/gateways/Invoice.php b/includes/gateways/Invoice.php old mode 100755 new mode 100644 index 18f2af8..5c19294 --- a/includes/gateways/Invoice.php +++ b/includes/gateways/Invoice.php @@ -3,6 +3,7 @@ namespace UnzerPayments\Gateways; use Exception; +use UnzerPayments\Gateways\Blocks\InvoiceBlock; use UnzerPayments\Main; use UnzerPayments\Services\OrderService; use UnzerPayments\Services\PaymentService; @@ -10,6 +11,7 @@ use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType; use UnzerSDK\Resources\TransactionTypes\Authorization; +use UnzerSDK\Resources\TransactionTypes\Charge; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -18,8 +20,11 @@ class Invoice extends AbstractGateway { - const GATEWAY_ID = 'unzer_invoice'; - public $method_title = 'Unzer Invoice'; + const GATEWAY_ID = 'unzer_invoice'; + const BLOCK_CLASS = InvoiceBlock::class; + public $allowedCurrencies = array( 'EUR', 'CHF' ); + public $allowedCountries = array( 'AT', 'CH', 'DE', 'NL' ); + public $method_title = 'Unzer Invoice'; public $method_description; public $title = 'Invoice'; public $description = ''; @@ -30,8 +35,6 @@ class Invoice extends AbstractGateway { 'refunds', ); - public $allowedCurrencies = array( 'EUR', 'CHF' ); - public $allowedCountries = array( 'AT', 'CH', 'DE', 'NL' ); public function __construct() { parent::__construct(); @@ -152,37 +155,37 @@ public function payment_fields() { echo wp_kses_post( wpautop( wptexturize( $description ) ) ); } Util::getNonceField(); - ?> -
- - -
-
- - -
-
- -
-
- -
-
-
- threatmetrix_payment_scripts(); + $form = ' + + + + +
+ + '; + echo wp_kses( $form, $this->get_allowed_html_tags() ); } + public function get_current_public_key() { + $currency = get_woocommerce_currency(); + $isB2C = empty( $this->get_company_from_post() ); + $keyName = 'public_key_' . strtolower( $currency ) . '_' . ( $isB2C ? 'b2c' : 'b2b' ); + $publicKey = $this->get_option( $keyName ); + if ( empty( $publicKey ) ) { + $publicKey = get_option( 'unzer_public_key' ); + } + return $publicKey; + } /** * @param $order_id @@ -193,33 +196,14 @@ public function process_payment( $order_id ) { $return = array( 'result' => 'success', ); - $order = wc_get_order( $order_id ); - - if ( !$order->get_billing_company() ) { - $dob = Util::getNonceCheckedPostValue('unzer-invoice-dob'); - $this->handleDateOfBirth($order, $dob); - $_POST['unzer-dob'] = $dob; // for unified handling in CustomerService and OrderService - } elseif ( $order->get_billing_company() ) { - $companyType = (string) Util::getNonceCheckedPostValue( 'unzer-invoice-company-type' ); - if ( empty( $companyType ) ) { - throw new Exception( esc_html__( 'Please enter your company type', 'unzer-payments' ) ); - } - if ($companyType === 'sole') { - $dob = Util::getNonceCheckedPostValue('unzer-invoice-dob'); - $this->handleDateOfBirth($order, $dob); - $_POST['unzer-dob'] = $dob; // for unified handling in CustomerService and OrderService - } - $order->update_meta_data( Main::ORDER_META_KEY_COMPANY_TYPE, $companyType ); - } - $order->save_meta_data(); - + $riskId = Util::getNonceCheckedPostValue( 'unzer-invoice-risk-id' ); try { $authorization = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, Util::getNonceCheckedPostValue( 'unzer-invoice-id' ), - function ( Authorization $authorization ) { - AbstractGateway::addRiskDataToAuthorization( $authorization ); + function ( Authorization $authorization ) use ( $riskId ) { + AbstractGateway::addRiskDataToAuthorization( $authorization, $riskId ); } ); } catch ( UnzerApiException $e ) { @@ -235,8 +219,8 @@ function ( Authorization $authorization ) { } else { $this->set_order_transaction_number( wc_get_order( $order_id ), $authorization->getPayment()->getId() ); } + $this->before_payment_redirect( $order_id ); $return['redirect'] = $this->get_return_url( wc_get_order( $order_id ) ); - AbstractGateway::removeRiskDataFromSession(); return $return; } @@ -253,6 +237,10 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { } + /** + * @param Charge|Authorization $chargeOrAuthorization + * @return string + */ public function get_payment_information( AbstractTransactionType $chargeOrAuthorization ) { return sprintf( __( diff --git a/includes/gateways/Klarna.php b/includes/gateways/Klarna.php old mode 100755 new mode 100644 index f4fb701..f06b7e4 --- a/includes/gateways/Klarna.php +++ b/includes/gateways/Klarna.php @@ -2,8 +2,10 @@ namespace UnzerPayments\Gateways; +use UnzerPayments\Gateways\Blocks\KlarnaBlock; use UnzerPayments\Services\PaymentService; -use UnzerSDK\Resources\TransactionTypes\Charge; +use UnzerSDK\Exceptions\UnzerApiException; +use UnzerSDK\Resources\TransactionTypes\Authorization; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -11,8 +13,117 @@ class Klarna extends AbstractGateway { - const GATEWAY_ID = 'unzer_klarna'; - public $method_title = 'Unzer Klarna'; + + + const GATEWAY_ID = 'unzer_klarna'; + const BLOCK_CLASS = KlarnaBlock::class; + public $allowedCountryCurrencySets = array( + array( + 'country' => 'AU', + 'currency' => 'AUD', + ), + array( + 'country' => 'AT', + 'currency' => 'EUR', + ), + array( + 'country' => 'BE', + 'currency' => 'EUR', + ), + array( + 'country' => 'CA', + 'currency' => 'CAD', + ), + array( + 'country' => 'CZ', + 'currency' => 'CZK', + ), + array( + 'country' => 'DK', + 'currency' => 'DKK', + ), + array( + 'country' => 'FI', + 'currency' => 'EUR', + ), + array( + 'country' => 'FR', + 'currency' => 'EUR', + ), + array( + 'country' => 'DE', + 'currency' => 'EUR', + ), + array( + 'country' => 'GR', + 'currency' => 'EUR', + ), + array( + 'country' => 'HU', + 'currency' => 'HUF', + ), + array( + 'country' => 'IE', + 'currency' => 'EUR', + ), + array( + 'country' => 'IT', + 'currency' => 'EUR', + ), + array( + 'country' => 'MX', + 'currency' => 'MXN', + ), + array( + 'country' => 'NL', + 'currency' => 'EUR', + ), + array( + 'country' => 'NZ', + 'currency' => 'NZD', + ), + array( + 'country' => 'NO', + 'currency' => 'NOK', + ), + array( + 'country' => 'PL', + 'currency' => 'PLN', + ), + array( + 'country' => 'PT', + 'currency' => 'EUR', + ), + array( + 'country' => 'RO', + 'currency' => 'RON', + ), + array( + 'country' => 'SK', + 'currency' => 'EUR', + ), + array( + 'country' => 'ES', + 'currency' => 'EUR', + ), + array( + 'country' => 'SE', + 'currency' => 'SEK', + ), + array( + 'country' => 'CH', + 'currency' => 'CHF', + ), + array( + 'country' => 'GB', + 'currency' => 'GBP', + ), + array( + 'country' => 'US', + 'currency' => 'USD', + ), + ); + public $method_title = 'Unzer Klarna'; public $method_description; public $title = 'Klarna'; public $description = ''; @@ -55,20 +166,33 @@ public function process_payment( $order_id ) { $return = array( 'result' => 'success', ); - $charge = ( new PaymentService() )->performChargeForOrder( + $charge = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, \UnzerSDK\Resources\PaymentTypes\Klarna::class, - function ( Charge $charge ) { - $charge - ->setTermsAndConditionUrl( 'https://google.com' ) - ->setPrivacyPolicyUrl( 'https://google.com/de/' ); + function ( Authorization $authorization ) { + $authorization + ->setTermsAndConditionUrl( 'https://unzer.com' ) + ->setPrivacyPolicyUrl( 'https://unzer.com' ); } ); + $this->before_payment_redirect( $order_id ); + if ( $charge->getPayment()->getRedirectUrl() ) { $return['redirect'] = $charge->getPayment()->getRedirectUrl(); } return $return; } + + /** + * @param $order_id + * @param $amount + * @param $reason + * @return bool + * @throws UnzerApiException + */ + public function process_refund( $order_id, $amount = null, $reason = '' ) { + return $this->process_refund_on_payment( $order_id, $amount, $reason ); + } } diff --git a/includes/gateways/OpenBanking.php b/includes/gateways/OpenBanking.php index 2fd5096..e06835e 100644 --- a/includes/gateways/OpenBanking.php +++ b/includes/gateways/OpenBanking.php @@ -1,9 +1,8 @@ -
- - - -
-
+ '; + echo wp_kses( $html, $this->get_allowed_html_tags() ); } public function process_refund( $order_id, $amount = null, $reason = '' ) { diff --git a/includes/gateways/Paypal.php b/includes/gateways/Paypal.php old mode 100755 new mode 100644 index b9b40b8..c3d92a3 --- a/includes/gateways/Paypal.php +++ b/includes/gateways/Paypal.php @@ -2,6 +2,7 @@ namespace UnzerPayments\Gateways; +use UnzerPayments\Gateways\Blocks\PaypalBlock; use UnzerPayments\Services\PaymentService; use UnzerPayments\Traits\SavePaymentInstrumentTrait; use UnzerPayments\Util; @@ -14,10 +15,12 @@ class Paypal extends AbstractGateway { + use SavePaymentInstrumentTrait; public $paymentTypeResource = PaypalResource::class; const GATEWAY_ID = 'unzer_paypal'; + const BLOCK_CLASS = PaypalBlock::class; public $method_title = 'Unzer PayPal'; public $method_description; public $title = 'PayPal'; @@ -109,10 +112,12 @@ public function process_payment( $order_id ) { $transaction = ( new PaymentService() )->performChargeForOrder( $order_id, $this, $paymentMean, $transactionEditorFunction ); } + $this->before_payment_redirect( $order_id ); + if ( $transaction->getPayment()->getRedirectUrl() ) { $return['redirect'] = $transaction->getPayment()->getRedirectUrl(); } elseif ( $transaction->isSuccess() ) { - $return['redirect'] = $this->get_confirm_url(); + $return['redirect'] = $this->get_confirm_url( $order_id ); } return $return; } diff --git a/includes/gateways/Pis.php b/includes/gateways/Pis.php deleted file mode 100755 index 41b76aa..0000000 --- a/includes/gateways/Pis.php +++ /dev/null @@ -1,53 +0,0 @@ - array( - 'title' => __( 'Enable/Disable', 'unzer-payments' ), - 'label' => __( 'Enable Unzer Bank Transfer', 'unzer-payments' ), - 'type' => 'checkbox', - 'description' => '', - 'default' => 'no', - ), - 'title' => array( - 'title' => __( 'Title', 'unzer-payments' ), - 'type' => 'text', - 'description' => __( 'This controls the title which the user sees during checkout.', 'unzer-payments' ), - 'default' => __( 'Bank Transfer', 'unzer-payments' ), - ), - 'description' => array( - 'title' => __( 'Description', 'unzer-payments' ), - 'type' => 'text', - 'description' => __( 'This controls the description which the user sees during checkout.', 'unzer-payments' ), - 'default' => '', - ), - ) - ); - } -} diff --git a/includes/gateways/PostFinanceCard.php b/includes/gateways/PostFinanceCard.php old mode 100755 new mode 100644 index 89a430d..72b73a4 --- a/includes/gateways/PostFinanceCard.php +++ b/includes/gateways/PostFinanceCard.php @@ -2,6 +2,8 @@ namespace UnzerPayments\Gateways; +use UnzerPayments\Gateways\Blocks\PostFinanceCardBlock; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -9,6 +11,9 @@ class PostFinanceCard extends AbstractGateway { const GATEWAY_ID = 'unzer_postfinance_card'; + const BLOCK_CLASS = PostFinanceCardBlock::class; + public $allowedCountries = array( 'CH' ); + public $allowedCurrencies = array( 'CHF' ); public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\PostFinanceCard::class; public $method_title = 'Unzer Post Finance Card'; public $method_description; @@ -16,11 +21,10 @@ class PostFinanceCard extends AbstractGateway { public $description = ''; public $id = self::GATEWAY_ID; public $plugin_id; - public $supports = array( + public $supports = array( 'products', 'refunds', ); - public $allowedCurrencies = array( 'CHF' ); public function get_form_fields() { return apply_filters( diff --git a/includes/gateways/PostFinanceEfinance.php b/includes/gateways/PostFinanceEfinance.php old mode 100755 new mode 100644 index f6e066d..30bacac --- a/includes/gateways/PostFinanceEfinance.php +++ b/includes/gateways/PostFinanceEfinance.php @@ -2,6 +2,8 @@ namespace UnzerPayments\Gateways; +use UnzerPayments\Gateways\Blocks\PostFinanceEfinanceBlock; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -9,6 +11,9 @@ class PostFinanceEfinance extends AbstractGateway { const GATEWAY_ID = 'unzer_postfinance_efinance'; + const BLOCK_CLASS = PostFinanceEfinanceBlock::class; + public $allowedCountries = array( 'CH' ); + public $allowedCurrencies = array( 'CHF' ); public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\PostFinanceEfinance::class; public $method_title = 'Unzer Post Finance eFinance'; public $method_description; @@ -16,11 +21,10 @@ class PostFinanceEfinance extends AbstractGateway { public $description = ''; public $id = self::GATEWAY_ID; public $plugin_id; - public $supports = array( + public $supports = array( 'products', 'refunds', ); - public $allowedCurrencies = array( 'CHF' ); public function get_form_fields() { return apply_filters( diff --git a/includes/gateways/Prepayment.php b/includes/gateways/Prepayment.php old mode 100755 new mode 100644 index f1d160a..ff7ea42 --- a/includes/gateways/Prepayment.php +++ b/includes/gateways/Prepayment.php @@ -3,8 +3,10 @@ namespace UnzerPayments\Gateways; use Exception; +use UnzerPayments\Gateways\Blocks\PrepaymentBlock; use UnzerPayments\Services\OrderService; use UnzerPayments\Services\PaymentService; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; if ( ! defined( 'ABSPATH' ) ) { @@ -14,8 +16,10 @@ class Prepayment extends AbstractGateway { - const GATEWAY_ID = 'unzer_prepayment'; - public $method_title = 'Unzer Prepayment'; + const GATEWAY_ID = 'unzer_prepayment'; + const BLOCK_CLASS = PrepaymentBlock::class; + public $allowedCurrencies = array( 'EUR' ); + public $method_title = 'Unzer Prepayment'; public $method_description; public $title = 'Prepayment'; public $description = ''; diff --git a/includes/gateways/Przelewy24.php b/includes/gateways/Przelewy24.php old mode 100755 new mode 100644 index 52c95d0..4e74ee3 --- a/includes/gateways/Przelewy24.php +++ b/includes/gateways/Przelewy24.php @@ -2,6 +2,7 @@ namespace UnzerPayments\Gateways; +use UnzerPayments\Gateways\Blocks\Przelewy24Block; use UnzerPayments\Services\PaymentService; if ( ! defined( 'ABSPATH' ) ) { @@ -11,6 +12,9 @@ class Przelewy24 extends AbstractGateway { const GATEWAY_ID = 'unzer_przelewy24'; + const BLOCK_CLASS = Przelewy24Block::class; + public $allowedCountries = array( 'PL' ); + public $allowedCurrencies = array( 'EUR', 'PLN' ); public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\Przelewy24::class; public $method_title = 'Unzer Przelewy24'; public $method_description; diff --git a/includes/gateways/Sofort.php b/includes/gateways/Sofort.php deleted file mode 100755 index 57d4061..0000000 --- a/includes/gateways/Sofort.php +++ /dev/null @@ -1,53 +0,0 @@ - array( - 'title' => __( 'Enable/Disable', 'unzer-payments' ), - 'label' => __( 'Enable Unzer Sofort', 'unzer-payments' ), - 'type' => 'checkbox', - 'description' => '', - 'default' => 'no', - ), - 'title' => array( - 'title' => __( 'Title', 'unzer-payments' ), - 'type' => 'text', - 'description' => __( 'This controls the title which the user sees during checkout.', 'unzer-payments' ), - 'default' => __( 'Sofort', 'unzer-payments' ), - ), - 'description' => array( - 'title' => __( 'Description', 'unzer-payments' ), - 'type' => 'text', - 'description' => __( 'This controls the description which the user sees during checkout.', 'unzer-payments' ), - 'default' => '', - ), - ) - ); - } -} diff --git a/includes/gateways/Twint.php b/includes/gateways/Twint.php index 9a45633..8efb2ab 100644 --- a/includes/gateways/Twint.php +++ b/includes/gateways/Twint.php @@ -1,6 +1,8 @@ array( + 'title' => __( 'Enable/Disable', 'unzer-payments' ), + 'label' => __( 'Enable Unzer Wero', 'unzer-payments' ), + 'type' => 'checkbox', + 'description' => '', + 'default' => 'no', + ), + 'title' => array( + 'title' => __( 'Title', 'unzer-payments' ), + 'type' => 'text', + 'description' => __( 'This controls the title which the user sees during checkout.', 'unzer-payments' ), + 'default' => __( 'Wero', 'unzer-payments' ), + ), + 'description' => array( + 'title' => __( 'Description', 'unzer-payments' ), + 'type' => 'text', + 'description' => __( 'This controls the description which the user sees during checkout.', 'unzer-payments' ), + 'default' => '', + ), + 'transaction_type' => array( + 'title' => __( 'Charge or Authorize', 'unzer-payments' ), + 'label' => '', + 'type' => 'select', + 'description' => __( 'Choose "authorize", if you you want to charge the shopper at a later point of time', 'unzer-payments' ), + 'options' => array( + AbstractGateway::TRANSACTION_TYPE_AUTHORIZE => __( 'authorize', 'unzer-payments' ), + AbstractGateway::TRANSACTION_TYPE_CHARGE => __( 'charge', 'unzer-payments' ), + ), + 'default' => 'charge', + ), + ) + ); + } + + public function process_payment( $order_id ) { + $return = array( + 'result' => 'success', + ); + if ( $this->get_option( 'transaction_type' ) === AbstractGateway::TRANSACTION_TYPE_AUTHORIZE ) { + $transaction = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, $this->paymentTypeResource ); + } else { + $transaction = ( new PaymentService() )->performChargeForOrder( $order_id, $this, $this->paymentTypeResource ); + } + + $this->before_payment_redirect( $order_id ); + + if ( $transaction->getPayment()->getRedirectUrl() ) { + $return['redirect'] = $transaction->getPayment()->getRedirectUrl(); + } + return $return; + } +} diff --git a/includes/sdk-extension/Resource/ApplePayCertificate.php b/includes/sdk-extension/Resource/ApplePayCertificate.php deleted file mode 100755 index d114976..0000000 --- a/includes/sdk-extension/Resource/ApplePayCertificate.php +++ /dev/null @@ -1,89 +0,0 @@ -format; - } - - public function setFormat( string $format ): self { - $this->format = $format; - - return $this; - } - - public function getType(): string { - return $this->type; - } - - public function setType( string $type ): self { - $this->type = $type; - - return $this; - } - - public function getPrivateKey(): ?string { - return $this->privateKey; - } - - public function setPrivateKey( string $privateKey ): self { - $this->privateKey = $privateKey; - - return $this; - } - - public function getCertificate(): ?string { - return $this->certificate; - } - - public function setCertificate( string $certificate ): self { - $this->certificate = $certificate; - - return $this; - } - - public function getActive(): ?bool { - return $this->active; - } - - public function setActive( bool $active ): self { - $this->active = $active; - - return $this; - } - - public function expose() { - $data = parent::expose(); - - if ( ! ( $data instanceof stdClass ) && array_key_exists( 'privateKey', $data ) ) { - $data['private-key'] = $data['privateKey']; - unset( $data['privateKey'] ); - } - - return $data; - } - - protected function getResourcePath( $httpMethod = HttpAdapterInterface::REQUEST_GET ): string { - return 'keypair/applepay/certificates'; - } -} diff --git a/includes/sdk-extension/Resource/ApplePayPrivateKey.php b/includes/sdk-extension/Resource/ApplePayPrivateKey.php deleted file mode 100755 index 2a00a64..0000000 --- a/includes/sdk-extension/Resource/ApplePayPrivateKey.php +++ /dev/null @@ -1,50 +0,0 @@ -format; - } - - public function setFormat( string $format ): self { - $this->format = $format; - - return $this; - } - - public function getType(): string { - return $this->type; - } - - public function setType( string $type ): self { - $this->type = $type; - - return $this; - } - - public function getCertificate(): string { - return $this->certificate; - } - - public function setCertificate( string $certificate ): self { - $this->certificate = $certificate; - - return $this; - } - - protected function getResourcePath( $httpMethod = HttpAdapterInterface::REQUEST_GET ): string { - return 'keypair/applepay/privatekeys'; - } -} diff --git a/includes/sdk-extension/Services/AppleKeyService.php b/includes/sdk-extension/Services/AppleKeyService.php deleted file mode 100644 index 893d4d1..0000000 --- a/includes/sdk-extension/Services/AppleKeyService.php +++ /dev/null @@ -1,31 +0,0 @@ -unzer = $unzer; - } - - public function activateCertificate( string $certificateId ): bool { - $certificate = ( new ApplePayCertificate() ) - ->setId( $certificateId ) - ->setParentResource( $this->unzer ); - $responseJson = $this->unzer->getHttpService()->send( - '/keypair/applepay/certificates/' . $certificateId . '/activate', - $certificate, - HttpAdapterInterface::REQUEST_POST - ); - $response = json_decode( $responseJson, true ); - return $response['active'] ?? false; - } -} diff --git a/includes/services/CustomerService.php b/includes/services/CustomerService.php old mode 100755 new mode 100644 index ca906ee..f25eaef --- a/includes/services/CustomerService.php +++ b/includes/services/CustomerService.php @@ -3,9 +3,8 @@ namespace UnzerPayments\Services; use Exception; -use UnzerPayments\Main; +use UnzerPayments\Gateways\AbstractGateway; use UnzerPayments\Util; -use UnzerSDK\Constants\CompanyRegistrationTypes; use UnzerSDK\Constants\ShippingTypes; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\EmbeddedResources\Address; @@ -16,6 +15,8 @@ class CustomerService { + public const SESSION_KEY_USER_ID = 'unzer_temp_user_id'; + /** * @var LogService */ @@ -25,28 +26,140 @@ public function __construct() { $this->logger = new LogService(); } + public function calculateCustomerNumber( ?int $customerId = null ) { + $prefix = 'wp-' . substr( md5( site_url() ), 0, 10 ) . '-'; + if ( $customerId !== null ) { + return $prefix . $customerId; + } elseif ( is_user_logged_in() ) { + return $prefix . get_current_user_id(); + } else { + static $sessionUserId; + if ( empty( $sessionUserId ) ) { + $sessionUserId = isset( $_COOKIE[ self::SESSION_KEY_USER_ID ] ) ? sanitize_text_field( $_COOKIE[ self::SESSION_KEY_USER_ID ] ) : null; + if ( empty( $sessionUserId ) ) { + $sessionUserId = uniqid(); + setcookie( self::SESSION_KEY_USER_ID, $sessionUserId, time() + 3600, COOKIEPATH, COOKIE_DOMAIN ); + WC()->session->set( self::SESSION_KEY_USER_ID, $sessionUserId ); + } + } + return 'temp-' . $prefix . $sessionUserId; + } + } + + public function getCustomerFromData( AbstractGateway $paymentGateway, array $data ) { + $customer = null; + $paymentService = new PaymentService(); + $unzer = $paymentService->getUnzerManager( $paymentGateway, ! empty( $data['billing_company'] ), get_woocommerce_currency() ); + $customerNumber = $this->calculateCustomerNumber(); + try { + $customer = $unzer->fetchCustomerByExtCustomerId( $customerNumber ); + } catch ( Exception $e ) { + // no worries, we cover this by creating a new customer + } + + if ( empty( $customer ) ) { + $customer = new Customer(); + $customer->setCustomerId( $customerNumber ); + } + + $billingAddress = $customer->getBillingAddress(); + + if ( ! empty( $data['billing_first_name'] ) && ! empty( $data['billing_last_name'] ) ) { + $customer->setFirstName( $data['billing_first_name'] ); + $customer->setLastName( $data['billing_last_name'] ); + $billingAddress->setName( $customer->getFirstname() . ' ' . $customer->getLastname() ); + } + + if ( isset( $data['billing_email'] ) ) { + $customer->setEmail( $data['billing_email'] ); + } + + $postBillingCompany = $data['billing_company'] ?? null; + + if ( $postBillingCompany !== null ) { + $updatedCompany = false; + if ( $customer->getCompany() !== $postBillingCompany ) { + $customer->setCompany( $postBillingCompany ); + $updatedCompany = true; + } + + if ( empty( $customer->getCompany() ) ) { + $customer->setCompanyInfo( null ); + } else { + $companyInfo = $customer->getCompanyInfo(); + if ( empty( $companyInfo ) ) { + $companyInfo = new CompanyInfo(); + } + if ( empty( $companyInfo->getCompanyType() ) || $updatedCompany ) { + $companyInfo->setCompanyType( 'Company Type' ); + } + $customer->setCompanyInfo( $companyInfo ); + } + } + + if ( isset( $data['billing_address_1'] ) ) { + $billingAddress->setStreet( $data['billing_address_1'] ); + } + + if ( isset( $data['billing_city'] ) ) { + $billingAddress->setCity( $data['billing_city'] ); + } + + if ( isset( $data['billing_postcode'] ) ) { + $billingAddress->setZip( $data['billing_postcode'] ); + } + + if ( isset( $data['billing_country'] ) ) { + $billingAddress->setCountry( $data['billing_country'] ); + } + + if ( ! empty( $customer->getFirstname() ) && ! empty( $customer->getLastname() ) ) { + if ( empty( $customer->getId() ) ) { + try { + $customer = $unzer->createCustomer( $customer ); + } catch ( Exception $e ) { + $this->logger->error( 'create customer failed: ' . $e->getMessage() ); + } + } else { + try { + $customer = $unzer->updateCustomer( $customer ); + } catch ( Exception $e ) { + $this->logger->error( 'update customer failed: ' . $e->getMessage() ); + } + } + } + + return $customer->getId() ? $customer : null; + } + + public function getCustomerFromSession( AbstractGateway $paymentGateway, ?int $orderId = null ): ?Customer { + if ( ! empty( $orderId ) ) { + return $this->getCustomerFromOrder( $orderId ); + } + $data = Util::getNonceCheckedBillingData(); + + return $this->getCustomerFromData( $paymentGateway, $data ); + } + + /** * @param int|WC_Order $order * @return Customer */ public function getCustomerFromOrder( $order ): Customer { - $order = is_object( $order ) ? $order : wc_get_order( $order ); - - if ( is_user_logged_in() ) { - $paymentService = new PaymentService(); - $unzer = $paymentService->getUnzerManagerForOrder( $order ); - try { - $customer = $unzer->fetchCustomerByExtCustomerId( 'wp-' . wp_get_current_user()->ID ); - } catch ( Exception $e ) { - // no worries, we cover this by creating a new customer - } + $order = is_object( $order ) ? $order : wc_get_order( $order ); + $paymentService = new PaymentService(); + $unzer = $paymentService->getUnzerManagerForOrder( $order ); + $unzerCustomerNumber = $this->calculateCustomerNumber( $order->get_customer_id() ?: null ); + try { + $customer = $unzer->fetchCustomerByExtCustomerId( $unzerCustomerNumber ); + } catch ( Exception $e ) { + // no worries, we cover this by creating a new customer } if ( empty( $customer ) ) { $customer = new Customer(); - if ( is_user_logged_in() ) { - $customer->setCustomerId( 'wp-' . wp_get_current_user()->ID ); - } + $customer->setCustomerId( $unzerCustomerNumber ); } $customer @@ -56,48 +169,26 @@ public function getCustomerFromOrder( $order ): Customer { ->setCompany( $order->get_billing_company() ?: '' ) ->setEmail( $order->get_billing_email() ?: '' ); - $this->setDateOfBirth( $customer, $order ); - $this->setCompanyInfo( $customer, $order ); $this->setAddresses( $customer, $order ); $this->logger->debug( 'customer data', array( $customer->expose() ) ); if ( $customer->getId() ) { try { - /** @noinspection PhpUndefinedVariableInspection */ $unzer->updateCustomer( $customer ); } catch ( Exception $e ) { $this->logger->warning( 'update customer failed: ' . $e->getMessage(), array( $customer->expose() ) ); } + } else { + try { + $customer = $unzer->createCustomer( $customer ); + } catch ( Exception $e ) { + $this->logger->warning( 'update customer failed: ' . $e->getMessage(), array( $customer->expose() ) ); + } } return $customer; } - protected function setDateOfBirth( Customer $customer, WC_Abstract_Order $order ) { - $dob = $order->get_meta( Main::ORDER_META_KEY_DATE_OF_BIRTH ); - if ( empty( $dob ) ) { - $dob = Util::getDobFromPost(); - } - if ( ! empty( $dob ) ) { - $customer->setBirthDate( gmdate( 'Y-m-d', strtotime( $dob ) ) ); - } - } - - protected function setCompanyInfo( Customer $customer, WC_Abstract_Order $order ) { - if ( $order->get_billing_company() ) { - $companyType = $order->get_meta( Main::ORDER_META_KEY_COMPANY_TYPE ); - if ( empty( $companyType ) ) { - $companyType = Util::getCompanyTypeFromPost(); - } - if ( ! empty( $companyType ) ) { - $companyInfo = ( new CompanyInfo() ) - ->setCompanyType( $companyType ) - ->setRegistrationType( CompanyRegistrationTypes::REGISTRATION_TYPE_NOT_REGISTERED ) - ->setFunction( 'OWNER' ); - $customer->setCompanyInfo( $companyInfo ); - } - } - } protected function setAddresses( Customer $customer, WC_Abstract_Order $order ) { $shippingType = ShippingTypes::EQUALS_BILLING; diff --git a/includes/services/DashboardService.php b/includes/services/DashboardService.php old mode 100755 new mode 100644 diff --git a/includes/services/LogService.php b/includes/services/LogService.php old mode 100755 new mode 100644 diff --git a/includes/services/OrderService.php b/includes/services/OrderService.php old mode 100755 new mode 100644 index b1abc88..a9836d1 --- a/includes/services/OrderService.php +++ b/includes/services/OrderService.php @@ -213,66 +213,6 @@ private function getDiscountFromOrderItem( $orderItem ) { return 0; } - /** - * @param int|WC_Order $order - * @return Customer - */ - public function getCustomer( $order ): Customer { - $order = is_object( $order ) ? $order : wc_get_order( $order ); - - if ( is_user_logged_in() ) { - $paymentService = new PaymentService(); - $unzer = $paymentService->getUnzerManagerForOrder( $order ); - try { - $customer = $unzer->fetchCustomerByExtCustomerId( 'wp-' . wp_get_current_user()->ID ); - } catch ( Exception $e ) { - // no worries, we cover this by creating a new customer - } - } - - if ( empty( $customer ) ) { - $customer = new Customer(); - if ( is_user_logged_in() ) { - $customer->setCustomerId( 'wp-' . wp_get_current_user()->ID ); - } - } - - $customer - ->setFirstname( $order->get_billing_first_name() ) - ->setLastname( $order->get_billing_last_name() ) - ->setPhone( $order->get_billing_phone() ) - ->setCompany( $order->get_billing_company() ) - ->setEmail( $order->get_billing_email() ); - - $dob = $order->get_meta( Main::ORDER_META_KEY_DATE_OF_BIRTH ); - if ( empty( $dob ) ) { - $dob = Util::getDobFromPost(); - } - - if ( ! empty( $dob ) ) { - $customer->setBirthDate( gmdate( 'Y-m-d', strtotime( $dob ) ) ); - } - - if ( $order->get_billing_company() ) { - $companyType = $order->get_meta( Main::ORDER_META_KEY_COMPANY_TYPE ); - if ( empty( $companyType ) ) { - $companyType = Util::getCompanyTypeFromPost(); - } - if ( ! empty( $companyType ) ) { - $companyInfo = ( new CompanyInfo() ) - ->setCompanyType( $companyType ) - ->setRegistrationType( CompanyRegistrationTypes::REGISTRATION_TYPE_NOT_REGISTERED ) - ->setFunction( 'OWNER' ); - // ->setRegistrationType(CompanyRegistrationTypes::REGISTRATION_TYPE_REGISTERED) - // ->setCommercialRegisterNumber(uniqid()); - $customer->setCompanyInfo( $companyInfo ); - } - } - - $this->setAddresses( $customer, $order ); - return $customer; - } - /** * @param Authorization|Charge $transaction * @return void @@ -352,7 +292,6 @@ public function setOrderAuthorized( WC_Order $order, ?string $transactionId = nu } public function getOrderIdFromPaymentId( $paymentId ) { - // TODO: TEST $orderId = null; if ( Util::isHPOS() ) { $orders = wc_get_orders( diff --git a/includes/services/PaymentService.php b/includes/services/PaymentService.php old mode 100755 new mode 100644 index 84095b6..86c8bcf --- a/includes/services/PaymentService.php +++ b/includes/services/PaymentService.php @@ -16,6 +16,7 @@ use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\Unzer; +use WC_Geolocation; use WC_Order; class PaymentService { @@ -27,14 +28,55 @@ public function __construct() { $this->logger = new LogService(); } + public function getPublicKey( ?AbstractGateway $paymentGateway = null, $isB2B = null, $currency = null ): string { + if ( $paymentGateway === null ) { + return get_option( 'unzer_public_key' ); + } else { + $keyTail = $this->getKeyTail( $paymentGateway, $isB2B, $currency ); + if ( $keyTail !== null ) { + $publicKey = $paymentGateway->get_option( 'public_key_' . $keyTail ); + } + if ( empty( $publicKey ) ) { + $publicKey = $paymentGateway->get_public_key(); + } + return $publicKey; + } + } + /** * @param AbstractGateway|null $paymentGateway * @return Unzer */ - public function getUnzerManager( AbstractGateway $paymentGateway = null ): Unzer { - $unzer = new Unzer( $paymentGateway ? $paymentGateway->get_private_key() : get_option( 'unzer_private_key' ) ); - $unzer->setClientIp($_SERVER['REMOTE_ADDR'] ?? null); - return $unzer; + public function getUnzerManager( ?AbstractGateway $paymentGateway = null, $isB2B = null, $currency = null ): Unzer { + if ( $paymentGateway === null ) { + $privateKey = get_option( 'unzer_private_key' ); + } else { + $keyTail = $this->getKeyTail( $paymentGateway, $isB2B, $currency ); + if ( $keyTail !== null ) { + $privateKey = $paymentGateway->get_option( 'private_key_' . $keyTail ); + } + if ( empty( $privateKey ) ) { + $privateKey = $paymentGateway->get_private_key(); + } + } + $unzer = new Unzer( $privateKey ); + $unzer->setClientIp( WC_Geolocation::get_ip_address() ?: null ); + return $unzer; + } + + protected function getKeyTail( AbstractGateway $paymentGateway, $isB2B = null, $currency = null ): ?string { + + $result = null; + if ( $paymentGateway instanceof Invoice && $currency !== null && $isB2B !== null ) { + $result = strtolower( $currency ) . '_' . ( $isB2B ? 'b2b' : 'b2c' ); + } elseif ( $paymentGateway instanceof Installment && $currency !== null ) { + // B2C only + $result = strtolower( $currency ) . '_b2c'; + } elseif ( $paymentGateway instanceof DirectDebitSecured ) { + // B2C EUR only + $result = 'eur_b2c'; + } + return $result; } /** @@ -44,34 +86,7 @@ public function getUnzerManager( AbstractGateway $paymentGateway = null ): Unzer public function getUnzerManagerForOrder( WC_Order $order = null ): Unzer { $unzerPluginManager = Main::getInstance(); $paymentGateway = $unzerPluginManager->getPaymentGateway( $order->get_payment_method() ); - $privateKey = $paymentGateway->get_private_key(); - if ( $paymentGateway instanceof Invoice ) { - $isB2B = ! empty( $order->get_billing_company() ); - $currency = $order->get_currency(); - $optionKey = 'private_key_' . strtolower( $currency ) . '_' . ( $isB2B ? 'b2b' : 'b2c' ); - $specialPrivateKey = $paymentGateway->get_option( $optionKey ); - if ( ! empty( $specialPrivateKey ) ) { - $privateKey = $specialPrivateKey; - } - } elseif ( $paymentGateway instanceof Installment ) { - // B2C only - $currency = $order->get_currency(); - $optionKey = 'private_key_' . strtolower( $currency ) . '_b2c'; - $specialPrivateKey = $paymentGateway->get_option( $optionKey ); - if ( ! empty( $specialPrivateKey ) ) { - $privateKey = $specialPrivateKey; - } - } elseif ( $paymentGateway instanceof DirectDebitSecured ) { - // B2C EUR only - $optionKey = 'private_key_eur_b2c'; - $specialPrivateKey = $paymentGateway->get_option( $optionKey ); - if ( ! empty( $specialPrivateKey ) ) { - $privateKey = $specialPrivateKey; - } - } - $unzer = new Unzer( $privateKey ); - $unzer->setClientIp($_SERVER['REMOTE_ADDR'] ?? null); - return $unzer; + return $this->getUnzerManager( $paymentGateway, ! empty( $order->get_billing_company() ), $order->get_currency() ); } public function performChargeOnAuthorization( $orderId, $amount = null ) { @@ -165,7 +180,7 @@ protected function performChargeOrAuthorizationForOrder( ) ); if ( $type === AbstractGateway::TRANSACTION_TYPE_AUTHORIZE ) { - $authorization = new Authorization( $basket->getTotalValueGross(), $basket->getCurrencyCode(), $paymentGateway->get_confirm_url() ); + $authorization = new Authorization( $basket->getTotalValueGross(), $basket->getCurrencyCode(), $paymentGateway->get_confirm_url( $orderId ) ); $authorization->setOrderId( $order->get_id() ); if ( $transactionEditor !== null ) { $transactionEditor( $authorization ); @@ -173,7 +188,7 @@ protected function performChargeOrAuthorizationForOrder( $transactionObject = $unzer->performAuthorization( $authorization, $paymentType, $customer, ( new ShopService() )->getMetadata(), $basket ); $order->update_meta_data( Main::ORDER_META_KEY_AUTHORIZATION_ID, $transactionObject->getId() ); } else { - $charge = new Charge( $basket->getTotalValueGross(), $basket->getCurrencyCode(), $paymentGateway->get_confirm_url() ); + $charge = new Charge( $basket->getTotalValueGross(), $basket->getCurrencyCode(), $paymentGateway->get_confirm_url( $orderId ) ); $charge->setOrderId( $order->get_id() ); if ( $transactionEditor !== null ) { $transactionEditor( $charge ); @@ -301,7 +316,7 @@ public function performRefundOrReversal( $orderId, AbstractGateway $paymentGatew $errorMessages[] = $e->getMessage(); } throw new Exception( - wp_kses_post( sprintf( __( 'Unable to do refund: Maximum amount for single refund is %s.', 'unzer-payments' ), html_entity_decode( wp_strip_all_tags( wc_price( $maxCaptureRefund, array( 'currency' => $payment->getCurrency() ) ) ) ) ) ) . + ( $maxCaptureRefund > 0 ? wp_kses_post( sprintf( __( 'Unable to do refund: Maximum amount for single refund is %s.', 'unzer-payments' ), html_entity_decode( wp_strip_all_tags( wc_price( $maxCaptureRefund, array( 'currency' => $payment->getCurrency() ) ) ) ) ) ) : '' ) . ( $numberOfRefundsPossible > 1 ? ' ' . esc_html( sprintf( __( 'However, you may refund in up to %s smaller chunks.', 'unzer-payments' ), $numberOfRefundsPossible ) ) : '' ) . ( $errorMessages ? "\n\n" . esc_html__( 'Original error message: ', 'unzer-payments' ) . esc_html( implode( ' ', $errorMessages ) ) : '' ) ); @@ -336,10 +351,7 @@ public function performRefundOrReversalOnPayment( $orderId, $amount ): AbstractU } } else { try { - if ( ! Util::safeCompareAmount( $payment->getAmount()->getTotal(), $amount ) ) { - throw new Exception( __( 'Reversals prior to capturing are only allowed for the full amount', 'unzer-payments' ) ); - } - return $unzer->cancelAuthorizedPayment( $paymentId ); + return $unzer->cancelAuthorizedPayment( $paymentId, new Cancellation( $amount ) ); } catch ( Exception $e ) { $this->logger->warning( 'Reversal not possible: ' . $e->getMessage() ); throw new Exception( esc_html__( 'Reversal not possible', 'unzer-payments' ) . ': ' . esc_html( $e->getMessage() ) ); diff --git a/includes/services/ShopService.php b/includes/services/ShopService.php old mode 100755 new mode 100644 diff --git a/includes/services/WebhookManagementService.php b/includes/services/WebhookManagementService.php old mode 100755 new mode 100644 diff --git a/includes/traits/SavePaymentInstrumentTrait.php b/includes/traits/SavePaymentInstrumentTrait.php old mode 100755 new mode 100644 index b76782f..df8f0e4 --- a/includes/traits/SavePaymentInstrumentTrait.php +++ b/includes/traits/SavePaymentInstrumentTrait.php @@ -59,16 +59,16 @@ public function maybeSavePaymentInstrument( $paymentInstrumentId ) { } $existingPaymentMeans[ $this->paymentTypeResource ][ $paymentInstrumentId ] = array( 'id' => $paymentInstrumentId, - 'label' => $this->getLabelForPaymentInstrument( $paymentInstrument ), + 'label' => (string) $this->getLabelForPaymentInstrument( $paymentInstrument ), ); update_user_meta( $user->ID, Main::USER_META_KEY_PAYMENT_INSTRUMENTS, $existingPaymentMeans ); } - public function getLabelForPaymentInstrument( BasePaymentType $paymentInstrument ): string { + public function getLabelForPaymentInstrument( BasePaymentType $paymentInstrument ): ?string { if ( $paymentInstrument instanceof Card ) { return $paymentInstrument->getNumber() . ' (' . $paymentInstrument->getExpiryDate() . ')'; } elseif ( $paymentInstrument instanceof Paypal ) { - return $paymentInstrument->getEmail(); + return $paymentInstrument->getEmail() ?: $paymentInstrument->getId(); } elseif ( $paymentInstrument instanceof SepaDirectDebit ) { return $paymentInstrument->getIban(); } else { diff --git a/languages/unzer-payments-de_DE.l10n.php b/languages/unzer-payments-de_DE.l10n.php new file mode 100644 index 0000000..309fa02 --- /dev/null +++ b/languages/unzer-payments-de_DE.l10n.php @@ -0,0 +1,194 @@ + null, + 'plural-forms' => 'nplurals=2; plural=(n != 1);', + 'language' => 'de_DE', + 'pot-creation-date' => '2025-09-30 22:36+0200', + 'po-revision-date' => '2025-09-30 22:37+0200', + 'translation-revision-date' => '2025-09-30 22:37+0200', + 'project-id-version' => 'Unzer Payments', + 'x-generator' => 'Poedit 3.7', + 'messages' => array( + 'General settings' => 'Allgemeine Einstellungen', + 'Keys are not valid' => 'Schlüssel sind nicht gültig', + 'Keys are valid' => 'Schlüssel sind gültig', + 'Payment Instructions' => 'Zahlungsanweisungen', + 'Totals' => 'Gesamt', + 'Detailed Transactions' => 'Detaillierte Transaktionen', + 'Time' => 'Zeit', + 'Type' => 'Typ', + 'Amount' => 'Menge', + 'Status' => 'Status', + 'Show Debug Information' => 'Debug-Informationen anzeigen', + 'Capture Amount' => 'Betrag einziehen', + 'Total amount' => 'Gesamtbetrag', + 'Charged amount' => 'Eingezogener Betrag', + 'Cancelled amount' => 'Erstatteter Betrag', + 'Remaining amount' => 'Verbleibender Betrag', + 'Chargeback' => 'Chargeback', + 'Ready to Capture' => 'Bereit zum Zahlungseinzug', + 'Waiting for payment' => 'Warten auf Zahlung', + 'Unzer Transactions' => 'Unzer-Transaktionen', + 'Unzer API settings' => 'Unzer API-Einstellungen', + 'Public Key' => 'Öffentlicher Schlüssel', + 'Private Key' => 'Privater Schlüssel', + 'Order status for authorized payments' => 'Auftragsstatus für Aufträge mit autorisierter Zahlung', + 'This status is assigned for orders, that are authorized' => 'Dieser Status wird für autorisierte Aufträge vergeben', + '[Use WooC default status]' => '[WooC-Standardstatus verwenden]', + 'Order status for captured payments' => 'Auftragsstatus für Aufträge mit eingezogener Zahlung', + 'This status is assigned for orders, that are captured' => 'Dieser Status wird für Aufträge vergeben, deren Zahlung eingezogen wurde', + 'Order status for chargebacks' => 'Auftragsstatus für Aufträge mit Chargeback', + 'This status is assigned for orders with chargebacks' => 'Dieser Status wird für Aufträge vergeben, bei denen ein Chargeback stattgefunden hat', + '[No status change]' => '[Status nicht ändern]', + 'Delete' => 'Löschen', + 'Your saved payment means' => 'Ihre gespeicherten Zahlungsarten', + 'Payment error' => 'Zahlungsfehler', + 'Payment cancelled' => 'Zahlung storniert', + 'Chargeback received' => 'Chargeback', + 'The Unzer API settings can be adjusted here' => 'Die Einstellungen der Unzer API können hier angepasst werden', + 'To start using Unzer payment methods, please enter your credentials first.
API settings' => 'Um mit den Unzer-Zahlungsmethoden zu beginnen, geben Sie bitte zunächst Ihre Anmeldedaten ein
API-Einstellungen', + 'Turning off this feature will delete all stored payment instruments of your customers. Change this setting back to "yes" if you want to keep your customers\' payment instruments.' => 'Wenn Sie diese Funktion deaktivieren, werden alle gespeicherten Zahlungsmittel Ihrer Kunden gelöscht. Ändern Sie diese Einstellung wieder auf "ja", wenn Sie die Zahlungsmittel Ihrer Kunden behalten möchten.', + 'Select another Unzer payment method' => 'Wählen Sie eine andere Unzer-Zahlungsmethode', + 'Return to payments' => 'Zurück zu den Zahlungen', + 'An error occurred while processing your payment. Please try another payment method.' => 'Bei der Bearbeitung Ihrer Zahlung ist ein Fehler aufgetreten. Bitte versuchen Sie eine andere Zahlungsmethode.', + 'Please enter your date of birth' => 'Bitte geben Sie Ihr Geburtsdatum ein', + 'Please enter your company type' => 'Bitte geben Sie Ihren Unternehmenstyp ein', + 'Please accept the SEPA mandate' => 'Bitte akzeptieren Sie das SEPA Mandat', + 'Enable/Disable' => 'Aktivieren/Deaktivieren', + 'Enable Unzer Alipay' => 'Unzer Alipay aktivieren', + 'Title' => 'Titel', + 'This controls the title which the user sees during checkout.' => 'Dies steuert den Titel, den der Kunde während des Zahlvorgangs sieht.', + 'Alipay' => 'Alipay', + 'Description' => 'Beschreibung', + 'This controls the description which the user sees during checkout.' => 'Beschreibungstext, den Benutzer bei der Auswahl dieser Zahlungsart sehen.', + 'Enable Unzer Apple Pay' => 'Aktivieren Sie Unzer Apple Pay', + 'Apple Pay' => 'Apple Pay', + 'Charge or Authorize' => 'Belasten oder autorisieren', + 'Choose "authorize", if you you want to charge the shopper at a later point of time' => 'Wählen Sie "autorisieren", wenn Sie den Käufer zu einem späteren Zeitpunkt belasten möchten', + 'authorize' => 'Autorisieren', + 'charge' => 'Belastung', + 'Enable Unzer Bancontact' => 'Unzer Bancontact aktivieren', + 'Bancontact' => 'Bancontact', + 'Enable Unzer Card Payments' => 'Unzer-Kartenzahlungen aktivieren', + 'Credit Card' => 'Kreditkarte', + 'Save card for registered customers' => 'Kreditkarten für registrierte Kunden speichern', + ' ' => ' ', + 'No' => 'Nein', + 'Yes' => 'Ja', + 'Offer Click To Pay' => 'Click To Pay anbieten', + 'By signing this mandate form, you authorize %merchant% to send instructions to your bank to debit your account and your bank to debit your account in accordance with the instructions from %merchant%. + +Note: As part of your rights, you are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited. Your rights regarding this SEPA mandate are explained in a statement that you can obtain from your bank. + +In case of refusal or rejection of direct debit payment I instruct my bank irrevocably to inform %merchant% or any third party upon request about my name, address and date of birth.' => 'Ich ermächtige %merchant%, Zahlungen von meinem Konto mittels SEPA Lastschrift einzuziehen. Zugleich weise ich mein Kreditinstitut an, die von %merchant% auf mein Konto gezogenen SEPA Lastschriften einzulösen. + +Hinweis: Ich kann innerhalb von acht Wochen, beginnend mit dem Belastungsdatum, die Erstattung des belasteten Betrags verlangen. Es gelten dabei die mit meinem Kreditinstitut vereinbarten Bedingungen. + +Für den Fall der Nichteinlösung der Lastschriften oder des Widerspruchs gegen die Lastschriften weise ich meine Bank unwiderruflich an, %merchant% oder Dritten auf Anforderung meinen Namen, Adresse und Geburtsdatum vollständig mitzuteilen.', + 'Unzer SEPA Direct Debit' => 'Unzer SEPA Lastschrift', + 'Enable Unzer SEPA Direct Debit Payments' => 'Unzer SEPA Lastschrift Zahlungen aktivieren', + 'SEPA Direct Debit' => 'SEPA Lastschrift', + 'Save bank details for registered customers' => 'Bankverbindung für registrierte Kunden speichern', + 'Unzer Direct Debit' => 'Unzer Lastschrift', + 'Enable Unzer Direct Debit Payments' => 'Unzer Lastschrift Zahlungen aktivieren', + 'Direct Debit' => 'Lastschrift', + 'Public Key EUR/B2C' => 'Öffentlicher Schlüssel EUR/B2C', + 'Private Key EUR/B2C' => 'Privater Schlüssel EUR/B2C', + 'Key Check EUR/B2C' => 'Schlüsselprüfung EUR/B2C', + 'An amount of %1$s will be deducted from your account using the descriptor \'%2$s\' according to the SEPA mandate' => 'Der Betrag in Höhe von %s wird mit der Referenz \'%s\' von Ihrem Konto in Übereinstimmung mit dem SEPA-Mandat eingezogen werden', + 'Enable Unzer EPS' => 'Unzer EPS aktivieren', + 'EPS' => 'EPS', + 'Enable Unzer Giropay' => 'Unzer Giropay aktivieren', + 'Giropay' => 'Giropay', + 'Enable Unzer Google Pay' => 'Unzer Google Pay aktivieren', + 'Google Pay' => 'Google Pay', + 'Gateway Merchant ID' => 'Gateway Merchant ID', + 'Merchant ID' => 'Merchant ID', + 'Merchant Name' => 'Merchant Name', + 'Country Code' => 'Länder-Code', + 'Country code of the acquirer' => 'Land des Acquirers', + 'DK (default)' => 'DK (Standard)', + 'Allow Credit Cards' => 'Kreditkarten zulassen', + 'Allow Prepaid Cards' => 'Prepaid Karten zulassen', + 'Allowed Card Networks' => 'Zugelassene Kreditkarten-Anbieter', + 'Button Color' => 'Farbe des Buttons', + 'Google\'s default' => 'Standard', + 'Black' => 'Schwarz', + 'White' => 'Weiß', + 'Button Size Mode' => 'Größe des Buttons', + 'Full Width' => 'Volle Breite', + 'Static' => 'Statisch (kleiner)', + 'Enable Unzer iDEAL' => 'Aktivieren Sie Unzer iDEAL', + 'iDEAL' => 'iDEAL', + 'Unzer Installment' => 'Unzer Ratenzahlung', + 'Enable Unzer Installment' => 'Unzer Ratenkauf aktivieren', + 'Installment' => 'Ratenkauf', + 'Public Key CHF/B2C' => 'Öffentlicher Schlüssel CHF/B2C', + 'Private Key CHF/B2C' => 'Privater Schlüssel CHF/B2C', + 'Key Check CHF/B2C' => 'Schlüsselprüfung CHF/B2C', + 'Payment details:

Holder: %s
IBAN: %s
BIC: %s

Descriptor:
%s' => 'Zahlungsangaben:

Inhaber: %s
IBAN: %s
BIC: %s

Deskriptor :
%s', + 'Unzer Invoice' => 'Unzer Rechnung', + 'Enable Unzer Invoice' => 'Unzer Rechnung aktivieren', + 'Invoice' => 'Rechnungskauf', + 'Public Key EUR/B2B' => 'Öffentlicher Schlüssel EUR/B2B', + 'Private Key EUR/B2B' => 'Privater Schlüssel EUR/B2B', + 'Key Check EUR/B2B' => 'Schlüsselprüfung EUR/B2B', + 'Public Key CHF/B2B' => 'Öffentlicher Schlüssel CHF/B2B', + 'Private Key CHF/B2B' => 'Privater Schlüssel CHF/B2B', + 'Key Check CHF/B2B' => 'Schlüsselprüfung CHF/B2B', + 'Type of company' => 'Art des Unternehmens', + 'Association' => 'Gesellschaft', + 'Authority' => 'Behörde', + 'Company' => 'Firma', + 'Sole' => 'Einzelunternehmen', + 'Other' => 'Sonstiges', + 'Please transfer the amount of %s to the following account:

Holder: %s
IBAN: %s
BIC: %s

Please use only this identification number as the descriptor:
%s' => 'Bitte überweisen Sie den Betrag von %s auf das folgende Konto:

Inhaber: %s
IBAN: %s
BIC: %s

Bitte verwenden Sie nur diese Identifikationsnummer als Bezeichnung
%s', + 'Enable Unzer Klarna' => 'Unzer Klarna aktivieren', + 'Klarna' => 'Klarna', + 'Enable Unzer Direct Bank Transfer' => 'Unzer Direktüberweisung aktivieren', + 'Direct Bank Transfer' => 'Direktüberweisung', + 'Enable Unzer PayPal' => 'Aktivieren Sie Unzer PayPal', + 'PayPal' => 'PayPal', + 'Save PayPAl account for registered customers' => 'PayPal-Konto für registrierte Kunden speichern', + 'Enable Unzer Bank Transfer' => 'Unzer Banküberweisung aktivieren', + 'Bank Transfer' => 'Banküberweisung', + 'Enable Unzer Post Finance Card' => 'Unzer Post Finance Card aktivieren', + 'Post Finance Card' => 'Post Finance Card', + 'Enable Unzer Post Finance eFinance' => 'Unzer Post Finance eFinance aktivieren', + 'Post Finance eFinance' => 'Post Finance eFinance', + 'Enable Unzer Prepayment' => 'Unzer Vorauszahlung aktivieren', + 'Prepayment' => 'Vorauszahlung', + 'Order status' => 'Bestellstatus', + 'This status is assigned to all orders created with this payment method' => 'Dieser Status wird allen Bestellungen zugewiesen, die mit dieser Zahlungsmethode erstellt werden', + 'Enable Unzer Przelewy24' => 'Unzer Przelewy24 aktivieren', + 'Przelewy24' => 'Przelewy24', + 'Enable Unzer Sofort' => 'Unzer Sofort Aktivieren', + 'Sofort' => 'Sofort', + 'Enable Unzer TWINT' => 'Unzer TWINT aktivieren', + 'TWINT' => 'TWINT', + 'Enable Unzer WeChat Pay' => 'Aktivieren Sie Unzer WeChat Pay', + 'WeChat Pay' => 'WeChat Bezahlen', + 'Enable Unzer Wero' => 'Unzer Wero aktivieren', + 'Wero' => 'Wero', + 'A chargeback has been received. Please check the payment details for order %s' => 'Es hat ein Chargeback bei Bestellung %s stattgefunden. Bitte überprüfen Sie diesen Fall.', + 'Could not create apple-developer-merchantid-domain-association file' => 'DIe Apple Domain Datei konnte nicht erstellt werden', + 'Dismiss this notification' => 'Ausblenden', + 'Payment complete event failed.' => 'Abschluss der Zahlung ist fehlgeschlagen.', + 'Installment payment is only available for shipping and billing address with the same name' => 'Ratenzahlung ist nur möglich, wenn Liefer- und Rechnungsadresse denselben Namen haben', + 'Unzer Payment ID: ' => 'Unzer Payment ID: ', + 'Unable to do refund: Maximum amount for single refund is %s.' => 'Erstattung nicht möglich: Maximaler Betrag für eine einzelne Erstattung ist %s.', + 'However, you may refund in up to %s smaller chunks.' => 'Es ist jedoch möglich bis zu %s einzelne Erstattungen vorzunehmen.', + 'Original error message: ' => 'Ursprüngliche Fehlermeldung: ', + 'Refund not possible' => 'Rückerstattung nicht möglich', + 'Reversals prior to capturing are only allowed for the full amount' => 'Stornierungen vor Zahlungseinzug sind nur in Höhe des vollen Betrags möglich', + 'Reversal not possible' => 'Stornierung nicht möglich', + 'Save this for my next purchase' => 'Für meinen nächsten Einkauf speichern', + 'Use another one' => 'Andere', + 'Unzer requires WooCommerce to be installed and active.' => 'WooCommerce muss installiert und aktiv sein.', + 'Unzer Payments' => 'Unzer Payments', + 'Official Unzer Plugin' => 'Das offizielle Unzer Plugin', + 'Unzer' => 'Unzer', + 'https://www.unzer.com' => 'https://www.unzer.com', + ), +); diff --git a/languages/unzer-payments-de_DE.mo b/languages/unzer-payments-de_DE.mo index 37b0b9e..1792da4 100755 Binary files a/languages/unzer-payments-de_DE.mo and b/languages/unzer-payments-de_DE.mo differ diff --git a/languages/unzer-payments-de_DE.po b/languages/unzer-payments-de_DE.po index ff2b339..9c161d7 100755 --- a/languages/unzer-payments-de_DE.po +++ b/languages/unzer-payments-de_DE.po @@ -1,63 +1,36 @@ msgid "" msgstr "" "Project-Id-Version: Unzer Payments\n" -"POT-Creation-Date: 2025-02-10 12:27+0100\n" -"PO-Revision-Date: 2025-02-10 12:30+0100\n" +"POT-Creation-Date: 2025-09-30 22:36+0200\n" +"PO-Revision-Date: 2025-09-30 22:37+0200\n" "Last-Translator: \n" "Language-Team: \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 3.5\n" +"X-Generator: Poedit 3.7\n" "X-Poedit-Basepath: ..\n" "X-Poedit-Flags-xgettext: --add-comments=translators:\n" "X-Poedit-WPHeader: unzer-payments.php\n" "X-Poedit-SourceCharset: UTF-8\n" -"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;" -"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;" -"_nx_noop:3c,1,2;__ngettext_noop:1,2\n" +"X-Poedit-KeywordsList: " +"__;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n" "X-Poedit-SearchPath-0: .\n" "X-Poedit-SearchPathExcluded-0: *.min.js\n" "X-Poedit-SearchPathExcluded-1: vendor\n" -#: html/admin/apple-pay-settings.php:24 -msgid "Apple Pay certificate settings" -msgstr "Einstellungen für Apple Pay-Zertifikate" - -#: html/admin/apple-pay-settings.php:30 -msgid "Payment Processing Certificate (apple_pay.pem)" -msgstr "Payment Processing Zertifikat (apple_pay.pem)" - -#: html/admin/apple-pay-settings.php:42 html/admin/apple-pay-settings.php:63 -#: html/admin/apple-pay-settings.php:82 html/admin/apple-pay-settings.php:101 -#: includes/controllers/AccountController.php:58 -msgid "Delete" -msgstr "Löschen" - -#: html/admin/apple-pay-settings.php:49 -msgid "Payment Processing Key (privatekey.key)" -msgstr "Payment Processing Key (privatekey.key)" - -#: html/admin/apple-pay-settings.php:70 -msgid "Merchant Identification Certificate (merchant_id.pem)" -msgstr "Merchant Identification Zertifikat (merchant_id.pem)" - -#: html/admin/apple-pay-settings.php:89 -msgid "Merchant Identification Key (merchant_id.key)" -msgstr "Merchant Identification Key (merchant_id.key))" - #: html/admin/global-settings-start.php:10 msgid "General settings" msgstr "Allgemeine Einstellungen" #: html/admin/global-settings-start.php:29 -#: includes/gateways/AbstractGateway.php:209 +#: includes/gateways/AbstractGateway.php:317 msgid "Keys are not valid" msgstr "Schlüssel sind nicht gültig" #: html/admin/global-settings-start.php:31 -#: includes/gateways/AbstractGateway.php:210 +#: includes/gateways/AbstractGateway.php:318 msgid "Keys are valid" msgstr "Schlüssel sind gültig" @@ -113,118 +86,85 @@ msgstr "Erstatteter Betrag" msgid "Remaining amount" msgstr "Verbleibender Betrag" -#: includes/Main.php:157 includes/Main.php:190 +#: includes/Main.php:149 includes/Main.php:182 msgid "Chargeback" msgstr "Chargeback" -#: includes/Main.php:167 includes/Main.php:191 +#: includes/Main.php:159 includes/Main.php:183 msgid "Ready to Capture" msgstr "Bereit zum Zahlungseinzug" -#: includes/Main.php:177 includes/Main.php:192 +#: includes/Main.php:169 includes/Main.php:184 msgid "Waiting for payment" msgstr "Warten auf Zahlung" -#: includes/Main.php:304 +#: includes/Main.php:253 msgid "Unzer Transactions" msgstr "Unzer-Transaktionen" -#: includes/Main.php:308 +#: includes/Main.php:257 msgid "Unzer API settings" msgstr "Unzer API-Einstellungen" -#: includes/Main.php:327 +#: includes/Main.php:276 msgid "Public Key" msgstr "Öffentlicher Schlüssel" -#: includes/Main.php:335 +#: includes/Main.php:284 msgid "Private Key" msgstr "Privater Schlüssel" -#: includes/Main.php:343 +#: includes/Main.php:292 msgid "Order status for authorized payments" msgstr "Auftragsstatus für Aufträge mit autorisierter Zahlung" -#: includes/Main.php:346 +#: includes/Main.php:295 msgid "This status is assigned for orders, that are authorized" msgstr "Dieser Status wird für autorisierte Aufträge vergeben" -#: includes/Main.php:347 includes/Main.php:357 +#: includes/Main.php:296 includes/Main.php:306 #: includes/gateways/Prepayment.php:58 msgid "[Use WooC default status]" msgstr "[WooC-Standardstatus verwenden]" -#: includes/Main.php:353 +#: includes/Main.php:302 msgid "Order status for captured payments" msgstr "Auftragsstatus für Aufträge mit eingezogener Zahlung" -#: includes/Main.php:356 +#: includes/Main.php:305 msgid "This status is assigned for orders, that are captured" msgstr "" "Dieser Status wird für Aufträge vergeben, deren Zahlung eingezogen wurde" -#: includes/Main.php:363 +#: includes/Main.php:312 msgid "Order status for chargebacks" msgstr "Auftragsstatus für Aufträge mit Chargeback" -#: includes/Main.php:366 +#: includes/Main.php:315 msgid "This status is assigned for orders with chargebacks" msgstr "" "Dieser Status wird für Aufträge vergeben, bei denen ein Chargeback " "stattgefunden hat" -#: includes/Main.php:367 +#: includes/Main.php:316 msgid "[No status change]" msgstr "[Status nicht ändern]" +#: includes/controllers/AccountController.php:58 +msgid "Delete" +msgstr "Löschen" + #: includes/controllers/AccountController.php:64 msgid "Your saved payment means" msgstr "Ihre gespeicherten Zahlungsarten" -#: includes/controllers/AdminController.php:253 -#: includes/controllers/AdminController.php:254 -#: includes/controllers/AdminController.php:255 -#: includes/controllers/AdminController.php:256 -msgid "invalid" -msgstr "ungültig" - -#: includes/controllers/AdminController.php:269 -msgid "The certificate is not active" -msgstr "Das Zertifikat ist nicht aktiviert" - -#: includes/controllers/AdminController.php:272 -#: includes/controllers/AdminController.php:313 -#: includes/controllers/AdminController.php:331 -msgid "valid" -msgstr "gültig" - -#: includes/controllers/AdminController.php:304 -msgid "Unable to read certificate" -msgstr "Zertifikat kann nicht gelesen werden" - -#: includes/controllers/AdminController.php:307 -msgid "Certificate does not match merchant id: " -msgstr "Das Zertifikat stimmt nicht mit der Merchant ID überein: " - -#: includes/controllers/AdminController.php:310 -msgid "Not a valid certificate" -msgstr "Kein gültiges Zertifikat" - -#: includes/controllers/AdminController.php:325 -msgid "Key does not match certificate" -msgstr "Schlüssel stimmt nicht mit Zertifikat überein" - -#: includes/controllers/AdminController.php:328 -msgid "Not a valid private key" -msgstr "Kein gültiger privater Schlüssel" - -#: includes/controllers/CheckoutController.php:42 -#: includes/controllers/CheckoutController.php:52 -#: includes/controllers/CheckoutController.php:90 +#: includes/controllers/CheckoutController.php:35 +#: includes/controllers/CheckoutController.php:45 +#: includes/controllers/CheckoutController.php:83 msgid "Payment error" msgstr "Zahlungsfehler" -#: includes/controllers/CheckoutController.php:67 +#: includes/controllers/CheckoutController.php:60 msgid "Payment cancelled" msgstr "Zahlung storniert" @@ -232,14 +172,14 @@ msgstr "Zahlung storniert" msgid "Chargeback received" msgstr "Chargeback" -#: includes/gateways/AbstractGateway.php:53 +#: includes/gateways/AbstractGateway.php:104 #, php-format msgid "The Unzer API settings can be adjusted here" msgstr "" "Die Einstellungen der Unzer API können hier angepasst " "werden" -#: includes/gateways/AbstractGateway.php:55 +#: includes/gateways/AbstractGateway.php:106 #, php-format msgid "" "To start using Unzer payment methods, please enter your credentials first. " @@ -249,7 +189,7 @@ msgstr "" "Anmeldedaten ein
API-" "Einstellungen" -#: includes/gateways/AbstractGateway.php:167 +#: includes/gateways/AbstractGateway.php:275 msgid "" "Turning off this feature will delete all stored payment instruments of your " "customers. Change this setting back to \"yes\" if you want to keep your " @@ -259,23 +199,15 @@ msgstr "" "Zahlungsmittel Ihrer Kunden gelöscht. Ändern Sie diese Einstellung wieder " "auf \"ja\", wenn Sie die Zahlungsmittel Ihrer Kunden behalten möchten." -#: includes/gateways/AbstractGateway.php:174 +#: includes/gateways/AbstractGateway.php:282 msgid "Select another Unzer payment method" msgstr "Wählen Sie eine andere Unzer-Zahlungsmethode" -#: includes/gateways/AbstractGateway.php:175 +#: includes/gateways/AbstractGateway.php:283 msgid "Return to payments" msgstr "Zurück zu den Zahlungen" -#: includes/gateways/AbstractGateway.php:289 -msgid "You have to be at least 18 years old for this payment method" -msgstr "Für diese Zahlungsmethode müssen Sie mindestens 18 Jahre alt sein" - -#: includes/gateways/AbstractGateway.php:292 -msgid "Please check your date of birth" -msgstr "Bitte überprüfen Sie Ihr Geburtsdatum" - -#: includes/gateways/AbstractGateway.php:356 +#: includes/gateways/AbstractGateway.php:436 msgid "" "An error occurred while processing your payment. Please try another payment " "method." @@ -283,124 +215,122 @@ msgstr "" "Bei der Bearbeitung Ihrer Zahlung ist ein Fehler aufgetreten. Bitte " "versuchen Sie eine andere Zahlungsmethode." -#: includes/gateways/AbstractGateway.php:385 +#: includes/gateways/AbstractGateway.php:465 msgid "Please enter your date of birth" msgstr "Bitte geben Sie Ihr Geburtsdatum ein" -#: includes/gateways/AbstractGateway.php:386 includes/gateways/Invoice.php:204 +#: includes/gateways/AbstractGateway.php:466 includes/gateways/Invoice.php:215 msgid "Please enter your company type" msgstr "Bitte geben Sie Ihren Unternehmenstyp ein" -#: includes/gateways/AbstractGateway.php:387 +#: includes/gateways/AbstractGateway.php:467 msgid "Please accept the SEPA mandate" msgstr "Bitte akzeptieren Sie das SEPA Mandat" -#: includes/gateways/Alipay.php:32 includes/gateways/ApplePay.php:62 -#: includes/gateways/ApplePayV2.php:61 includes/gateways/Bancontact.php:32 -#: includes/gateways/Card.php:100 includes/gateways/DirectDebit.php:107 -#: includes/gateways/DirectDebitSecured.php:73 includes/gateways/Eps.php:33 -#: includes/gateways/Giropay.php:35 includes/gateways/GooglePay.php:96 -#: includes/gateways/Ideal.php:50 includes/gateways/Installment.php:75 -#: includes/gateways/Invoice.php:47 includes/gateways/Klarna.php:32 -#: includes/gateways/OpenBanking.php:59 includes/gateways/Paypal.php:51 -#: includes/gateways/Pis.php:32 includes/gateways/PostFinanceCard.php:31 -#: includes/gateways/PostFinanceEfinance.php:31 -#: includes/gateways/Prepayment.php:35 includes/gateways/Przelewy24.php:32 +#: includes/gateways/Alipay.php:34 includes/gateways/ApplePayV2.php:60 +#: includes/gateways/Bancontact.php:34 includes/gateways/Card.php:70 +#: includes/gateways/DirectDebit.php:85 +#: includes/gateways/DirectDebitSecured.php:78 includes/gateways/Eps.php:35 +#: includes/gateways/Giropay.php:35 includes/gateways/GooglePay.php:94 +#: includes/gateways/Ideal.php:34 includes/gateways/Installment.php:83 +#: includes/gateways/Invoice.php:47 includes/gateways/Klarna.php:140 +#: includes/gateways/OpenBanking.php:65 includes/gateways/Paypal.php:51 +#: includes/gateways/Pis.php:32 includes/gateways/PostFinanceCard.php:32 +#: includes/gateways/PostFinanceEfinance.php:32 +#: includes/gateways/Prepayment.php:35 includes/gateways/Przelewy24.php:34 #: includes/gateways/Sofort.php:32 includes/gateways/Twint.php:32 -#: includes/gateways/WeChatPay.php:32 +#: includes/gateways/WeChatPay.php:34 includes/gateways/Wero.php:32 msgid "Enable/Disable" msgstr "Aktivieren/Deaktivieren" -#: includes/gateways/Alipay.php:33 +#: includes/gateways/Alipay.php:35 msgid "Enable Unzer Alipay" msgstr "Unzer Alipay aktivieren" -#: includes/gateways/Alipay.php:39 includes/gateways/ApplePay.php:69 -#: includes/gateways/ApplePayV2.php:68 includes/gateways/Bancontact.php:39 -#: includes/gateways/Card.php:107 includes/gateways/DirectDebit.php:114 -#: includes/gateways/DirectDebitSecured.php:80 includes/gateways/Eps.php:40 -#: includes/gateways/Giropay.php:42 includes/gateways/GooglePay.php:103 -#: includes/gateways/Ideal.php:57 includes/gateways/Installment.php:82 -#: includes/gateways/Invoice.php:54 includes/gateways/Klarna.php:39 -#: includes/gateways/OpenBanking.php:66 includes/gateways/Paypal.php:58 -#: includes/gateways/Pis.php:39 includes/gateways/PostFinanceCard.php:38 -#: includes/gateways/PostFinanceEfinance.php:38 -#: includes/gateways/Prepayment.php:42 includes/gateways/Przelewy24.php:39 +#: includes/gateways/Alipay.php:41 includes/gateways/ApplePayV2.php:67 +#: includes/gateways/Bancontact.php:41 includes/gateways/Card.php:77 +#: includes/gateways/DirectDebit.php:92 +#: includes/gateways/DirectDebitSecured.php:85 includes/gateways/Eps.php:42 +#: includes/gateways/Giropay.php:42 includes/gateways/GooglePay.php:101 +#: includes/gateways/Ideal.php:41 includes/gateways/Installment.php:90 +#: includes/gateways/Invoice.php:54 includes/gateways/Klarna.php:147 +#: includes/gateways/OpenBanking.php:72 includes/gateways/Paypal.php:58 +#: includes/gateways/Pis.php:39 includes/gateways/PostFinanceCard.php:39 +#: includes/gateways/PostFinanceEfinance.php:39 +#: includes/gateways/Prepayment.php:42 includes/gateways/Przelewy24.php:41 #: includes/gateways/Sofort.php:39 includes/gateways/Twint.php:39 -#: includes/gateways/WeChatPay.php:39 +#: includes/gateways/WeChatPay.php:41 includes/gateways/Wero.php:39 msgid "Title" msgstr "Titel" -#: includes/gateways/Alipay.php:41 includes/gateways/ApplePay.php:71 -#: includes/gateways/ApplePayV2.php:70 includes/gateways/Bancontact.php:41 -#: includes/gateways/Card.php:109 includes/gateways/DirectDebit.php:116 -#: includes/gateways/DirectDebitSecured.php:82 includes/gateways/Eps.php:42 -#: includes/gateways/Giropay.php:44 includes/gateways/GooglePay.php:105 -#: includes/gateways/Ideal.php:59 includes/gateways/Installment.php:84 -#: includes/gateways/Invoice.php:56 includes/gateways/Klarna.php:41 -#: includes/gateways/OpenBanking.php:68 includes/gateways/Paypal.php:60 -#: includes/gateways/Pis.php:41 includes/gateways/PostFinanceCard.php:40 -#: includes/gateways/PostFinanceEfinance.php:40 -#: includes/gateways/Prepayment.php:44 includes/gateways/Przelewy24.php:41 +#: includes/gateways/Alipay.php:43 includes/gateways/ApplePayV2.php:69 +#: includes/gateways/Bancontact.php:43 includes/gateways/Card.php:79 +#: includes/gateways/DirectDebit.php:94 +#: includes/gateways/DirectDebitSecured.php:87 includes/gateways/Eps.php:44 +#: includes/gateways/Giropay.php:44 includes/gateways/GooglePay.php:103 +#: includes/gateways/Ideal.php:43 includes/gateways/Installment.php:92 +#: includes/gateways/Invoice.php:56 includes/gateways/Klarna.php:149 +#: includes/gateways/OpenBanking.php:74 includes/gateways/Paypal.php:60 +#: includes/gateways/Pis.php:41 includes/gateways/PostFinanceCard.php:41 +#: includes/gateways/PostFinanceEfinance.php:41 +#: includes/gateways/Prepayment.php:44 includes/gateways/Przelewy24.php:43 #: includes/gateways/Sofort.php:41 includes/gateways/Twint.php:41 -#: includes/gateways/WeChatPay.php:41 +#: includes/gateways/WeChatPay.php:43 includes/gateways/Wero.php:41 msgid "This controls the title which the user sees during checkout." msgstr "Dies steuert den Titel, den der Kunde während des Zahlvorgangs sieht." -#: includes/gateways/Alipay.php:42 +#: includes/gateways/Alipay.php:44 msgid "Alipay" msgstr "Alipay" -#: includes/gateways/Alipay.php:45 includes/gateways/ApplePay.php:75 -#: includes/gateways/ApplePayV2.php:74 includes/gateways/Bancontact.php:45 -#: includes/gateways/Card.php:113 includes/gateways/DirectDebit.php:120 -#: includes/gateways/DirectDebitSecured.php:86 includes/gateways/Eps.php:46 -#: includes/gateways/Giropay.php:48 includes/gateways/GooglePay.php:109 -#: includes/gateways/Ideal.php:63 includes/gateways/Installment.php:88 -#: includes/gateways/Invoice.php:60 includes/gateways/Klarna.php:45 -#: includes/gateways/OpenBanking.php:72 includes/gateways/Paypal.php:64 -#: includes/gateways/Pis.php:45 includes/gateways/PostFinanceCard.php:44 -#: includes/gateways/PostFinanceEfinance.php:44 -#: includes/gateways/Prepayment.php:48 includes/gateways/Przelewy24.php:45 +#: includes/gateways/Alipay.php:47 includes/gateways/ApplePayV2.php:73 +#: includes/gateways/Bancontact.php:47 includes/gateways/Card.php:83 +#: includes/gateways/DirectDebit.php:98 +#: includes/gateways/DirectDebitSecured.php:91 includes/gateways/Eps.php:48 +#: includes/gateways/Giropay.php:48 includes/gateways/GooglePay.php:107 +#: includes/gateways/Ideal.php:47 includes/gateways/Installment.php:96 +#: includes/gateways/Invoice.php:60 includes/gateways/Klarna.php:153 +#: includes/gateways/OpenBanking.php:78 includes/gateways/Paypal.php:64 +#: includes/gateways/Pis.php:45 includes/gateways/PostFinanceCard.php:45 +#: includes/gateways/PostFinanceEfinance.php:45 +#: includes/gateways/Prepayment.php:48 includes/gateways/Przelewy24.php:47 #: includes/gateways/Sofort.php:45 includes/gateways/Twint.php:45 -#: includes/gateways/WeChatPay.php:45 +#: includes/gateways/WeChatPay.php:47 includes/gateways/Wero.php:45 msgid "Description" msgstr "Beschreibung" -#: includes/gateways/Alipay.php:47 includes/gateways/ApplePay.php:77 -#: includes/gateways/ApplePayV2.php:76 includes/gateways/Bancontact.php:47 -#: includes/gateways/Card.php:115 includes/gateways/DirectDebit.php:122 -#: includes/gateways/DirectDebitSecured.php:88 includes/gateways/Eps.php:48 -#: includes/gateways/Giropay.php:50 includes/gateways/GooglePay.php:111 -#: includes/gateways/Ideal.php:65 includes/gateways/Installment.php:90 -#: includes/gateways/Invoice.php:62 includes/gateways/Klarna.php:47 -#: includes/gateways/OpenBanking.php:74 includes/gateways/Paypal.php:66 -#: includes/gateways/Pis.php:47 includes/gateways/PostFinanceCard.php:46 -#: includes/gateways/PostFinanceEfinance.php:46 -#: includes/gateways/Prepayment.php:50 includes/gateways/Przelewy24.php:47 +#: includes/gateways/Alipay.php:49 includes/gateways/ApplePayV2.php:75 +#: includes/gateways/Bancontact.php:49 includes/gateways/Card.php:85 +#: includes/gateways/DirectDebit.php:100 +#: includes/gateways/DirectDebitSecured.php:93 includes/gateways/Eps.php:50 +#: includes/gateways/Giropay.php:50 includes/gateways/GooglePay.php:109 +#: includes/gateways/Ideal.php:49 includes/gateways/Installment.php:98 +#: includes/gateways/Invoice.php:62 includes/gateways/Klarna.php:155 +#: includes/gateways/OpenBanking.php:80 includes/gateways/Paypal.php:66 +#: includes/gateways/Pis.php:47 includes/gateways/PostFinanceCard.php:47 +#: includes/gateways/PostFinanceEfinance.php:47 +#: includes/gateways/Prepayment.php:50 includes/gateways/Przelewy24.php:49 #: includes/gateways/Sofort.php:47 includes/gateways/Twint.php:47 -#: includes/gateways/WeChatPay.php:47 +#: includes/gateways/WeChatPay.php:49 includes/gateways/Wero.php:47 msgid "This controls the description which the user sees during checkout." msgstr "" "Beschreibungstext, den Benutzer bei der Auswahl dieser Zahlungsart sehen." -#: includes/gateways/ApplePay.php:63 includes/gateways/ApplePayV2.php:62 +#: includes/gateways/ApplePayV2.php:61 msgid "Enable Unzer Apple Pay" msgstr "Aktivieren Sie Unzer Apple Pay" -#: includes/gateways/ApplePay.php:72 includes/gateways/ApplePayV2.php:71 +#: includes/gateways/ApplePayV2.php:70 msgid "Apple Pay" msgstr "Apple Pay" -#: includes/gateways/ApplePay.php:81 includes/gateways/ApplePayV2.php:80 -#: includes/gateways/Card.php:119 includes/gateways/GooglePay.php:115 -#: includes/gateways/Paypal.php:70 +#: includes/gateways/ApplePayV2.php:79 includes/gateways/Card.php:89 +#: includes/gateways/GooglePay.php:113 includes/gateways/Paypal.php:70 msgid "Charge or Authorize" msgstr "Belasten oder autorisieren" -#: includes/gateways/ApplePay.php:84 includes/gateways/ApplePayV2.php:83 -#: includes/gateways/Card.php:122 includes/gateways/GooglePay.php:118 -#: includes/gateways/Paypal.php:73 +#: includes/gateways/ApplePayV2.php:82 includes/gateways/Card.php:92 +#: includes/gateways/GooglePay.php:116 includes/gateways/Paypal.php:73 msgid "" "Choose \"authorize\", if you you want to charge the shopper at a later point " "of time" @@ -408,57 +338,55 @@ msgstr "" "Wählen Sie \"autorisieren\", wenn Sie den Käufer zu einem späteren Zeitpunkt " "belasten möchten" -#: includes/gateways/ApplePay.php:86 includes/gateways/ApplePayV2.php:85 -#: includes/gateways/Card.php:124 includes/gateways/GooglePay.php:120 -#: includes/gateways/Paypal.php:75 +#: includes/gateways/ApplePayV2.php:84 includes/gateways/Card.php:94 +#: includes/gateways/GooglePay.php:118 includes/gateways/Paypal.php:75 msgid "authorize" msgstr "Autorisieren" -#: includes/gateways/ApplePay.php:87 includes/gateways/ApplePayV2.php:86 -#: includes/gateways/Card.php:125 includes/gateways/GooglePay.php:121 -#: includes/gateways/Paypal.php:76 +#: includes/gateways/ApplePayV2.php:85 includes/gateways/Card.php:95 +#: includes/gateways/GooglePay.php:119 includes/gateways/Paypal.php:76 msgid "charge" msgstr "Belastung" -#: includes/gateways/ApplePay.php:92 includes/gateways/GooglePay.php:132 -msgid "Merchant ID" -msgstr "Merchant ID" - -#: includes/gateways/Bancontact.php:33 +#: includes/gateways/Bancontact.php:35 msgid "Enable Unzer Bancontact" msgstr "Unzer Bancontact aktivieren" -#: includes/gateways/Bancontact.php:42 +#: includes/gateways/Bancontact.php:44 msgid "Bancontact" msgstr "Bancontact" -#: includes/gateways/Card.php:101 +#: includes/gateways/Card.php:71 msgid "Enable Unzer Card Payments" msgstr "Unzer-Kartenzahlungen aktivieren" -#: includes/gateways/Card.php:110 +#: includes/gateways/Card.php:80 msgid "Credit Card" msgstr "Kreditkarte" -#: includes/gateways/Card.php:130 +#: includes/gateways/Card.php:100 msgid "Save card for registered customers" msgstr "Kreditkarten für registrierte Kunden speichern" -#: includes/gateways/Card.php:131 includes/gateways/DirectDebit.php:134 -#: includes/gateways/Paypal.php:82 +#: includes/gateways/Card.php:101 includes/gateways/Card.php:112 +#: includes/gateways/DirectDebit.php:105 includes/gateways/Paypal.php:82 msgid " " msgstr " " -#: includes/gateways/Card.php:136 includes/gateways/DirectDebit.php:139 -#: includes/gateways/Paypal.php:87 +#: includes/gateways/Card.php:106 includes/gateways/Card.php:117 +#: includes/gateways/DirectDebit.php:110 includes/gateways/Paypal.php:87 msgid "No" msgstr "Nein" -#: includes/gateways/Card.php:137 includes/gateways/DirectDebit.php:140 -#: includes/gateways/Paypal.php:88 +#: includes/gateways/Card.php:107 includes/gateways/Card.php:118 +#: includes/gateways/DirectDebit.php:111 includes/gateways/Paypal.php:88 msgid "Yes" msgstr "Ja" +#: includes/gateways/Card.php:111 +msgid "Offer Click To Pay" +msgstr "Click To Pay anbieten" + #: includes/gateways/DirectDebit.php:37 msgid "" "By signing this mandate form, you authorize %merchant% to send instructions " @@ -492,67 +420,46 @@ msgstr "" msgid "Unzer SEPA Direct Debit" msgstr "Unzer SEPA Lastschrift" -#: includes/gateways/DirectDebit.php:73 -msgid "I accept the SEPA mandate" -msgstr "Ich akzeptiere das SEPA Mandat" - -#: includes/gateways/DirectDebit.php:75 -msgid "(read more)" -msgstr "(mehr lesen)" - -#: includes/gateways/DirectDebit.php:108 +#: includes/gateways/DirectDebit.php:86 msgid "Enable Unzer SEPA Direct Debit Payments" msgstr "Unzer SEPA Lastschrift Zahlungen aktivieren" -#: includes/gateways/DirectDebit.php:117 +#: includes/gateways/DirectDebit.php:95 msgid "SEPA Direct Debit" msgstr "SEPA Lastschrift" -#: includes/gateways/DirectDebit.php:126 -msgid "Alternative SEPA mandate description" -msgstr "Eigener Text fuer Akzeptanz des SEPA Mandats" - -#: includes/gateways/DirectDebit.php:128 -msgid "Leave empty to display the default text" -msgstr "Leer lassen für Standard-Vorlage" - -#: includes/gateways/DirectDebit.php:133 +#: includes/gateways/DirectDebit.php:104 msgid "Save bank details for registered customers" msgstr "Bankverbindung für registrierte Kunden speichern" -#: includes/gateways/DirectDebitSecured.php:35 +#: includes/gateways/DirectDebitSecured.php:37 msgid "Unzer Direct Debit" msgstr "Unzer Lastschrift" -#: includes/gateways/DirectDebitSecured.php:54 -#: includes/gateways/Installment.php:51 includes/gateways/Invoice.php:157 -msgid "Date of birth" -msgstr "Geburtsdatum" - -#: includes/gateways/DirectDebitSecured.php:74 +#: includes/gateways/DirectDebitSecured.php:79 msgid "Enable Unzer Direct Debit Payments" msgstr "Unzer Lastschrift Zahlungen aktivieren" -#: includes/gateways/DirectDebitSecured.php:83 +#: includes/gateways/DirectDebitSecured.php:88 msgid "Direct Debit" msgstr "Lastschrift" -#: includes/gateways/DirectDebitSecured.php:92 -#: includes/gateways/Installment.php:94 includes/gateways/Invoice.php:66 +#: includes/gateways/DirectDebitSecured.php:97 +#: includes/gateways/Installment.php:102 includes/gateways/Invoice.php:66 msgid "Public Key EUR/B2C" msgstr "Öffentlicher Schlüssel EUR/B2C" -#: includes/gateways/DirectDebitSecured.php:98 -#: includes/gateways/Installment.php:100 includes/gateways/Invoice.php:72 +#: includes/gateways/DirectDebitSecured.php:103 +#: includes/gateways/Installment.php:108 includes/gateways/Invoice.php:72 msgid "Private Key EUR/B2C" msgstr "Privater Schlüssel EUR/B2C" -#: includes/gateways/DirectDebitSecured.php:104 -#: includes/gateways/Installment.php:106 includes/gateways/Invoice.php:78 +#: includes/gateways/DirectDebitSecured.php:109 +#: includes/gateways/Installment.php:114 includes/gateways/Invoice.php:78 msgid "Key Check EUR/B2C" msgstr "Schlüsselprüfung EUR/B2C" -#: includes/gateways/DirectDebitSecured.php:172 +#: includes/gateways/DirectDebitSecured.php:174 #, php-format msgid "" "An amount of %1$s will be deducted from your account using the descriptor " @@ -561,11 +468,11 @@ msgstr "" "Der Betrag in Höhe von %s wird mit der Referenz '%s' von Ihrem Konto in " "Übereinstimmung mit dem SEPA-Mandat eingezogen werden" -#: includes/gateways/Eps.php:34 +#: includes/gateways/Eps.php:36 msgid "Enable Unzer EPS" msgstr "Unzer EPS aktivieren" -#: includes/gateways/Eps.php:43 +#: includes/gateways/Eps.php:45 msgid "EPS" msgstr "EPS" @@ -577,107 +484,111 @@ msgstr "Unzer Giropay aktivieren" msgid "Giropay" msgstr "Giropay" -#: includes/gateways/GooglePay.php:97 +#: includes/gateways/GooglePay.php:95 msgid "Enable Unzer Google Pay" msgstr "Unzer Google Pay aktivieren" -#: includes/gateways/GooglePay.php:106 +#: includes/gateways/GooglePay.php:104 msgid "Google Pay" msgstr "Google Pay" -#: includes/gateways/GooglePay.php:126 +#: includes/gateways/GooglePay.php:124 msgid "Gateway Merchant ID" msgstr "Gateway Merchant ID" -#: includes/gateways/GooglePay.php:138 +#: includes/gateways/GooglePay.php:130 +msgid "Merchant ID" +msgstr "Merchant ID" + +#: includes/gateways/GooglePay.php:136 msgid "Merchant Name" msgstr "Merchant Name" -#: includes/gateways/GooglePay.php:144 +#: includes/gateways/GooglePay.php:142 msgid "Country Code" msgstr "Länder-Code" -#: includes/gateways/GooglePay.php:147 +#: includes/gateways/GooglePay.php:145 msgid "Country code of the acquirer" msgstr "Land des Acquirers" -#: includes/gateways/GooglePay.php:149 +#: includes/gateways/GooglePay.php:147 msgid "DK (default)" msgstr "DK (Standard)" -#: includes/gateways/GooglePay.php:156 +#: includes/gateways/GooglePay.php:154 msgid "Allow Credit Cards" msgstr "Kreditkarten zulassen" -#: includes/gateways/GooglePay.php:163 +#: includes/gateways/GooglePay.php:161 msgid "Allow Prepaid Cards" msgstr "Prepaid Karten zulassen" -#: includes/gateways/GooglePay.php:170 +#: includes/gateways/GooglePay.php:168 msgid "Allowed Card Networks" msgstr "Zugelassene Kreditkarten-Anbieter" -#: includes/gateways/GooglePay.php:181 +#: includes/gateways/GooglePay.php:179 msgid "Button Color" msgstr "Farbe des Buttons" -#: includes/gateways/GooglePay.php:186 +#: includes/gateways/GooglePay.php:184 msgid "Google's default" msgstr "Standard" -#: includes/gateways/GooglePay.php:187 +#: includes/gateways/GooglePay.php:185 msgid "Black" msgstr "Schwarz" -#: includes/gateways/GooglePay.php:188 +#: includes/gateways/GooglePay.php:186 msgid "White" msgstr "Weiß" -#: includes/gateways/GooglePay.php:193 +#: includes/gateways/GooglePay.php:191 msgid "Button Size Mode" msgstr "Größe des Buttons" -#: includes/gateways/GooglePay.php:198 +#: includes/gateways/GooglePay.php:196 msgid "Full Width" msgstr "Volle Breite" -#: includes/gateways/GooglePay.php:199 +#: includes/gateways/GooglePay.php:197 msgid "Static" msgstr "Statisch (kleiner)" -#: includes/gateways/Ideal.php:51 +#: includes/gateways/Ideal.php:35 msgid "Enable Unzer iDEAL" msgstr "Aktivieren Sie Unzer iDEAL" -#: includes/gateways/Ideal.php:60 +#: includes/gateways/Ideal.php:44 msgid "iDEAL" msgstr "iDEAL" -#: includes/gateways/Installment.php:36 +#: includes/gateways/Installment.php:37 msgid "Unzer Installment" msgstr "Unzer Ratenzahlung" -#: includes/gateways/Installment.php:76 +#: includes/gateways/Installment.php:84 msgid "Enable Unzer Installment" msgstr "Unzer Ratenkauf aktivieren" -#: includes/gateways/Installment.php:85 +#: includes/gateways/Installment.php:93 msgid "Installment" msgstr "Ratenkauf" -#: includes/gateways/Installment.php:113 includes/gateways/Invoice.php:104 +#: includes/gateways/Installment.php:121 includes/gateways/Invoice.php:104 msgid "Public Key CHF/B2C" msgstr "Öffentlicher Schlüssel CHF/B2C" -#: includes/gateways/Installment.php:119 includes/gateways/Invoice.php:110 +#: includes/gateways/Installment.php:127 includes/gateways/Invoice.php:110 msgid "Private Key CHF/B2C" msgstr "Privater Schlüssel CHF/B2C" -#: includes/gateways/Installment.php:125 includes/gateways/Invoice.php:116 +#: includes/gateways/Installment.php:133 includes/gateways/Invoice.php:116 msgid "Key Check CHF/B2C" msgstr "Schlüsselprüfung CHF/B2C" -#: includes/gateways/Installment.php:193 +#: includes/gateways/Installment.php:197 #, php-format msgid "" "Payment details:

Holder: %s
IBAN: %s
BIC: %s


Inhaber: %s
IBAN: %s
BIC: %s

Bitte verwenden Sie nur " "diese Identifikationsnummer als Bezeichnung
%s" -#: includes/gateways/Klarna.php:33 +#: includes/gateways/Klarna.php:141 msgid "Enable Unzer Klarna" msgstr "Unzer Klarna aktivieren" -#: includes/gateways/Klarna.php:42 +#: includes/gateways/Klarna.php:150 msgid "Klarna" msgstr "Klarna" -#: includes/gateways/OpenBanking.php:60 +#: includes/gateways/OpenBanking.php:66 msgid "Enable Unzer Direct Bank Transfer" msgstr "Unzer Direktüberweisung aktivieren" -#: includes/gateways/OpenBanking.php:69 +#: includes/gateways/OpenBanking.php:75 msgid "Direct Bank Transfer" msgstr "Direktüberweisung" @@ -793,19 +704,19 @@ msgstr "Unzer Banküberweisung aktivieren" msgid "Bank Transfer" msgstr "Banküberweisung" -#: includes/gateways/PostFinanceCard.php:32 +#: includes/gateways/PostFinanceCard.php:33 msgid "Enable Unzer Post Finance Card" msgstr "Unzer Post Finance Card aktivieren" -#: includes/gateways/PostFinanceCard.php:41 +#: includes/gateways/PostFinanceCard.php:42 msgid "Post Finance Card" msgstr "Post Finance Card" -#: includes/gateways/PostFinanceEfinance.php:32 +#: includes/gateways/PostFinanceEfinance.php:33 msgid "Enable Unzer Post Finance eFinance" msgstr "Unzer Post Finance eFinance aktivieren" -#: includes/gateways/PostFinanceEfinance.php:41 +#: includes/gateways/PostFinanceEfinance.php:42 msgid "Post Finance eFinance" msgstr "Post Finance eFinance" @@ -827,11 +738,11 @@ msgstr "" "Dieser Status wird allen Bestellungen zugewiesen, die mit dieser " "Zahlungsmethode erstellt werden" -#: includes/gateways/Przelewy24.php:33 +#: includes/gateways/Przelewy24.php:35 msgid "Enable Unzer Przelewy24" msgstr "Unzer Przelewy24 aktivieren" -#: includes/gateways/Przelewy24.php:42 +#: includes/gateways/Przelewy24.php:44 msgid "Przelewy24" msgstr "Przelewy24" @@ -849,16 +760,24 @@ msgstr "Unzer TWINT aktivieren" #: includes/gateways/Twint.php:42 msgid "TWINT" -msgstr "" +msgstr "TWINT" -#: includes/gateways/WeChatPay.php:33 +#: includes/gateways/WeChatPay.php:35 msgid "Enable Unzer WeChat Pay" msgstr "Aktivieren Sie Unzer WeChat Pay" -#: includes/gateways/WeChatPay.php:42 +#: includes/gateways/WeChatPay.php:44 msgid "WeChat Pay" msgstr "WeChat Bezahlen" +#: includes/gateways/Wero.php:33 +msgid "Enable Unzer Wero" +msgstr "Unzer Wero aktivieren" + +#: includes/gateways/Wero.php:42 +msgid "Wero" +msgstr "Wero" + #: includes/services/DashboardService.php:32 #, php-format msgid "" @@ -879,7 +798,7 @@ msgstr "Ausblenden" msgid "Payment complete event failed." msgstr "Abschluss der Zahlung ist fehlgeschlagen." -#: includes/services/PaymentService.php:147 +#: includes/services/PaymentService.php:151 msgid "" "Installment payment is only available for shipping and billing address with " "the same name" @@ -887,36 +806,36 @@ msgstr "" "Ratenzahlung ist nur möglich, wenn Liefer- und Rechnungsadresse denselben " "Namen haben" -#: includes/services/PaymentService.php:187 +#: includes/services/PaymentService.php:191 msgid "Unzer Payment ID: " msgstr "Unzer Payment ID: " -#: includes/services/PaymentService.php:300 +#: includes/services/PaymentService.php:304 #, php-format msgid "Unable to do refund: Maximum amount for single refund is %s." msgstr "" "Erstattung nicht möglich: Maximaler Betrag für eine einzelne Erstattung ist " "%s." -#: includes/services/PaymentService.php:301 +#: includes/services/PaymentService.php:305 #, php-format msgid "However, you may refund in up to %s smaller chunks." msgstr "Es ist jedoch möglich bis zu %s einzelne Erstattungen vorzunehmen." -#: includes/services/PaymentService.php:302 +#: includes/services/PaymentService.php:306 msgid "Original error message: " msgstr "Ursprüngliche Fehlermeldung: " -#: includes/services/PaymentService.php:331 +#: includes/services/PaymentService.php:335 msgid "Refund not possible" msgstr "Rückerstattung nicht möglich" -#: includes/services/PaymentService.php:336 +#: includes/services/PaymentService.php:340 msgid "Reversals prior to capturing are only allowed for the full amount" msgstr "" "Stornierungen vor Zahlungseinzug sind nur in Höhe des vollen Betrags möglich" -#: includes/services/PaymentService.php:341 +#: includes/services/PaymentService.php:345 msgid "Reversal not possible" msgstr "Stornierung nicht möglich" @@ -948,6 +867,66 @@ msgstr "Unzer" msgid "https://www.unzer.com" msgstr "https://www.unzer.com" +#~ msgid "Apple Pay certificate settings" +#~ msgstr "Einstellungen für Apple Pay-Zertifikate" + +#~ msgid "Payment Processing Certificate (apple_pay.pem)" +#~ msgstr "Payment Processing Zertifikat (apple_pay.pem)" + +#~ msgid "Payment Processing Key (privatekey.key)" +#~ msgstr "Payment Processing Key (privatekey.key)" + +#~ msgid "Merchant Identification Certificate (merchant_id.pem)" +#~ msgstr "Merchant Identification Zertifikat (merchant_id.pem)" + +#~ msgid "Merchant Identification Key (merchant_id.key)" +#~ msgstr "Merchant Identification Key (merchant_id.key))" + +#~ msgid "invalid" +#~ msgstr "ungültig" + +#~ msgid "The certificate is not active" +#~ msgstr "Das Zertifikat ist nicht aktiviert" + +#~ msgid "valid" +#~ msgstr "gültig" + +#~ msgid "Unable to read certificate" +#~ msgstr "Zertifikat kann nicht gelesen werden" + +#~ msgid "Certificate does not match merchant id: " +#~ msgstr "Das Zertifikat stimmt nicht mit der Merchant ID überein: " + +#~ msgid "Not a valid certificate" +#~ msgstr "Kein gültiges Zertifikat" + +#~ msgid "Key does not match certificate" +#~ msgstr "Schlüssel stimmt nicht mit Zertifikat überein" + +#~ msgid "Not a valid private key" +#~ msgstr "Kein gültiger privater Schlüssel" + +#~ msgid "You have to be at least 18 years old for this payment method" +#~ msgstr "Für diese Zahlungsmethode müssen Sie mindestens 18 Jahre alt sein" + +#~ msgid "Please check your date of birth" +#~ msgstr "Bitte überprüfen Sie Ihr Geburtsdatum" + +#~ msgid "I accept the SEPA mandate" +#~ msgstr "Ich akzeptiere das SEPA Mandat" + +#~ msgid "(read more)" +#~ msgstr "(mehr lesen)" + +#~ msgid "Alternative SEPA mandate description" +#~ msgstr "Eigener Text fuer Akzeptanz des SEPA Mandats" + +#~ msgid "Leave empty to display the default text" +#~ msgstr "Leer lassen für Standard-Vorlage" + +#~ msgid "Date of birth" +#~ msgstr "Geburtsdatum" + #~ msgid "Please select your bank" #~ msgstr "Bitte wählen Sie Ihre Bank" diff --git a/package.json b/package.json new file mode 100644 index 0000000..a7021cf --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "unzer-payments", + "version": "2.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "pnpm run start:hot", + "start": "wp-scripts start", + "start:hot": "wp-scripts start --hot", + "build": "wp-scripts build" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@woocommerce/dependency-extraction-webpack-plugin": "^4.0.0", + "@wordpress/scripts": "^30.25.0" + }, + "dependencies": { + "@woocommerce/settings": "^1.0.0", + "@wordpress/element": "^6.32.0", + "@wordpress/html-entities": "^4.32.0", + "@wordpress/i18n": "^6.5.0" + } +} diff --git a/readme.txt b/readme.txt index be3ea54..015fc90 100755 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: Unzer Tags: payments, woocommerce Requires at least: 4.5 Tested up to: 6.9 -Stable tag: 1.8.4 +Stable tag: 2.0.0 License: Apache-2.0 License URI: http://www.apache.org/licenses/LICENSE-2.0 Author URI: https://unzer.com @@ -13,7 +13,8 @@ Use Unzer plugin for WooCommerce to provide an easy-to-install and use payment g ## Description ## -* Unzer Payments for WooCommerce payments by credit card, SOFORT, PayPal, Unzer Invoice (Paylater), iDEAL, EPS, Direct Bank Transfer and many more (See complete list below). +* Version 2.0.0 is a breaking change - remember to test and create backup before updating your LIVE environment. +* Migration from WooCommerce Classic Checkout to Checkout Block will follow with version 2.1.0 * Easily accept digital payments in your online store with Unzer Plugins. * Unzer Payments is a 3rd party payment gateway plugin, https://docs.unzer.com/plugins/woocommerce and https://unzer.com/ * Unzer Payments can use external JavaScripts for certain payment methods, Apple Pay https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js, Google Pay https://pay.google.com/gp/p/js/pay.js, Unzer paylater payment methods https://h.online-metrix.net/fp/tags.js. @@ -30,26 +31,24 @@ Use Unzer plugin for WooCommerce to provide an easy-to-install and use payment g ## Available payment methods ## -* Credit Cards +* Apple Pay +* Bancontact +* Cards and Click to Pay * EPS +* Google Pay * iDEAL +* Klarna * PayPal -* SOFORT -* Unzer Invoice (Paylater) -* Unzer Installment -* Apple Pay -* Google Pay -* Alipay -* Bancontact -* Direct Bank Transfer -* Direct Debit -* Direct Debit Secured -* PostFinance Card -* PostFinance E-Finance -* Prepayment * Przelewy24 -* Wechat Pay * TWINT +* Unzer Direct Bank Transfer +* Unzer Direct Debit (SEPA) +* Unzer Direct Debit Secured +* Unzer Installment +* Unzer Invoice +* Unzer Prepayment +* WeChat Pay +* Wero ## Support ## @@ -61,6 +60,12 @@ Unzer is one of the leading payment companies in Europe. Over 70,000 retailers t ## Changelog ## +# 2.0.0 # +* Version 2.0.0 is a breaking change - remember to test and create backup before updating your LIVE environment. +* Migration from Unzer UI Component V1 to Unzer UI Component V2 +* EAA Support, https://docs.unzer.com/online-payments/compliance/eaa/ +* Deprecated payment methods have been replaced with new ones, removed or renamed. For full list see https://github.com/unzerdev/woocommerce/blob/master/readme.txt for an updated list. + # 1.8.4 # * Fix correct amount for order pay page diff --git a/unzer-payments.php b/unzer-payments.php index af9a7e7..b89d751 100755 --- a/unzer-payments.php +++ b/unzer-payments.php @@ -5,12 +5,12 @@ * Description: Official Unzer Plugin * Author: Unzer * Author URI: https://www.unzer.com - * Version: 1.8.4 + * Version: 2.0.0 * License: Apache-2.0 * Requires at least: 4.5 * Tested up to: 6.9 * WC requires at least: 6.0 - * WC tested up to: 10.2 + * WC tested up to: 10.4 * Text Domain: unzer-payments */ @@ -21,7 +21,7 @@ /** * Required minimums and constants */ -define( 'UNZER_VERSION', '1.8.4' ); +define( 'UNZER_VERSION', '2.0.0' ); define( 'UNZER_PLUGIN_TYPE_STRING', 'Unzer Payments' ); define( 'UNZER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); define( 'UNZER_PLUGIN_PATH', __DIR__ . '/' ); @@ -55,31 +55,26 @@ function () { ); return; } - // TODO: add autoload require_once UNZER_PLUGIN_PATH . 'vendor/autoload.php'; - require_once UNZER_PLUGIN_PATH . 'includes/Main.php'; - require_once UNZER_PLUGIN_PATH . 'includes/Util.php'; - require_once UNZER_PLUGIN_PATH . 'includes/sdk-extension/Resource/ApplePayCertificate.php'; - require_once UNZER_PLUGIN_PATH . 'includes/sdk-extension/Resource/ApplePayPrivateKey.php'; - require_once UNZER_PLUGIN_PATH . 'includes/sdk-extension/Services/AppleKeyService.php'; - require_once UNZER_PLUGIN_PATH . 'includes/services/DashboardService.php'; - require_once UNZER_PLUGIN_PATH . 'includes/services/OrderService.php'; - require_once UNZER_PLUGIN_PATH . 'includes/services/CustomerService.php'; - require_once UNZER_PLUGIN_PATH . 'includes/services/LogService.php'; - require_once UNZER_PLUGIN_PATH . 'includes/services/PaymentService.php'; - require_once UNZER_PLUGIN_PATH . 'includes/services/ShopService.php'; - require_once UNZER_PLUGIN_PATH . 'includes/services/WebhookManagementService.php'; - require_once UNZER_PLUGIN_PATH . 'includes/controllers/CheckoutController.php'; - require_once UNZER_PLUGIN_PATH . 'includes/controllers/AccountController.php'; - require_once UNZER_PLUGIN_PATH . 'includes/controllers/AdminController.php'; - require_once UNZER_PLUGIN_PATH . 'includes/controllers/WebhookController.php'; - require_once UNZER_PLUGIN_PATH . 'includes/gateways/AbstractGateway.php'; - foreach ( glob( UNZER_PLUGIN_PATH . 'includes/traits/*.php' ) as $trait ) { - require_once $trait; - } - foreach ( glob( UNZER_PLUGIN_PATH . 'includes/gateways/*.php' ) as $gateway ) { - require_once $gateway; - } + + spl_autoload_register( + function ( $class ) { + $prefix = 'UnzerPayments\\'; + $base_dir = UNZER_PLUGIN_PATH . 'includes/'; + + $len = strlen( $prefix ); + if ( strncmp( $prefix, $class, $len ) !== 0 ) { + return; + } + + $relative_class = substr( $class, $len ); + $file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php'; + + if ( file_exists( $file ) ) { + require_once $file; + } + } + ); $unzer = \UnzerPayments\Main::getInstance(); $unzer->init(); diff --git a/vendor/autoload.php b/vendor/autoload.php index a2a98fd..0abbfa3 100755 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -14,10 +14,7 @@ echo $err; } } - trigger_error( - $err, - E_USER_ERROR - ); + throw new RuntimeException($err); } require_once __DIR__ . '/composer/autoload_real.php'; diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php index 51e734a..2052022 100755 --- a/vendor/composer/InstalledVersions.php +++ b/vendor/composer/InstalledVersions.php @@ -26,12 +26,23 @@ */ class InstalledVersions { + /** + * @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to + * @internal + */ + private static $selfDir = null; + /** * @var mixed[]|null * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array}|array{}|null */ private static $installed; + /** + * @var bool + */ + private static $installedIsLocalDir; + /** * @var bool|null */ @@ -309,6 +320,24 @@ public static function reload($data) { self::$installed = $data; self::$installedByVendor = array(); + + // when using reload, we disable the duplicate protection to ensure that self::$installed data is + // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not, + // so we have to assume it does not, and that may result in duplicate data being returned when listing + // all installed packages for example + self::$installedIsLocalDir = false; + } + + /** + * @return string + */ + private static function getSelfDir() + { + if (self::$selfDir === null) { + self::$selfDir = strtr(__DIR__, '\\', '/'); + } + + return self::$selfDir; } /** @@ -322,19 +351,27 @@ private static function getInstalled() } $installed = array(); + $copiedLocalDir = false; if (self::$canGetVendors) { + $selfDir = self::getSelfDir(); foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { + $vendorDir = strtr($vendorDir, '\\', '/'); if (isset(self::$installedByVendor[$vendorDir])) { $installed[] = self::$installedByVendor[$vendorDir]; } elseif (is_file($vendorDir.'/composer/installed.php')) { /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ $required = require $vendorDir.'/composer/installed.php'; - $installed[] = self::$installedByVendor[$vendorDir] = $required; - if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { - self::$installed = $installed[count($installed) - 1]; + self::$installedByVendor[$vendorDir] = $required; + $installed[] = $required; + if (self::$installed === null && $vendorDir.'/composer' === $selfDir) { + self::$installed = $required; + self::$installedIsLocalDir = true; } } + if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) { + $copiedLocalDir = true; + } } } @@ -350,7 +387,7 @@ private static function getInstalled() } } - if (self::$installed !== array()) { + if (self::$installed !== array() && !$copiedLocalDir) { $installed[] = self::$installed; } diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE index 62ecfd8..f27399a 100755 --- a/vendor/composer/LICENSE +++ b/vendor/composer/LICENSE @@ -1,3 +1,4 @@ + Copyright (c) Nils Adermann, Jordi Boggiano Permission is hereby granted, free of charge, to any person obtaining a copy @@ -17,3 +18,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 3b4db68..2c030a7 100755 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -2,17 +2,17 @@ "packages": [ { "name": "unzerdev/php-sdk", - "version": "3.11.0", - "version_normalized": "3.11.0.0", + "version": "3.13.1", + "version_normalized": "3.13.1.0", "source": { "type": "git", "url": "https://github.com/unzerdev/php-sdk.git", - "reference": "274650b6120b8665c8867627210cd8adab65406b" + "reference": "0a26d70b33185d52e49b06cb500a6e01bb6f1087" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/unzerdev/php-sdk/zipball/274650b6120b8665c8867627210cd8adab65406b", - "reference": "274650b6120b8665c8867627210cd8adab65406b", + "url": "https://api.github.com/repos/unzerdev/php-sdk/zipball/0a26d70b33185d52e49b06cb500a6e01bb6f1087", + "reference": "0a26d70b33185d52e49b06cb500a6e01bb6f1087", "shasum": "" }, "require": { @@ -26,7 +26,7 @@ "suggest": { "ext-curl": "*" }, - "time": "2024-12-04T08:14:47+00:00", + "time": "2025-09-23T14:21:50+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -42,7 +42,7 @@ "description": "This is the php sdk to connect to the Unzer rest API.", "support": { "email": "support@unzer.com", - "source": "https://github.com/unzerdev/php-sdk/tree/3.11.0" + "source": "https://github.com/unzerdev/php-sdk/tree/3.13.1" }, "install-path": "../unzerdev/php-sdk" } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 23c3d1d..c84fb1c 100755 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -20,9 +20,9 @@ 'dev_requirement' => false, ), 'unzerdev/php-sdk' => array( - 'pretty_version' => '3.11.0', - 'version' => '3.11.0.0', - 'reference' => '274650b6120b8665c8867627210cd8adab65406b', + 'pretty_version' => '3.13.1', + 'version' => '3.13.1.0', + 'reference' => '0a26d70b33185d52e49b06cb500a6e01bb6f1087', 'type' => 'library', 'install_path' => __DIR__ . '/../unzerdev/php-sdk', 'aliases' => array(), diff --git a/vendor/unzerdev/php-sdk/CHANGELOG.md b/vendor/unzerdev/php-sdk/CHANGELOG.md index 384135b..468e50c 100755 --- a/vendor/unzerdev/php-sdk/CHANGELOG.md +++ b/vendor/unzerdev/php-sdk/CHANGELOG.md @@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [3.13.1](https://github.com/unzerdev/php-sdk/compare/3.13.0..3.13.1) + +### Added + +* Added support for payment method `Wero`. + +## [3.13.0](https://github.com/unzerdev/php-sdk/compare/3.12.0..3.13.0) + +### Changed + +* Ensure type hints of nullable function parameters are explicitly defined as such to address deprecation warnings. +* Change paypage v2 test domain ending from ".io" to ".com". + +## [3.12.0](https://github.com/unzerdev/php-sdk/compare/3.11.0..3.12.0) + +### Added + +* Add Styling properties for v2 Paypage `\UnzerSDK\Resources\V2\Paypage`: + * `basketBackgroundColor` + * `paymentFormBackgroundColor` +* Add prototypes for v2 Customer: `\UnzerSDK\Resources\V2\Customer`. +* Add prototypes for v3 Basket: `\UnzerSDK\Resources\V3\Basket`. + ## [3.11.0](https://github.com/unzerdev/php-sdk/compare/3.10.0..3.11.0) ### Added diff --git a/vendor/unzerdev/php-sdk/src/Adapter/ApplepayAdapter.php b/vendor/unzerdev/php-sdk/src/Adapter/ApplepayAdapter.php index 824650a..b23a463 100644 --- a/vendor/unzerdev/php-sdk/src/Adapter/ApplepayAdapter.php +++ b/vendor/unzerdev/php-sdk/src/Adapter/ApplepayAdapter.php @@ -67,7 +67,7 @@ public function validMerchantValidationDomain(string $merchantValidationURL): bo * This is necessary if the ssl cert file doesn't contain key already. * @param string|null $caCert Path to CA certificate. */ - public function init(string $sslCert, string $sslKey = null, string $caCert = null): void + public function init(string $sslCert, ?string $sslKey = null, ?string $caCert = null): void { $timeout = EnvironmentService::getTimeout(); $curlVerbose = EnvironmentService::isCurlVerbose(); diff --git a/vendor/unzerdev/php-sdk/src/Adapter/CurlAdapter.php b/vendor/unzerdev/php-sdk/src/Adapter/CurlAdapter.php index e3ddd2b..5535eb4 100755 --- a/vendor/unzerdev/php-sdk/src/Adapter/CurlAdapter.php +++ b/vendor/unzerdev/php-sdk/src/Adapter/CurlAdapter.php @@ -10,11 +10,10 @@ namespace UnzerSDK\Adapter; -use UnzerSDK\Unzer; -use UnzerSDK\Services\EnvironmentService; -use UnzerSDK\Exceptions\UnzerApiException; use RuntimeException; - +use UnzerSDK\Exceptions\UnzerApiException; +use UnzerSDK\Services\EnvironmentService; +use UnzerSDK\Unzer; use function extension_loaded; use function in_array; @@ -37,7 +36,7 @@ public function __construct() /** * {@inheritDoc} */ - public function init(string $url, string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void + public function init(string $url, ?string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void { $timeout = EnvironmentService::getTimeout(); $curlVerbose = EnvironmentService::isCurlVerbose(); diff --git a/vendor/unzerdev/php-sdk/src/Adapter/HttpAdapterInterface.php b/vendor/unzerdev/php-sdk/src/Adapter/HttpAdapterInterface.php index 4e238b8..2e2bd0a 100755 --- a/vendor/unzerdev/php-sdk/src/Adapter/HttpAdapterInterface.php +++ b/vendor/unzerdev/php-sdk/src/Adapter/HttpAdapterInterface.php @@ -25,7 +25,7 @@ interface HttpAdapterInterface * @param string|null $payload Json encoded payload string. * @param string $httpMethod The Http method to perform. */ - public function init(string $url, string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void; + public function init(string $url, ?string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void; /** * Executes the request and returns the response. diff --git a/vendor/unzerdev/php-sdk/src/Apis/PaymentApiConfigBearerAuth.php b/vendor/unzerdev/php-sdk/src/Apis/PaymentApiConfigBearerAuth.php new file mode 100644 index 0000000..b0d166e --- /dev/null +++ b/vendor/unzerdev/php-sdk/src/Apis/PaymentApiConfigBearerAuth.php @@ -0,0 +1,17 @@ +clientMessage = empty($clientMessage) ? static::CLIENT_MESSAGE : $clientMessage; diff --git a/vendor/unzerdev/php-sdk/src/Interfaces/CancelServiceInterface.php b/vendor/unzerdev/php-sdk/src/Interfaces/CancelServiceInterface.php index efa5314..5400380 100644 --- a/vendor/unzerdev/php-sdk/src/Interfaces/CancelServiceInterface.php +++ b/vendor/unzerdev/php-sdk/src/Interfaces/CancelServiceInterface.php @@ -8,13 +8,13 @@ namespace UnzerSDK\Interfaces; +use RuntimeException; use UnzerSDK\Constants\CancelReasonCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; -use RuntimeException; interface CancelServiceInterface { @@ -30,7 +30,7 @@ interface CancelServiceInterface * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function cancelAuthorization(Authorization $authorization, float $amount = null): Cancellation; + public function cancelAuthorization(Authorization $authorization, ?float $amount = null): Cancellation; /** * Performs a Cancellation transaction for the Authorization of the given Payment object. @@ -44,7 +44,7 @@ public function cancelAuthorization(Authorization $authorization, float $amount * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function cancelAuthorizationByPayment($payment, float $amount = null): Cancellation; + public function cancelAuthorizationByPayment($payment, ?float $amount = null): Cancellation; /** * Performs a Cancellation transaction for the given Charge and returns the resulting Cancellation object. @@ -67,11 +67,11 @@ public function cancelAuthorizationByPayment($payment, float $amount = null): Ca public function cancelChargeById( $payment, string $chargeId, - float $amount = null, - string $reasonCode = null, - string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amount = null, + ?string $reasonCode = null, + ?string $referenceText = null, + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation; /** @@ -93,11 +93,11 @@ public function cancelChargeById( */ public function cancelCharge( Charge $charge, - float $amount = null, - string $reasonCode = null, - string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amount = null, + ?string $reasonCode = null, + ?string $referenceText = null, + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation; /** @@ -119,11 +119,11 @@ public function cancelCharge( */ public function cancelPayment( $payment, - float $amount = null, + ?float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, - string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?string $referenceText = null, + ?float $amountNet = null, + ?float $amountVat = null ): array; /** @@ -167,5 +167,5 @@ public function cancelChargedPayment($payment, ?Cancellation $cancellation = nul * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is a error while using the SDK. */ - public function cancelPaymentAuthorization($payment, float $amount = null): ?Cancellation; + public function cancelPaymentAuthorization($payment, ?float $amount = null): ?Cancellation; } diff --git a/vendor/unzerdev/php-sdk/src/Interfaces/PaymentServiceInterface.php b/vendor/unzerdev/php-sdk/src/Interfaces/PaymentServiceInterface.php index 477e03e..d461397 100644 --- a/vendor/unzerdev/php-sdk/src/Interfaces/PaymentServiceInterface.php +++ b/vendor/unzerdev/php-sdk/src/Interfaces/PaymentServiceInterface.php @@ -9,6 +9,7 @@ namespace UnzerSDK\Interfaces; use DateTime; +use RuntimeException; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\Basket; @@ -24,7 +25,6 @@ use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\Resources\TransactionTypes\Payout; use UnzerSDK\Resources\TransactionTypes\Shipment; -use RuntimeException; interface PaymentServiceInterface { @@ -48,8 +48,8 @@ public function performAuthorization( Authorization $authorization, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Authorization; /** @@ -130,8 +130,8 @@ public function performCharge( Charge $charge, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Charge; /** @@ -229,9 +229,9 @@ public function performChargeOnPayment( */ public function chargeAuthorization( $payment, - float $amount = null, - string $orderId = null, - string $invoiceId = null + ?float $amount = null, + ?string $orderId = null, + ?string $invoiceId = null ): Charge; /** @@ -252,9 +252,9 @@ public function chargeAuthorization( */ public function chargePayment( $payment, - float $amount = null, - string $orderId = null, - string $invoiceId = null + ?float $amount = null, + ?string $orderId = null, + ?string $invoiceId = null ): Charge; /** @@ -284,11 +284,11 @@ public function payout( $paymentType, string $returnUrl, $customer = null, - string $orderId = null, - Metadata $metadata = null, - Basket $basket = null, - string $invoiceId = null, - string $referenceText = null + ?string $orderId = null, + ?Metadata $metadata = null, + ?Basket $basket = null, + ?string $invoiceId = null, + ?string $referenceText = null ): Payout; /** @@ -303,7 +303,7 @@ public function payout( * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function ship($payment, string $invoiceId = null, string $orderId = null): Shipment; + public function ship($payment, ?string $invoiceId = null, ?string $orderId = null): Shipment; /** * Initializes a PayPage for charge transaction and returns the PayPage resource. @@ -328,9 +328,9 @@ public function ship($payment, string $invoiceId = null, string $orderId = null) */ public function initPayPageCharge( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage; /** @@ -356,9 +356,9 @@ public function initPayPageCharge( */ public function initPayPageAuthorize( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage; /** @@ -378,7 +378,7 @@ public function fetchInstallmentPlans( float $amount, string $currency, float $effectiveInterest, - DateTime $orderDate = null + ?DateTime $orderDate = null ): InstalmentPlans; /** diff --git a/vendor/unzerdev/php-sdk/src/Interfaces/ResourceServiceInterface.php b/vendor/unzerdev/php-sdk/src/Interfaces/ResourceServiceInterface.php index a95fe3e..6f26b0a 100644 --- a/vendor/unzerdev/php-sdk/src/Interfaces/ResourceServiceInterface.php +++ b/vendor/unzerdev/php-sdk/src/Interfaces/ResourceServiceInterface.php @@ -30,7 +30,7 @@ interface ResourceServiceInterface { /** - * Retrieves an Payout resource via the API using the corresponding Payment or paymentId. + * Retrieves a Payout resource via the API using the corresponding Payment or paymentId. * The Payout resource can not be fetched using its id since they are unique only within the Payment. * A Payment can have zero or one Payouts. * @@ -57,7 +57,7 @@ public function fetchPayout($payment): Payout; * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function activateRecurringPayment($paymentType, string $returnUrl, string $recurrenceType = null): Recurring; + public function activateRecurringPayment($paymentType, string $returnUrl, ?string $recurrenceType = null): Recurring; /** * Fetch and return payment by given payment id or payment object. @@ -162,7 +162,7 @@ public function createBasket(Basket $basket): Basket; public function fetchBasket($basket): Basket; /** - * Update the a basket resource with the given basket object (id must be set). + * Update a basket resource with the given basket object (id must be set). * * @param Basket $basket * @@ -195,12 +195,12 @@ public function createPaymentType(BasePaymentType $paymentType): BasePaymentType * @return BasePaymentType|AbstractUnzerResource The updated PaymentType object. * * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. - * @throws RuntimeException A RuntimeException is thrown when there is a error while using the SDK. + * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ public function updatePaymentType(BasePaymentType $paymentType): BasePaymentType; /** - * Fetch the payment type with the given Id from the API. + * Fetch the payment type with the given ID from the API. * * @param string $typeId * @@ -257,7 +257,7 @@ public function fetchCustomer($customer): Customer; * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function fetchCustomerByExtCustomerId(string $customerId): Customer; + public function fetchCustomerByExtCustomerId(string $customerId, int $version): Customer; /** * Update and return a Customer object via API. @@ -325,8 +325,8 @@ public function fetchCharge(Charge $charge): Charge; * Fetch a chargeback object by combination of payment id, chargeback id and charge id. * Chargeback ids are not unique to a merchant but to the payment. * - * @param Payment|string $payment The payment object or payment id to fetch the authorization from. - * @param string $chargebackId The id of the chargeback to fetch. + * @param string $paymentId The payment object or payment id to fetch the authorization from. + * @param string $chargebackId The id of the chargeback to fetch. * * @return Chargeback|AbstractUnzerResource The fetched chargeback. * diff --git a/vendor/unzerdev/php-sdk/src/Interfaces/WebhookServiceInterface.php b/vendor/unzerdev/php-sdk/src/Interfaces/WebhookServiceInterface.php index 48c89e2..8ae6b5a 100644 --- a/vendor/unzerdev/php-sdk/src/Interfaces/WebhookServiceInterface.php +++ b/vendor/unzerdev/php-sdk/src/Interfaces/WebhookServiceInterface.php @@ -8,10 +8,10 @@ namespace UnzerSDK\Interfaces; +use RuntimeException; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\Webhook; -use RuntimeException; interface WebhookServiceInterface { @@ -106,5 +106,5 @@ public function registerMultipleWebhooks(string $url, array $events): array; * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function fetchResourceFromEvent(string $eventJson = null): AbstractUnzerResource; + public function fetchResourceFromEvent(?string $eventJson = null): AbstractUnzerResource; } diff --git a/vendor/unzerdev/php-sdk/src/Resources/Basket.php b/vendor/unzerdev/php-sdk/src/Resources/Basket.php index 007af2b..3397f90 100755 --- a/vendor/unzerdev/php-sdk/src/Resources/Basket.php +++ b/vendor/unzerdev/php-sdk/src/Resources/Basket.php @@ -4,8 +4,9 @@ use stdClass; use UnzerSDK\Adapter\HttpAdapterInterface; +use UnzerSDK\Constants\ApiVersions; use UnzerSDK\Resources\EmbeddedResources\BasketItem; -use function count; +use UnzerSDK\Resources\V2\BasketProperties as BasketV2Properties; /** * This represents the basket resource. @@ -15,6 +16,8 @@ */ class Basket extends AbstractUnzerResource { + use BasketV2Properties; + /** * @var float $amountTotalGross * @@ -36,21 +39,6 @@ class Basket extends AbstractUnzerResource */ protected $amountTotalVat = 0.0; - /** @var float $totalValueGross */ - protected $totalValueGross = 0.0; - - /** @var string $currencyCode */ - protected $currencyCode; - - /** @var string $orderId */ - protected $orderId = ''; - - /** @var string $note */ - protected $note; - - /** @var BasketItem[] $basketItems */ - private $basketItems; - /** * Basket constructor. * @@ -86,9 +74,9 @@ public function getAmountTotalGross(): float /** * @param float $amountTotalGross * + * @return Basket * @deprecated since 1.1.5.0 @see setTotalValueGross(). * - * @return Basket */ public function setAmountTotalGross(float $amountTotalGross): Basket { @@ -96,25 +84,6 @@ public function setAmountTotalGross(float $amountTotalGross): Basket return $this; } - /** - * @return float - */ - public function getTotalValueGross(): float - { - return $this->totalValueGross; - } - - /** - * @param float $totalValueGross - * - * @return Basket - */ - public function setTotalValueGross(float $totalValueGross): Basket - { - $this->totalValueGross = $totalValueGross; - return $this; - } - /** * @return float * @@ -128,9 +97,9 @@ public function getAmountTotalDiscount(): float /** * @param float $amountTotalDiscount * + * @return Basket * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. * - * @return Basket */ public function setAmountTotalDiscount(float $amountTotalDiscount): Basket { @@ -151,9 +120,9 @@ public function getAmountTotalVat(): float /** * @param float $amountTotalVat * + * @return Basket * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. * - * @return Basket */ public function setAmountTotalVat(float $amountTotalVat): Basket { @@ -162,122 +131,6 @@ public function setAmountTotalVat(float $amountTotalVat): Basket } /** - * @return string - */ - public function getCurrencyCode(): string - { - return $this->currencyCode; - } - - /** - * @param string $currencyCode - * - * @return Basket - */ - public function setCurrencyCode(string $currencyCode): Basket - { - $this->currencyCode = $currencyCode; - return $this; - } - - /** - * @return int - */ - public function getItemCount(): int - { - return count($this->basketItems); - } - - /** - * @return string|null - */ - public function getNote(): ?string - { - return $this->note; - } - - /** - * @param string|null $note - * - * @return Basket - */ - public function setNote(?string $note): Basket - { - $this->note = $note; - return $this; - } - - /** - * @return string - */ - public function getOrderId(): string - { - return $this->orderId; - } - - /** - * @param string $orderId - * - * @return Basket - */ - public function setOrderId(string $orderId): Basket - { - $this->orderId = $orderId; - return $this; - } - - /** - * @return array - */ - public function getBasketItems(): array - { - return $this->basketItems; - } - - /** - * @param array $basketItems - * - * @return Basket - */ - public function setBasketItems(array $basketItems): Basket - { - $this->basketItems = []; - - foreach ($basketItems as $basketItem) { - $this->addBasketItem($basketItem); - } - - return $this; - } - - /** - * Adds the given BasketItem to the Basket. - * - * @param BasketItem $basketItem - * - * @return Basket - */ - public function addBasketItem(BasketItem $basketItem): Basket - { - $this->basketItems[] = $basketItem; - if ($basketItem->getBasketItemReferenceId() === null) { - $basketItem->setBasketItemReferenceId((string)$this->getKeyOfLastBasketItemAdded()); - } - return $this; - } - - /** - * @param int $index - * - * @return BasketItem|null - */ - public function getBasketItemByIndex(int $index): ?BasketItem - { - return $this->basketItems[$index] ?? null; - } - - /** - * Add the dynamically set meta data. * {@inheritDoc} */ public function expose(): array @@ -301,7 +154,7 @@ public function expose(): array public function getApiVersion(): string { if (!empty($this->getTotalValueGross())) { - return 'v2'; + return ApiVersions::V2; } return parent::getApiVersion(); } diff --git a/vendor/unzerdev/php-sdk/src/Resources/CustomerFactory.php b/vendor/unzerdev/php-sdk/src/Resources/CustomerFactory.php index 777c142..b353644 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/CustomerFactory.php +++ b/vendor/unzerdev/php-sdk/src/Resources/CustomerFactory.php @@ -6,6 +6,7 @@ use UnzerSDK\Constants\CompanyRegistrationTypes; use UnzerSDK\Resources\EmbeddedResources\Address; use UnzerSDK\Resources\EmbeddedResources\CompanyInfo; +use UnzerSDK\Resources\V2\Customer as CustomerV2; /** * Creates the different Customer objects. @@ -15,6 +16,18 @@ */ class CustomerFactory { + private static int $version = 1; + + public static function setVersion(int $version): void + { + self::$version = $version; + } + + public static function getVersion(): int + { + return self::$version; + } + /** * Creates a local Customer object for B2C transactions. * Please use Unzer::createCustomer(...) to create the customer resource on the API side. @@ -26,7 +39,7 @@ class CustomerFactory */ public static function createCustomer(string $firstname, string $lastname): Customer { - return (new Customer())->setFirstname($firstname)->setLastname($lastname); + return self::getCustomer()->setFirstname($firstname)->setLastname($lastname); } /** @@ -58,7 +71,7 @@ public static function createNotRegisteredB2bCustomer( ->setFunction('OWNER') ->setCommercialSector($commercialSector); - return (new Customer()) + return self::getCustomer() ->setFirstname($firstname) ->setLastname($lastname) ->setBirthDate($birthDate) @@ -89,9 +102,17 @@ public static function createRegisteredB2bCustomer( ->setCommercialRegisterNumber($commercialRegisterNumber) ->setCommercialSector($commercialSector); - return (new Customer()) + return self::getCustomer() ->setCompany($company) ->setBillingAddress($billingAddress) ->setCompanyInfo($companyInfo); } + + /** + * @return Customer + */ + protected static function getCustomer(): Customer + { + return (self::$version == 2) ? new CustomerV2() : new Customer(); + } } diff --git a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/BasketItem.php b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/BasketItem.php index bffe0eb..feaa2b3 100755 --- a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/BasketItem.php +++ b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/BasketItem.php @@ -3,6 +3,7 @@ namespace UnzerSDK\Resources\EmbeddedResources; use UnzerSDK\Resources\AbstractUnzerResource; +use UnzerSDK\Resources\V2\BasketItemProperties as BasketV2ItemProperties; /** * This trait adds amount properties to a class. @@ -12,14 +13,7 @@ */ class BasketItem extends AbstractUnzerResource { - /** @var string $basketItemReferenceId */ - protected $basketItemReferenceId; - - /** @var int $quantity */ - protected $quantity = 1; - - /** @var float $vat */ - protected $vat = 0.0; + use BasketV2ItemProperties; /** * @var float $amountDiscount @@ -28,9 +22,6 @@ class BasketItem extends AbstractUnzerResource */ protected $amountDiscount = 0.0; - /** @var float $amountDiscountPerUnitGross */ - protected $amountDiscountPerUnitGross = 0.0; - /** * @var float $amountGross * @@ -52,9 +43,6 @@ class BasketItem extends AbstractUnzerResource */ protected $amountPerUnit = 0.0; - /** @var float $amountPerUnitGross */ - protected $amountPerUnitGross = 0.0; - /** * @var float $amountNet * @@ -62,98 +50,27 @@ class BasketItem extends AbstractUnzerResource */ protected $amountNet = 0.0; - /** @var string $unit */ - protected $unit; - - /** @var string $title */ - protected $title = ''; - - /** @var string|null $subTitle */ - protected $subTitle; - - /** @var string|null $imageUrl */ - protected $imageUrl; - - /** @var string|null $type */ - protected $type; - /** * BasketItem constructor. * + * @param string $title + * @param float $amountNet + * @param float $amountPerUnit + * @param int $quantity * @deprecated since 1.1.5.0 Please call constructor without parameters and use setter functions instead. * - * @param string $title - * @param float $amountNet - * @param float $amountPerUnit - * @param int $quantity */ public function __construct( string $title = '', float $amountNet = 0.0, float $amountPerUnit = 0.0, - int $quantity = 1 - ) { - $this->title = $title; - $this->quantity = $quantity; - $this->setAmountNet($amountNet); - $this->setAmountPerUnit($amountPerUnit); - } - - /** - * @return string|null - */ - public function getBasketItemReferenceId(): ?string - { - return $this->basketItemReferenceId; - } - - /** - * @param string|null $basketItemReferenceId - * - * @return BasketItem - */ - public function setBasketItemReferenceId(?string $basketItemReferenceId): BasketItem - { - $this->basketItemReferenceId = $basketItemReferenceId; - return $this; - } - - /** - * @return int - */ - public function getQuantity(): int - { - return $this->quantity; - } - - /** - * @param int $quantity - * - * @return BasketItem - */ - public function setQuantity(int $quantity): BasketItem + int $quantity = 1 + ) { + $this->title = $title; $this->quantity = $quantity; - return $this; - } - - /** - * @return float - */ - public function getVat(): float - { - return $this->vat; - } - - /** - * @param float $vat - * - * @return BasketItem - */ - public function setVat(float $vat): BasketItem - { - $this->vat = $vat; - return $this; + $this->setAmountNet($amountNet); + $this->setAmountPerUnit($amountPerUnit); } /** @@ -169,9 +86,9 @@ public function getAmountDiscount(): float /** * @param float $amountDiscount * + * @return BasketItem * @deprecated since 1.1.5.0 @see $setAmountDiscountPerUnitGross. * - * @return BasketItem */ public function setAmountDiscount(float $amountDiscount): BasketItem { @@ -192,9 +109,9 @@ public function getAmountGross(): float /** * @param float $amountGross * + * @return BasketItem * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. * - * @return BasketItem */ public function setAmountGross(float $amountGross): BasketItem { @@ -202,43 +119,6 @@ public function setAmountGross(float $amountGross): BasketItem return $this; } - /** - * @return float - */ - public function getAmountDiscountPerUnitGross(): float - { - return $this->amountDiscountPerUnitGross; - } - - /** - * @param float $amountDiscountPerUnitGross - * - * @return BasketItem - */ - public function setAmountDiscountPerUnitGross(float $amountDiscountPerUnitGross): BasketItem - { - $this->amountDiscountPerUnitGross = $amountDiscountPerUnitGross; - return $this; - } - - /** - * @return float - */ - public function getAmountPerUnitGross(): float - { - return $this->amountPerUnitGross; - } - - /** - * @param float $amountPerUnitGross - * - * @return BasketItem - */ - public function setAmountPerUnitGross(float $amountPerUnitGross): BasketItem - { - $this->amountPerUnitGross = $amountPerUnitGross; - return $this; - } /** * @return float @@ -253,9 +133,9 @@ public function getAmountVat(): float /** * @param float $amountVat * + * @return BasketItem * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. * - * @return BasketItem */ public function setAmountVat(float $amountVat): BasketItem { @@ -276,9 +156,9 @@ public function getAmountPerUnit(): float /** * @param float $amountPerUnit * + * @return BasketItem * @deprecated since 1.1.5.0 @see setAmountPerUnitGross * - * @return BasketItem */ public function setAmountPerUnit(float $amountPerUnit): BasketItem { @@ -299,111 +179,13 @@ public function getAmountNet(): float /** * @param float $amountNet * + * @return BasketItem * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. * - * @return BasketItem */ public function setAmountNet(float $amountNet): BasketItem { $this->amountNet = $amountNet; return $this; } - - /** - * @return string|null - */ - public function getUnit(): ?string - { - return $this->unit; - } - - /** - * @param string|null $unit - * - * @return BasketItem - */ - public function setUnit(?string $unit): BasketItem - { - $this->unit = $unit; - return $this; - } - - /** - * @return string - */ - public function getTitle(): string - { - return $this->title; - } - - /** - * @param string $title - * - * @return BasketItem - */ - public function setTitle(string $title): BasketItem - { - $this->title = $title; - return $this; - } - - /** - * @return string|null - */ - public function getImageUrl(): ?string - { - return $this->imageUrl; - } - - /** - * @param string|null $imageUrl - * - * @return BasketItem - */ - public function setImageUrl(?string $imageUrl): BasketItem - { - $this->imageUrl = $imageUrl; - return $this; - } - - /** - * @return string|null - */ - public function getSubTitle(): ?string - { - return $this->subTitle; - } - - /** - * @param string|null $subTitle - * - * @return BasketItem - */ - public function setSubTitle(?string $subTitle): BasketItem - { - $this->subTitle = $subTitle; - return $this; - } - - /** - * @return string|null - */ - public function getType(): ?string - { - return $this->type; - } - - /** - * The type of the basket item. - * Please refer to UnzerSDK\Constants\BasketItemTypes for available type constants. - * - * @param string|null $type - * - * @return BasketItem - */ - public function setType(?string $type): BasketItem - { - $this->type = $type; - return $this; - } } diff --git a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php index 647474d..31dfa91 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php +++ b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php @@ -15,12 +15,7 @@ class SignedMessage extends AbstractUnzerResource /** @var string */ protected $encryptedMessage; - /** - * @param string $tag - * @param string $ephemeralPublicKey - * @param string $encryptedMessage - */ - public function __construct(string $tag = null, string $ephemeralPublicKey = null, string $encryptedMessage = null) + public function __construct(?string $tag = null, ?string $ephemeralPublicKey = null, ?string $encryptedMessage = null) { $this->tag = $tag; $this->ephemeralPublicKey = $ephemeralPublicKey; diff --git a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/PaymentMethodConfig.php b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/PaymentMethodConfig.php index e63914c..1f75a8d 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/PaymentMethodConfig.php +++ b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/PaymentMethodConfig.php @@ -3,6 +3,7 @@ namespace UnzerSDK\Resources\EmbeddedResources\Paypage; use UnzerSDK\Resources\AbstractUnzerResource; +use UnzerSDK\Resources\EmbeddedResources\WeroEventDependentPayment; class PaymentMethodConfig extends AbstractUnzerResource { @@ -15,6 +16,19 @@ class PaymentMethodConfig extends AbstractUnzerResource protected ?bool $credentialOnFile = null; // card only. protected ?string $exemption = null; // card only. + protected ?WeroEventDependentPayment $eventDependentPayment = null; + + public function getEventDependentPayment(): ?WeroEventDependentPayment + { + return $this->eventDependentPayment; + } + + public function setEventDependentPayment(?WeroEventDependentPayment $eventDependentPayment): PaymentMethodConfig + { + $this->eventDependentPayment = $eventDependentPayment; + return $this; + } + /** * @param bool|null $enabled * @param int|null $order @@ -80,4 +94,4 @@ public function setExemption(?string $exemption): PaymentMethodConfig $this->exemption = $exemption; return $this; } -} \ No newline at end of file +} diff --git a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/PaymentMethodsConfigs.php b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/PaymentMethodsConfigs.php index cb150f3..312e865 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/PaymentMethodsConfigs.php +++ b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/PaymentMethodsConfigs.php @@ -11,6 +11,7 @@ class PaymentMethodsConfigs extends AbstractUnzerResource const PAYPAGE_TYPE_NAME_MAPPING = [ 'card' => 'cards', 'eps' => 'eps', + 'openbankingpis' => 'openbankingpis', 'payu' => 'payu', 'postfinanceefinance' => 'pfefinance', 'postfinancecard' => 'pfcard' diff --git a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/Style.php b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/Style.php index 492a47d..1b27cff 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/Style.php +++ b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/Paypage/Style.php @@ -20,6 +20,30 @@ class Style extends AbstractUnzerResource protected ?string $logoImage = null; protected ?string $linkColor = null; protected ?string $textColor = null; + protected ?string $basketBackgroundColor = null; + protected ?string $paymentFormBackgroundColor = null; + + public function getBasketBackgroundColor(): ?string + { + return $this->basketBackgroundColor; + } + + public function setBasketBackgroundColor(?string $basketBackgroundColor): Style + { + $this->basketBackgroundColor = $basketBackgroundColor; + return $this; + } + + public function getPaymentFormBackgroundColor(): ?string + { + return $this->paymentFormBackgroundColor; + } + + public function setPaymentFormBackgroundColor(?string $paymentFormBackgroundColor): Style + { + $this->paymentFormBackgroundColor = $paymentFormBackgroundColor; + return $this; + } public function getHideBasket(): ?bool { diff --git a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/WeroEventDependentPayment.php b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/WeroEventDependentPayment.php new file mode 100644 index 0000000..71e32eb --- /dev/null +++ b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/WeroEventDependentPayment.php @@ -0,0 +1,70 @@ +captureTrigger; + } + + /** + * @see WeroCaptureTriggers for allowed values + */ + public function setCaptureTrigger(?string $captureTrigger): WeroEventDependentPayment + { + $this->captureTrigger = $captureTrigger; + return $this; + } + + public function getAmountPaymentType(): ?string + { + return $this->amountPaymentType; + } + + /** + * @see WeroAmountPaymentTypes for allowed values + */ + public function setAmountPaymentType(?string $amountPaymentType): WeroEventDependentPayment + { + $this->amountPaymentType = $amountPaymentType; + return $this; + } + + public function getMaxAuthToCaptureTime(): ?int + { + return $this->maxAuthToCaptureTime; + } + + public function setMaxAuthToCaptureTime(?int $maxAuthToCaptureTime): WeroEventDependentPayment + { + $this->maxAuthToCaptureTime = $maxAuthToCaptureTime; + return $this; + } + + public function getMultiCapturesAllowed(): ?bool + { + return $this->multiCapturesAllowed; + } + + public function setMultiCapturesAllowed(?bool $multiCapturesAllowed): WeroEventDependentPayment + { + $this->multiCapturesAllowed = $multiCapturesAllowed; + return $this; + } +} diff --git a/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/WeroTransactionData.php b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/WeroTransactionData.php new file mode 100644 index 0000000..e172e4e --- /dev/null +++ b/vendor/unzerdev/php-sdk/src/Resources/EmbeddedResources/WeroTransactionData.php @@ -0,0 +1,48 @@ +eventDependentPayment; + } + + /** + * @param WeroEventDependentPayment|null $eventDependentPayment + * @return WeroTransactionData + */ + public function setEventDependentPayment(?WeroEventDependentPayment $eventDependentPayment): WeroTransactionData + { + $this->eventDependentPayment = $eventDependentPayment; + return $this; + } + + /** + * @inheritDoc + */ + public function handleResponse($response, string $method = HttpAdapterInterface::REQUEST_GET): void + { + parent::handleResponse($response, $method); + if ($response instanceof stdClass && isset($response->eventDependentPayment)) { + $edp = $this->getEventDependentPayment() ?? new WeroEventDependentPayment(); + $edp->handleResponse($response->eventDependentPayment); + $this->setEventDependentPayment($edp); + } + } +} diff --git a/vendor/unzerdev/php-sdk/src/Resources/InstalmentPlan.php b/vendor/unzerdev/php-sdk/src/Resources/InstalmentPlan.php index bcdcf85..3c97695 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/InstalmentPlan.php +++ b/vendor/unzerdev/php-sdk/src/Resources/InstalmentPlan.php @@ -3,10 +3,10 @@ namespace UnzerSDK\Resources; use DateTime; +use stdClass; use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Traits\CanAuthorizeWithCustomer; -use stdClass; /** * Resource representing the installment plan for Installment Secured. @@ -77,17 +77,17 @@ class InstalmentPlan extends BasePaymentType * @param float|null $lastRate */ public function __construct( - int $numberOfRates = null, - string $dayOfPurchase = null, - float $totalPurchaseAmount = null, - float $totalInterestAmount = null, - float $totalAmount = null, - float $effectiveInterestRate = null, - float $nominalInterestRate = null, - float $feeFirstRate = null, - float $feePerRate = null, - float $monthlyRate = null, - float $lastRate = null + ?int $numberOfRates = null, + ?string $dayOfPurchase = null, + ?float $totalPurchaseAmount = null, + ?float $totalInterestAmount = null, + ?float $totalAmount = null, + ?float $effectiveInterestRate = null, + ?float $nominalInterestRate = null, + ?float $feeFirstRate = null, + ?float $feePerRate = null, + ?float $monthlyRate = null, + ?float $lastRate = null ) { $this->numberOfRates = $numberOfRates; $this->dayOfPurchase = $dayOfPurchase; diff --git a/vendor/unzerdev/php-sdk/src/Resources/Payment.php b/vendor/unzerdev/php-sdk/src/Resources/Payment.php index 20f956d..4a75656 100755 --- a/vendor/unzerdev/php-sdk/src/Resources/Payment.php +++ b/vendor/unzerdev/php-sdk/src/Resources/Payment.php @@ -829,11 +829,11 @@ public function getExternalId(): ?string * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ public function cancelAmount( - float $amount = null, + ?float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, - string $paymentReference = null, - float $amountNet = null, - float $amountVat = null + ?string $paymentReference = null, + ?float $amountNet = null, + ?float $amountVat = null ): array { return $this->getUnzerObject()->cancelPayment($this, $amount, $reasonCode, $paymentReference, $amountNet, $amountVat); } @@ -850,7 +850,7 @@ public function cancelAmount( * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function cancelAuthorizationAmount(float $amount = null): ?Cancellation + public function cancelAuthorizationAmount(?float $amount = null): ?Cancellation { return $this->getUnzerObject()->cancelPaymentAuthorization($this, $amount); } @@ -865,7 +865,7 @@ public function cancelAuthorizationAmount(float $amount = null): ?Cancellation * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function charge(float $amount = null): Charge + public function charge(?float $amount = null): Charge { return $this->getUnzerObject()->chargePayment($this, $amount); } @@ -881,7 +881,7 @@ public function charge(float $amount = null): Charge * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function ship(string $invoiceId = null, string $orderId = null) + public function ship(?string $invoiceId = null, ?string $orderId = null) { return $this->getUnzerObject()->ship($this, $invoiceId, $orderId); } diff --git a/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/Card.php b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/Card.php index 3a68888..3ada8c5 100755 --- a/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/Card.php +++ b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/Card.php @@ -2,6 +2,8 @@ namespace UnzerSDK\Resources\PaymentTypes; +use RuntimeException; +use stdClass; use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Resources\EmbeddedResources\CardDetails; use UnzerSDK\Traits\CanAuthorize; @@ -9,8 +11,6 @@ use UnzerSDK\Traits\CanPayout; use UnzerSDK\Traits\CanRecur; use UnzerSDK\Validators\ExpiryDateValidator; -use RuntimeException; -use stdClass; /** * This represents the card payment type which supports credit card as well as debit card payments. @@ -56,7 +56,7 @@ class Card extends BasePaymentType * @param string|null $expiryDate * @param string|null $email */ - public function __construct(?string $number, ?string $expiryDate, string $email = null) + public function __construct(?string $number, ?string $expiryDate, ?string $email = null) { $this->setNumber($number); $this->setExpiryDate($expiryDate); diff --git a/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/InstallmentSecured.php b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/InstallmentSecured.php index 1410d71..15a1dd0 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/InstallmentSecured.php +++ b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/InstallmentSecured.php @@ -34,7 +34,7 @@ class InstallmentSecured extends InstalmentPlan * @param null|DateTime|string $invoiceDate * @param null|DateTime|string $invoiceDueDate */ - public function __construct(InstalmentPlan $selectedPlan = null, $iban = null, $accountHolder = null, $orderDate = null, $bic = null, $invoiceDate = null, $invoiceDueDate = null) + public function __construct(?InstalmentPlan $selectedPlan = null, $iban = null, $accountHolder = null, $orderDate = null, $bic = null, $invoiceDate = null, $invoiceDueDate = null) { parent::__construct(); diff --git a/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/OpenbankingPis.php b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/OpenbankingPis.php index f8e07de..c7fa5af 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/OpenbankingPis.php +++ b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/OpenbankingPis.php @@ -9,7 +9,7 @@ class OpenbankingPis extends BasePaymentType /** @var string|null $ibanCountry */ protected $ibanCountry; - public function __construct(string $ibanCountry = null) + public function __construct(?string $ibanCountry = null) { $this->ibanCountry = $ibanCountry; } diff --git a/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/PaylaterDirectDebit.php b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/PaylaterDirectDebit.php index fb7c3a1..8c89b59 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/PaylaterDirectDebit.php +++ b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/PaylaterDirectDebit.php @@ -12,7 +12,7 @@ class PaylaterDirectDebit extends BasePaymentType /** @var string $holder */ protected $holder; - public function __construct(string $iban = null, string $holder = null) + public function __construct(?string $iban = null, ?string $holder = null) { $this->iban = $iban; $this->holder = $holder; diff --git a/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/Wero.php b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/Wero.php new file mode 100644 index 0000000..93a3f04 --- /dev/null +++ b/vendor/unzerdev/php-sdk/src/Resources/PaymentTypes/Wero.php @@ -0,0 +1,7 @@ +handleRiskData($additionalTransactionData); $this->handleShipping($additionalTransactionData); $this->handleCardTransactionData($additionalTransactionData); + $this->handleWeroTransactionData($additionalTransactionData); } } @@ -223,4 +225,21 @@ protected function handleCardTransactionData(stdClass $additionalTransactionData $this->setCardTransactionData($cardTransactionData); } } + + /** + * Handle WeroTransactionData object contained in additional transaction data from API response. + * + * @param stdClass $additionalTransactionData + * + * @return void + */ + protected function handleWeroTransactionData(stdClass $additionalTransactionData): void + { + $wero = $additionalTransactionData->wero ?? null; + if ($wero !== null) { + $weroTransactionData = $this->getWeroTransactionData() ?? new WeroTransactionData(); + $weroTransactionData->handleResponse($wero); + $this->setWeroTransactionData($weroTransactionData); + } + } } diff --git a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Authorization.php b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Authorization.php index b37ac71..6936b8b 100755 --- a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Authorization.php +++ b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Authorization.php @@ -2,6 +2,7 @@ namespace UnzerSDK\Resources\TransactionTypes; +use RuntimeException; use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\Payment; @@ -9,7 +10,6 @@ use UnzerSDK\Traits\HasCancellations; use UnzerSDK\Traits\HasDescriptor; use UnzerSDK\Traits\HasRecurrenceType; -use RuntimeException; /** * This represents the authorization transaction. @@ -55,7 +55,7 @@ class Authorization extends AbstractTransactionType * @param string|null $currency * @param string|null $returnUrl */ - public function __construct(float $amount = null, string $currency = null, string $returnUrl = null) + public function __construct(?float $amount = null, ?string $currency = null, ?string $returnUrl = null) { $this->setAmount($amount); $this->setCurrency($currency); @@ -250,7 +250,7 @@ protected function getResourcePath(string $httpMethod = HttpAdapterInterface::RE * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function cancel(float $amount = null): Cancellation + public function cancel(?float $amount = null): Cancellation { return $this->getUnzerObject()->cancelAuthorization($this, $amount); } @@ -265,7 +265,7 @@ public function cancel(float $amount = null): Cancellation * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function charge(float $amount = null): Charge + public function charge(?float $amount = null): Charge { $payment = $this->getPayment(); if (!$payment instanceof Payment) { diff --git a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Cancellation.php b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Cancellation.php index 26d92e8..ad41d1c 100755 --- a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Cancellation.php +++ b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Cancellation.php @@ -6,7 +6,6 @@ use UnzerSDK\Constants\CancelReasonCodes; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; - use function in_array; /** @@ -49,7 +48,7 @@ class Cancellation extends AbstractTransactionType * * @param float|null $amount The amount to be cancelled, is transferred as grossAmount in case of Installment Secured. */ - public function __construct(float $amount = null) + public function __construct(?float $amount = null) { $this->setAmount($amount); } diff --git a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Charge.php b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Charge.php index d7f1685..278cc9c 100755 --- a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Charge.php +++ b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Charge.php @@ -2,6 +2,7 @@ namespace UnzerSDK\Resources\TransactionTypes; +use RuntimeException; use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Traits\HasAccountInformation; @@ -9,7 +10,6 @@ use UnzerSDK\Traits\HasChargebacks; use UnzerSDK\Traits\HasDescriptor; use UnzerSDK\Traits\HasRecurrenceType; -use RuntimeException; /** * This represents the charge transaction. @@ -47,7 +47,7 @@ class Charge extends AbstractTransactionType * @param string|null $currency * @param string|null $returnUrl */ - public function __construct(float $amount = null, string $currency = null, string $returnUrl = null) + public function __construct(?float $amount = null, ?string $currency = null, ?string $returnUrl = null) { $this->setAmount($amount); $this->setCurrency($currency); @@ -199,11 +199,11 @@ protected function getResourcePath(string $httpMethod = HttpAdapterInterface::RE * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ public function cancel( - float $amount = null, - string $reasonCode = null, - string $paymentReference = null, - float $amountNet = null, - float $amountVat = null + ?float $amount = null, + ?string $reasonCode = null, + ?string $paymentReference = null, + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { return $this->getUnzerObject()->cancelCharge( $this, diff --git a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Chargeback.php b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Chargeback.php index 7c0c592..2ef22d0 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Chargeback.php +++ b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Chargeback.php @@ -24,7 +24,7 @@ class Chargeback extends AbstractTransactionType /** * @param float|null $amount The amount to be cancelled, is transferred as grossAmount in case of Installment Secured. */ - public function __construct(float $amount = null) + public function __construct(?float $amount = null) { $this->setAmount($amount); } diff --git a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Payout.php b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Payout.php index 39f6a93..15f0767 100644 --- a/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Payout.php +++ b/vendor/unzerdev/php-sdk/src/Resources/TransactionTypes/Payout.php @@ -24,14 +24,7 @@ class Payout extends AbstractTransactionType /** @var string $paymentReference */ protected $paymentReference; - /** - * Payout constructor. - * - * @param float|null $amount - * @param string|null $currency - * @param null $returnUrl - */ - public function __construct(float $amount = null, string $currency = null, $returnUrl = null) + public function __construct(?float $amount = null, ?string $currency = null, $returnUrl = null) { $this->setAmount($amount); $this->setCurrency($currency); diff --git a/vendor/unzerdev/php-sdk/src/Resources/V2/BasketItemProperties.php b/vendor/unzerdev/php-sdk/src/Resources/V2/BasketItemProperties.php new file mode 100644 index 0000000..fb5dc95 --- /dev/null +++ b/vendor/unzerdev/php-sdk/src/Resources/V2/BasketItemProperties.php @@ -0,0 +1,254 @@ +title = $title; + $this->quantity = $quantity; + $this->setAmountPerUnitGross($amountNet); + $this->setAmountPerUnit($amountPerUnit); + } + + /** + * @return string|null + */ + public function getBasketItemReferenceId(): ?string + { + return $this->basketItemReferenceId; + } + + /** + * @param string|null $basketItemReferenceId + * + * @return BasketItem + */ + public function setBasketItemReferenceId(?string $basketItemReferenceId): BasketItem + { + $this->basketItemReferenceId = $basketItemReferenceId; + return $this; + } + + /** + * @return int + */ + public function getQuantity(): int + { + return $this->quantity; + } + + /** + * @param int $quantity + * + * @return BasketItem + */ + public function setQuantity(int $quantity): self + { + $this->quantity = $quantity; + return $this; + } + + /** + * @return float + */ + public function getVat(): float + { + return $this->vat; + } + + /** + * @param float $vat + * + * @return BasketItem + */ + public function setVat(float $vat): BasketItem + { + $this->vat = $vat; + return $this; + } + + /** + * @return float + */ + public function getAmountDiscountPerUnitGross(): float + { + return $this->amountDiscountPerUnitGross; + } + + /** + * @param float $amountDiscountPerUnitGross + * + * @return BasketItem + */ + public function setAmountDiscountPerUnitGross(float $amountDiscountPerUnitGross): BasketItem + { + $this->amountDiscountPerUnitGross = $amountDiscountPerUnitGross; + return $this; + } + + /** + * @return float + */ + public function getAmountPerUnitGross(): float + { + return $this->amountPerUnitGross; + } + + /** + * @param float $amountPerUnitGross + * + * @return BasketItem + */ + public function setAmountPerUnitGross(float $amountPerUnitGross): BasketItem + { + $this->amountPerUnitGross = $amountPerUnitGross; + return $this; + } + + /** + * @return string|null + */ + public function getUnit(): ?string + { + return $this->unit; + } + + /** + * @param string|null $unit + * + * @return BasketItem + */ + public function setUnit(?string $unit): self + { + $this->unit = $unit; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $title + * + * @return BasketItem + */ + public function setTitle(string $title): self + { + $this->title = $title; + return $this; + } + + /** + * @return string|null + */ + public function getImageUrl(): ?string + { + return $this->imageUrl; + } + + /** + * @param string|null $imageUrl + * + * @return BasketItem + */ + public function setImageUrl(?string $imageUrl): self + { + $this->imageUrl = $imageUrl; + return $this; + } + + /** + * @return string|null + */ + public function getSubTitle(): ?string + { + return $this->subTitle; + } + + /** + * @param string|null $subTitle + * + * @return BasketItem + */ + public function setSubTitle(?string $subTitle): self + { + $this->subTitle = $subTitle; + return $this; + } + + /** + * @return string|null + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * The type of the basket item. + * Please refer to UnzerSDK\Constants\BasketItemTypes for available type constants. + * + * @param string|null $type + * + * @return BasketItem + */ + public function setType(?string $type): BasketItem + { + $this->type = $type; + return $this; + } +} \ No newline at end of file diff --git a/vendor/unzerdev/php-sdk/src/Resources/V2/BasketProperties.php b/vendor/unzerdev/php-sdk/src/Resources/V2/BasketProperties.php new file mode 100644 index 0000000..d19c17a --- /dev/null +++ b/vendor/unzerdev/php-sdk/src/Resources/V2/BasketProperties.php @@ -0,0 +1,158 @@ +totalValueGross; + } + + /** + * @param float $totalValueGross + * + * @return Basket + */ + public function setTotalValueGross(float $totalValueGross): Basket + { + $this->totalValueGross = $totalValueGross; + return $this; + } + + /** + * @return string + */ + public function getCurrencyCode(): string + { + return $this->currencyCode; + } + + /** + * @param string $currencyCode + * + * @return Basket + */ + public function setCurrencyCode(string $currencyCode): Basket + { + $this->currencyCode = $currencyCode; + return $this; + } + + /** + * @return int + */ + public function getItemCount(): int + { + return count($this->basketItems); + } + + /** + * @return string|null + */ + public function getNote(): ?string + { + return $this->note; + } + + /** + * @param string|null $note + * + * @return Basket + */ + public function setNote(?string $note): Basket + { + $this->note = $note; + return $this; + } + + /** + * @return string + */ + public function getOrderId(): string + { + return $this->orderId; + } + + /** + * @param string $orderId + * + * @return Basket + */ + public function setOrderId(string $orderId): Basket + { + $this->orderId = $orderId; + return $this; + } + + /** + * @return array + */ + public function getBasketItems(): array + { + return $this->basketItems; + } + + /** + * @param array $basketItems + * + * @return Basket + */ + public function setBasketItems(array $basketItems): Basket + { + $this->basketItems = []; + + foreach ($basketItems as $basketItem) { + $this->addBasketItem($basketItem); + } + + return $this; + } + + /** + * Adds the given BasketItem to the Basket. + * + * @param BasketItem $basketItem + * + * @return Basket + */ + public function addBasketItem(BasketItem $basketItem): Basket + { + $this->basketItems[] = $basketItem; + if ($basketItem->getBasketItemReferenceId() === null) { + $basketItem->setBasketItemReferenceId((string)$this->getKeyOfLastBasketItemAdded()); + } + return $this; + } + + /** + * @param int $index + * + * @return BasketItem|null + */ + public function getBasketItemByIndex(int $index): ?BasketItem + { + return $this->basketItems[$index] ?? null; + } +} diff --git a/vendor/unzerdev/php-sdk/src/Resources/V2/Customer.php b/vendor/unzerdev/php-sdk/src/Resources/V2/Customer.php new file mode 100644 index 0000000..528b1d7 --- /dev/null +++ b/vendor/unzerdev/php-sdk/src/Resources/V2/Customer.php @@ -0,0 +1,31 @@ +orderId = $orderId; + $this->setTotalValueGross($totalValueGross); + $this->currencyCode = $currencyCode; + $this->setBasketItems($basketItems); + } + + public function getApiVersion(): string + { + return ApiVersions::V3; + } + + public function getApiConfig(): string + { + return PaymentApiConfigBearerAuth::class; + } +} diff --git a/vendor/unzerdev/php-sdk/src/Services/CancelService.php b/vendor/unzerdev/php-sdk/src/Services/CancelService.php index 354cb90..3710617 100644 --- a/vendor/unzerdev/php-sdk/src/Services/CancelService.php +++ b/vendor/unzerdev/php-sdk/src/Services/CancelService.php @@ -12,7 +12,6 @@ use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\Unzer; - use function in_array; use function is_string; @@ -67,7 +66,7 @@ public function getResourceService(): ResourceService /** * {@inheritDoc} */ - public function cancelAuthorization(Authorization $authorization, float $amount = null): Cancellation + public function cancelAuthorization(Authorization $authorization, ?float $amount = null): Cancellation { $cancellation = new Cancellation($amount); $cancellation->setPayment($authorization->getPayment())->setParentResource($authorization); @@ -80,7 +79,7 @@ public function cancelAuthorization(Authorization $authorization, float $amount /** * {@inheritDoc} */ - public function cancelAuthorizationByPayment($payment, float $amount = null): Cancellation + public function cancelAuthorizationByPayment($payment, ?float $amount = null): Cancellation { $authorization = $this->getResourceService()->fetchAuthorization($payment); return $this->cancelAuthorization($authorization, $amount); @@ -92,11 +91,11 @@ public function cancelAuthorizationByPayment($payment, float $amount = null): Ca public function cancelChargeById( $payment, string $chargeId, - float $amount = null, - string $reasonCode = null, - string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amount = null, + ?string $reasonCode = null, + ?string $referenceText = null, + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { $charge = $this->getResourceService()->fetchChargeById($payment, $chargeId); return $this->cancelCharge($charge, $amount, $reasonCode, $referenceText, $amountNet, $amountVat); @@ -107,11 +106,11 @@ public function cancelChargeById( */ public function cancelCharge( Charge $charge, - float $amount = null, - string $reasonCode = null, - string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amount = null, + ?string $reasonCode = null, + ?string $referenceText = null, + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { $cancellation = new Cancellation($amount); $cancellation @@ -131,11 +130,11 @@ public function cancelCharge( */ public function cancelPayment( $payment, - float $amount = null, + ?float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, - string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?string $referenceText = null, + ?float $amountNet = null, + ?float $amountVat = null ): array { $paymentObject = $payment; if (is_string($payment)) { @@ -186,7 +185,7 @@ public function cancelPayment( /** * {@inheritDoc} */ - public function cancelPaymentAuthorization($payment, float $amount = null): ?Cancellation + public function cancelPaymentAuthorization($payment, ?float $amount = null): ?Cancellation { $cancellation = null; $completeCancel = $amount === null; diff --git a/vendor/unzerdev/php-sdk/src/Services/HttpService.php b/vendor/unzerdev/php-sdk/src/Services/HttpService.php index e8b4866..cce644c 100755 --- a/vendor/unzerdev/php-sdk/src/Services/HttpService.php +++ b/vendor/unzerdev/php-sdk/src/Services/HttpService.php @@ -18,7 +18,6 @@ * This service provides for functionalities concerning http transactions. * * @link https://docs.unzer.com/ - * */ class HttpService { @@ -82,32 +81,32 @@ public function setEnvironmentService(EnvironmentService $environmentService): H } /** - * @deprecated use sendRequest() instead. - * * send post request to payment server * - * @param $uri string|null uri of the target system - * @param ?AbstractUnzerResource $resource - * @param string $httpMethod - * @param string $apiVersion + * @param string|null $uri uri of the target system + * @param AbstractUnzerResource|null $resource + * @param string $httpMethod + * @param string|null $apiVersion * * @return string * * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. + * @deprecated use sendRequest() instead. */ public function send( ?string $uri = null, ?AbstractUnzerResource $resource = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET, - string $apiVersion = Unzer::API_VERSION - ): string { + ?string $apiVersion = null + ): string + { if (!$resource instanceof AbstractUnzerResource) { throw new RuntimeException('Transfer object is empty!'); } $unzerObj = $resource->getUnzerObject(); - $apiRequest = (new ApiRequest($uri, $resource, $httpMethod, $unzerObj, $apiVersion)); + $apiRequest = (new ApiRequest($uri, $resource, $httpMethod, $unzerObj, $apiVersion ?? $resource->getApiVersion())); return $this->sendRequest($apiRequest); } @@ -115,15 +114,11 @@ public function send( /** * send post request to payment server * - * @param ApiRequest $request - * @return string - * * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ - public function sendRequest( - ApiRequest $request - ): string { + public function sendRequest(ApiRequest $request): string + { $unzerObj = $request->getResource()->getUnzerObject(); $apiConfig = $request->getResource()->getApiConfig(); @@ -137,8 +132,8 @@ public function sendRequest( $headers = $this->composeHttpHeaders($unzerObj, $apiConfig::getAuthorizationMethod()); $httpMethod = $request->getHttpMethod(); $this->initRequest($requestUrl, $payload, $httpMethod, $headers); - $httpAdapter = $this->getAdapter(); - $response = $httpAdapter->execute(); + $httpAdapter = $this->getAdapter(); + $response = $httpAdapter->execute(); $responseCode = $httpAdapter->getResponseCode(); $httpAdapter->close(); @@ -158,7 +153,7 @@ public function sendRequest( * @param string $uri * @param string $payload * @param string $httpMethod - * @param array $httpHeaders + * @param array $httpHeaders * * @throws RuntimeException */ @@ -174,7 +169,7 @@ private function initRequest(string $uri, string $payload, string $httpMethod, a * Handles error responses by throwing an UnzerApiException with the returned messages and error code. * Returns doing nothing if no error occurred. * - * @param string $responseCode + * @param string $responseCode * @param string|null $response * * @throws UnzerApiException @@ -187,15 +182,15 @@ private function handleErrors(string $responseCode, ?string $response): void $responseObject = json_decode($response, false); if (!is_numeric($responseCode) || (int)$responseCode >= 400 || isset($responseObject->errors)) { - $code = null; - $errorId = null; + $code = null; + $errorId = null; $customerMessage = $code; $merchantMessage = $customerMessage; if (isset($responseObject->errors[0])) { - $errors = $responseObject->errors[0]; + $errors = $responseObject->errors[0]; $merchantMessage = $errors->merchantMessage ?? ''; $customerMessage = $errors->customerMessage ?? ''; - $code = $errors->code ?? ''; + $code = $errors->code ?? ''; } if (isset($responseObject->id)) { $errorId = $responseObject->id; @@ -209,23 +204,24 @@ private function handleErrors(string $responseCode, ?string $response): void } /** - * @param Unzer $unzerObj - * @param string $payload - * @param mixed $headers - * @param string $responseCode - * @param string $httpMethod - * @param string $url + * @param Unzer $unzerObj + * @param string $payload + * @param mixed $headers + * @param string $responseCode + * @param string $httpMethod + * @param string $url * @param string|null $response */ public function debugLog( Unzer $unzerObj, string $payload, - $headers, - string $responseCode, + $headers, + string $responseCode, string $httpMethod, string $url, ?string $response - ): void { + ): void + { // mask auth string $authHeader = explode(' ', $headers['Authorization']); $authHeader[1] = ValueService::maskValue($authHeader[1]); @@ -275,16 +271,16 @@ private function buildRequestUrl(ApiRequest $request): string */ public function composeHttpHeaders(Unzer $unzer, string $authorizationMethod = AuthorizationMethods::BASIC): array { - $locale = $unzer->getLocale(); - $clientIp = $unzer->getClientIp(); - $key = $unzer->getKey(); + $locale = $unzer->getLocale(); + $clientIp = $unzer->getClientIp(); + $key = $unzer->getKey(); $httpHeaders = [ 'Authorization' => $this->findAuthentication($unzer, $authorizationMethod), - 'Content-Type' => 'application/json', - 'SDK-VERSION' => Unzer::SDK_VERSION, - 'SDK-TYPE' => Unzer::SDK_TYPE, - 'PHP-VERSION' => PHP_VERSION + 'Content-Type' => 'application/json', + 'SDK-VERSION' => Unzer::SDK_VERSION, + 'SDK-TYPE' => Unzer::SDK_TYPE, + 'PHP-VERSION' => PHP_VERSION ]; if (!empty($locale)) { $httpHeaders['Accept-Language'] = $locale; @@ -347,6 +343,7 @@ public function isApiConfig($className): bool /** * @param Unzer $unzer + * * @return string */ private function findAuthentication(Unzer $unzer, string $authorizationMethod = AuthorizationMethods::BASIC): string diff --git a/vendor/unzerdev/php-sdk/src/Services/IdService.php b/vendor/unzerdev/php-sdk/src/Services/IdService.php index aecb23b..231ba17 100755 --- a/vendor/unzerdev/php-sdk/src/Services/IdService.php +++ b/vendor/unzerdev/php-sdk/src/Services/IdService.php @@ -3,7 +3,6 @@ namespace UnzerSDK\Services; use RuntimeException; - use function count; /** @@ -22,7 +21,7 @@ class IdService * * @param string $url * @param string $idString - * @param bool $onlyLast + * @param bool $onlyLast * * @return string * @@ -31,7 +30,7 @@ class IdService public static function getResourceIdFromUrl(string $url, string $idString, bool $onlyLast = false): string { $matches = []; - $pattern = '/\/([s|p]{1}-' . $idString . '-[a-z\d]+)\/?' . ($onlyLast ? '$' : '') . '/'; + $pattern = '/\/([s|p]{1}-' . $idString . '-[a-z\d-]+)\/?' . ($onlyLast ? '$' : '') . '/'; preg_match($pattern, $url, $matches); if (count($matches) < 2) { @@ -76,7 +75,7 @@ public static function isPaymentChargeback(string $url): string * * @param string $url * @param string $idString - * @param bool $onlyLast + * @param bool $onlyLast * * @return string|null */ @@ -117,4 +116,10 @@ public static function getResourceTypeFromIdString(string $typeId): ?string return $typeIdString; } + + public static function isUUIDResource(string $id): bool + { + preg_match('/^[sp]-([a-z]{3}|p24)-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/', $id, $matches); + return count($matches) > 0; + } } diff --git a/vendor/unzerdev/php-sdk/src/Services/JwtService.php b/vendor/unzerdev/php-sdk/src/Services/JwtService.php index 57bdee9..2d12f96 100644 --- a/vendor/unzerdev/php-sdk/src/Services/JwtService.php +++ b/vendor/unzerdev/php-sdk/src/Services/JwtService.php @@ -9,12 +9,11 @@ class JwtService public static function validateExpiryTime(string $jwt, int $expiryBufferSeconds = self::Expiry_Buffer): bool { $jwtData = self::extractPayload($jwt); - $expireTime = $jwtData['exp']; - $currentTime = time(); - return ($expireTime - $expiryBufferSeconds) > $currentTime; + $expireTime = $jwtData['exp'] ?? 0; + return ($expireTime - $expiryBufferSeconds) > time(); } - private static function extractPayload(string $jwt) + private static function extractPayload(string $jwt): ?array { $tokenSegments = explode('.', $jwt); return json_decode(base64_decode($tokenSegments[1]), true); diff --git a/vendor/unzerdev/php-sdk/src/Services/PaymentService.php b/vendor/unzerdev/php-sdk/src/Services/PaymentService.php index c59cd81..8eefc35 100755 --- a/vendor/unzerdev/php-sdk/src/Services/PaymentService.php +++ b/vendor/unzerdev/php-sdk/src/Services/PaymentService.php @@ -73,12 +73,15 @@ public function getResourceService(): ResourceService return $this->getUnzer()->getResourceService(); } + /** + * {@inheritDoc} + */ public function performAuthorization( Authorization $authorization, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Authorization { $payment = $this->createPayment($paymentType); $paymentType = $payment->getPaymentType(); @@ -144,7 +147,7 @@ public function authorize( /** * {@inheritDoc} */ - public function performCharge(Charge $charge, $paymentType, $customer = null, Metadata $metadata = null, Basket $basket = null): Charge + public function performCharge(Charge $charge, $paymentType, $customer = null, ?Metadata $metadata = null, ?Basket $basket = null): Charge { $payment = $this->createPayment($paymentType); $paymentType = $payment->getPaymentType(); @@ -214,9 +217,9 @@ public function charge( */ public function chargeAuthorization( $payment, - float $amount = null, - string $orderId = null, - string $invoiceId = null + ?float $amount = null, + ?string $orderId = null, + ?string $invoiceId = null ): Charge { return $this->chargePayment($payment, $amount, $orderId, $invoiceId); } @@ -226,9 +229,9 @@ public function chargeAuthorization( */ public function chargePayment( $payment, - float $amount = null, - string $orderId = null, - string $invoiceId = null + ?float $amount = null, + ?string $orderId = null, + ?string $invoiceId = null ): Charge { $charge = new Charge($amount); @@ -263,11 +266,11 @@ public function payout( $paymentType, string $returnUrl, $customer = null, - string $orderId = null, - Metadata $metadata = null, - Basket $basket = null, - string $invoiceId = null, - string $referenceText = null + ?string $orderId = null, + ?Metadata $metadata = null, + ?Basket $basket = null, + ?string $invoiceId = null, + ?string $referenceText = null ): Payout { $payment = $this->createPayment($paymentType); $payout = (new Payout($amount, $currency, $returnUrl)) @@ -283,7 +286,7 @@ public function payout( /** * {@inheritDoc} */ - public function ship($payment, string $invoiceId = null, string $orderId = null): Shipment + public function ship($payment, ?string $invoiceId = null, ?string $orderId = null): Shipment { $shipment = new Shipment(); $shipment->setInvoiceId($invoiceId)->setOrderId($orderId); @@ -297,9 +300,9 @@ public function ship($payment, string $invoiceId = null, string $orderId = null) */ public function initPayPageCharge( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { return $this->initPayPage($paypage, TransactionTypes::CHARGE, $customer, $basket, $metadata); } @@ -309,9 +312,9 @@ public function initPayPageCharge( */ public function initPayPageAuthorize( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { return $this->initPayPage($paypage, TransactionTypes::AUTHORIZATION, $customer, $basket, $metadata); } @@ -323,7 +326,7 @@ public function fetchInstallmentPlans( float $amount, string $currency, float $effectiveInterest, - DateTime $orderDate = null + ?DateTime $orderDate = null ): InstalmentPlans { $ins = (new InstallmentSecured(null, null, null))->setParentResource($this->unzer); $plans = (new InstalmentPlans($amount, $currency, $effectiveInterest, $orderDate))->setParentResource($ins); @@ -365,9 +368,9 @@ public function fetchPaylaterInstallmentPlans( private function initPayPage( Paypage $paypage, string $action, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { $paypage->setAction($action)->setParentResource($this->unzer); $payment = $this->createPayment($paypage)->setBasket($basket)->setCustomer($customer)->setMetadata($metadata)->setPayPage($paypage); diff --git a/vendor/unzerdev/php-sdk/src/Services/ResourceService.php b/vendor/unzerdev/php-sdk/src/Services/ResourceService.php index 6de8c08..b4bedfe 100755 --- a/vendor/unzerdev/php-sdk/src/Services/ResourceService.php +++ b/vendor/unzerdev/php-sdk/src/Services/ResourceService.php @@ -9,6 +9,7 @@ use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Apis\Constants\AuthorizationMethods; use UnzerSDK\Constants\ApiResponseCodes; +use UnzerSDK\Constants\ApiVersions; use UnzerSDK\Constants\IdStrings; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Interfaces\ResourceServiceInterface; @@ -51,6 +52,7 @@ use UnzerSDK\Resources\PaymentTypes\Sofort; use UnzerSDK\Resources\PaymentTypes\Twint; use UnzerSDK\Resources\PaymentTypes\Wechatpay; +use UnzerSDK\Resources\PaymentTypes\Wero; use UnzerSDK\Resources\Recurring; use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Cancellation; @@ -58,7 +60,9 @@ use UnzerSDK\Resources\TransactionTypes\Chargeback; use UnzerSDK\Resources\TransactionTypes\Payout; use UnzerSDK\Resources\TransactionTypes\Shipment; +use UnzerSDK\Resources\V2\Customer as CustomerV2; use UnzerSDK\Resources\V2\Paypage as PaypageV2; +use UnzerSDK\Resources\V3\Basket as BasketV3; use UnzerSDK\Traits\CanRecur; use UnzerSDK\Unzer; use function in_array; @@ -106,8 +110,8 @@ public function setUnzer(Unzer $unzer): ResourceServiceInterface * Send request to API. * * @param AbstractUnzerResource $resource - * @param string $httpMethod - * @param string $apiVersion + * @param string $httpMethod + * @param string|null $apiVersion * * @return stdClass * @@ -117,15 +121,16 @@ public function setUnzer(Unzer $unzer): ResourceServiceInterface public function send( AbstractUnzerResource $resource, string $httpMethod = HttpAdapterInterface::REQUEST_GET, - string $apiVersion = Unzer::API_VERSION - ): stdClass { - $configClass = $resource->getApiConfig(); - if (!$resource instanceof Token && $configClass::getAuthorizationMethod() === AuthorizationMethods::BEARER) { + ?string $apiVersion = null + ): stdClass + { + $apiConfig = $resource->getApiConfig(); + if (!$resource instanceof Token && $apiConfig::getAuthorizationMethod() === AuthorizationMethods::BEARER) { $this->unzer->prepareJwtToken(); } - $appendId = $httpMethod !== HttpAdapterInterface::REQUEST_POST; - $uri = $resource->getUri($appendId, $httpMethod); + $appendId = $httpMethod !== HttpAdapterInterface::REQUEST_POST; + $uri = $resource->getUri($appendId, $httpMethod); $responseJson = $resource->getUnzerObject()->getHttpService()->send($uri, $resource, $httpMethod, $apiVersion); return !empty($responseJson) ? json_decode($responseJson, false) : new stdClass(); } @@ -159,9 +164,9 @@ public function getResource(AbstractUnzerResource $resource): AbstractUnzerResou public function fetchResourceByUrl($url) { $resource = null; - $unzer = $this->unzer; + $unzer = $this->unzer; - $resourceId = IdService::getLastResourceIdFromUrlString($url); + $resourceId = IdService::getLastResourceIdFromUrlString($url); if (empty($resourceId)) { return null; } @@ -187,8 +192,8 @@ public function fetchResourceByUrl($url) ); break; case $resourceType === IdStrings::CANCEL: - $paymentId = IdService::getResourceIdFromUrl($url, IdStrings::PAYMENT); - $chargeId = IdService::getResourceIdOrNullFromUrl($url, IdStrings::CHARGE); + $paymentId = IdService::getResourceIdFromUrl($url, IdStrings::PAYMENT); + $chargeId = IdService::getResourceIdOrNullFromUrl($url, IdStrings::CHARGE); if (IdService::isPaymentCancellation($url)) { $isRefund = preg_match('/charge/', $url) === 1; if ($isRefund) { @@ -333,8 +338,8 @@ public function deleteResource(AbstractUnzerResource &$resource): ?AbstractUnzer /** * Updates the given local resource object (id must be set) * - * @param AbstractUnzerResource $resource The local resource object to update. - * @param string $apiVersion + * @param AbstractUnzerResource $resource The local resource object to update. + * @param string|null $apiVersion * * @return AbstractUnzerResource The updated resource object. * @@ -342,7 +347,7 @@ public function deleteResource(AbstractUnzerResource &$resource): ?AbstractUnzer * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. * @throws Exception */ - public function fetchResource(AbstractUnzerResource $resource, string $apiVersion = Unzer::API_VERSION): AbstractUnzerResource + public function fetchResource(AbstractUnzerResource $resource, ?string $apiVersion = null): AbstractUnzerResource { $method = HttpAdapterInterface::REQUEST_GET; $response = $this->send($resource, $method, $apiVersion); @@ -375,7 +380,7 @@ public function fetchPayout($payment): Payout /** * {@inheritDoc} */ - public function activateRecurringPayment($paymentType, string $returnUrl, string $recurrenceType = null): Recurring + public function activateRecurringPayment($paymentType, string $returnUrl, ?string $recurrenceType = null): Recurring { $paymentTypeObject = $paymentType; if (is_string($paymentType)) { @@ -549,15 +554,20 @@ public function createBasket(Basket $basket): Basket public function fetchBasket($basket): Basket { $basketObj = $basket; + if (is_string($basket)) { - $basketObj = (new Basket())->setId($basket); + $isV3Basket = IdService::isUUIDResource($basket); + $basketObj = $isV3Basket ? new BasketV3() : new Basket(); + $basketObj->setId($basket); } + $basketObj->setParentResource($this->unzer); + $basketVersion = $basketObj->getApiVersion() === ApiVersions::V3 ? ApiVersions::V3 : ApiVersions::V2; try { - $this->fetchResource($basketObj, 'v2'); + $this->fetchResource($basketObj, $basketVersion); } catch (UnzerApiException $exception) { - if ($exception->getCode() !== ApiResponseCodes::API_ERROR_BASKET_NOT_FOUND) { + if ($exception->getCode() !== ApiResponseCodes::API_ERROR_BASKET_NOT_FOUND || $basketVersion === ApiVersions::V3) { throw $exception; } $this->fetchResource($basketObj); @@ -648,7 +658,9 @@ public function fetchCustomer($customer): Customer $customerObject = $customer; if (is_string($customer)) { - $customerObject = (new Customer())->setId($customer); + $isUUID = IdService::isUUIDResource($customer); + $customerObject = $isUUID ? new CustomerV2() : new Customer(); + $customerObject->setId($customer); } $this->fetchResource($customerObject->setParentResource($this->unzer)); @@ -658,7 +670,7 @@ public function fetchCustomer($customer): Customer /** * {@inheritDoc} */ - public function fetchCustomerByExtCustomerId(string $customerId): Customer + public function fetchCustomerByExtCustomerId(string $customerId, int $version = 1): Customer { $customerObject = (new Customer())->setCustomerId($customerId); $this->fetchResource($customerObject->setParentResource($this->unzer)); @@ -946,6 +958,9 @@ public static function getTypeInstanceFromIdString($typeId): BasePaymentType case IdStrings::WECHATPAY: $paymentType = new Wechatpay(); break; + case IdStrings::WERO: + $paymentType = new Wero(); + break; case IdStrings::OPEN_BANKING: $paymentType = new OpenbankingPis(); break; diff --git a/vendor/unzerdev/php-sdk/src/Services/WebhookService.php b/vendor/unzerdev/php-sdk/src/Services/WebhookService.php index c8117d1..a273bb5 100755 --- a/vendor/unzerdev/php-sdk/src/Services/WebhookService.php +++ b/vendor/unzerdev/php-sdk/src/Services/WebhookService.php @@ -2,14 +2,13 @@ namespace UnzerSDK\Services; -use UnzerSDK\Unzer; +use RuntimeException; use UnzerSDK\Interfaces\ResourceServiceInterface; use UnzerSDK\Interfaces\WebhookServiceInterface; use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\Webhook; use UnzerSDK\Resources\Webhooks; -use RuntimeException; - +use UnzerSDK\Unzer; use function is_string; /** @@ -165,7 +164,7 @@ public function registerMultipleWebhooks(string $url, array $events): array /** * {@inheritDoc} */ - public function fetchResourceFromEvent(string $eventJson = null): AbstractUnzerResource + public function fetchResourceFromEvent(?string $eventJson = null): AbstractUnzerResource { $resourceObject = null; $eventData = json_decode($eventJson ?? $this->readInputStream(), false); diff --git a/vendor/unzerdev/php-sdk/src/Traits/CanPayout.php b/vendor/unzerdev/php-sdk/src/Traits/CanPayout.php index 4458e68..f03042d 100644 --- a/vendor/unzerdev/php-sdk/src/Traits/CanPayout.php +++ b/vendor/unzerdev/php-sdk/src/Traits/CanPayout.php @@ -8,13 +8,13 @@ namespace UnzerSDK\Traits; +use RuntimeException; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Interfaces\UnzerParentInterface; use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\TransactionTypes\Payout; -use RuntimeException; trait CanPayout { @@ -44,11 +44,11 @@ public function payout( string $currency, string $returnUrl, $customer = null, - string $orderId = null, + ?string $orderId = null, $metadata = null, - Basket $basket = null, - string $invoiceId = null, - string $paymentReference = null + ?Basket $basket = null, + ?string $invoiceId = null, + ?string $paymentReference = null ): Payout { if ($this instanceof UnzerParentInterface) { return $this->getUnzerObject()->payout( diff --git a/vendor/unzerdev/php-sdk/src/Traits/CanPayoutWithCustomer.php b/vendor/unzerdev/php-sdk/src/Traits/CanPayoutWithCustomer.php index 389a4bf..76c5673 100644 --- a/vendor/unzerdev/php-sdk/src/Traits/CanPayoutWithCustomer.php +++ b/vendor/unzerdev/php-sdk/src/Traits/CanPayoutWithCustomer.php @@ -8,13 +8,13 @@ namespace UnzerSDK\Traits; +use RuntimeException; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Interfaces\UnzerParentInterface; use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\TransactionTypes\Payout; -use RuntimeException; trait CanPayoutWithCustomer { @@ -42,9 +42,9 @@ public function payout( string $currency, string $returnUrl, $customer, - string $orderId = null, + ?string $orderId = null, $metadata = null, - Basket $basket = null + ?Basket $basket = null ): Payout { if ($this instanceof UnzerParentInterface) { return $this->getUnzerObject()->payout( diff --git a/vendor/unzerdev/php-sdk/src/Traits/HasAdditionalTransactionData.php b/vendor/unzerdev/php-sdk/src/Traits/HasAdditionalTransactionData.php index 3dcd4b2..ff8ced7 100644 --- a/vendor/unzerdev/php-sdk/src/Traits/HasAdditionalTransactionData.php +++ b/vendor/unzerdev/php-sdk/src/Traits/HasAdditionalTransactionData.php @@ -14,6 +14,7 @@ use UnzerSDK\Resources\EmbeddedResources\CardTransactionData; use UnzerSDK\Resources\EmbeddedResources\RiskData; use UnzerSDK\Resources\EmbeddedResources\ShippingData; +use UnzerSDK\Resources\EmbeddedResources\WeroTransactionData; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType; use UnzerSDK\Services\ResourceService; @@ -221,4 +222,29 @@ public function setCardTransactionData(?CardTransactionData $cardTransactionData $this->addAdditionalTransactionData(AdditionalTransactionDataKeys::CARD, $cardTransactionData); return $this; } + + /** + * Get the wero field from additional transaction Data. + * + * @return WeroTransactionData|null "wero" object of additionalTransaction data. + */ + public function getWeroTransactionData(): ?WeroTransactionData + { + $key = AdditionalTransactionDataKeys::WERO; + $wero = $this->getAdditionalTransactionData()->$key ?? null; + return $wero instanceof WeroTransactionData ? $wero : null; + } + + /** + * Sets WeroTransactionData object as "wero" field of additionalTransactionData. + * + * @param WeroTransactionData|null $weroTransactionData + * + * @return self + */ + public function setWeroTransactionData(?WeroTransactionData $weroTransactionData): self + { + $this->addAdditionalTransactionData(AdditionalTransactionDataKeys::WERO, $weroTransactionData); + return $this; + } } diff --git a/vendor/unzerdev/php-sdk/src/Unzer.php b/vendor/unzerdev/php-sdk/src/Unzer.php index 733b7e3..b4dc186 100644 --- a/vendor/unzerdev/php-sdk/src/Unzer.php +++ b/vendor/unzerdev/php-sdk/src/Unzer.php @@ -5,6 +5,7 @@ use DateTime; use RuntimeException; use UnzerSDK\Adapter\HttpAdapterInterface; +use UnzerSDK\Constants\ApiVersions; use UnzerSDK\Constants\CancelReasonCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Interfaces\CancelServiceInterface; @@ -55,9 +56,9 @@ class Unzer implements CancelServiceInterface { public const BASE_URL = 'api.unzer.com'; - public const API_VERSION = 'v1'; + public const API_VERSION = ApiVersions::V1; public const SDK_TYPE = 'UnzerPHP'; - public const SDK_VERSION = '3.11.0'; + public const SDK_VERSION = '3.13.1'; /** @var string $key */ private $key; @@ -94,7 +95,7 @@ class Unzer implements * Construct a new Unzer object. * * @param string $key The private key your received from your Unzer contact person. - * @param ?string $locale The locale of the customer defining defining the translation (e.g. 'en-GB' or 'de-DE'). + * @param string|null $locale The locale of the customer defining defining the translation (e.g. 'en-GB' or 'de-DE'). * * @throws RuntimeException A RuntimeException will be thrown if the key is not of type private. * @@ -357,7 +358,7 @@ public function getUri(bool $appendId = true, string $httpMethod = HttpAdapterIn /** * {@inheritDoc} */ - public function activateRecurringPayment($paymentType, string $returnUrl, string $recurrenceType = null): Recurring + public function activateRecurringPayment($paymentType, string $returnUrl, ?string $recurrenceType = null): Recurring { return $this->resourceService->activateRecurringPayment($paymentType, $returnUrl, $recurrenceType); } @@ -485,9 +486,9 @@ public function fetchCustomer($customer): Customer /** * {@inheritDoc} */ - public function fetchCustomerByExtCustomerId(string $customerId): Customer + public function fetchCustomerByExtCustomerId(string $customerId, int $version = 1): Customer { - return $this->resourceService->fetchCustomerByExtCustomerId($customerId); + return $this->resourceService->fetchCustomerByExtCustomerId($customerId, $version); } /** @@ -666,7 +667,7 @@ public function registerMultipleWebhooks(string $url, array $events): array /** * {@inheritDoc} */ - public function fetchResourceFromEvent(string $eventJson = null): AbstractUnzerResource + public function fetchResourceFromEvent(?string $eventJson = null): AbstractUnzerResource { return $this->webhookService->fetchResourceFromEvent($eventJson); } @@ -678,8 +679,8 @@ public function performAuthorization( Authorization $authorization, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Authorization { return $this->paymentService->performAuthorization($authorization, $paymentType, $customer, $metadata, $basket); @@ -734,8 +735,8 @@ public function performCharge( Charge $charge, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Charge { return $this->paymentService->performCharge($charge, $paymentType, $customer, $metadata, $basket); @@ -785,9 +786,9 @@ public function charge( */ public function chargeAuthorization( $payment, - float $amount = null, - string $orderId = null, - string $invoiceId = null + ?float $amount = null, + ?string $orderId = null, + ?string $invoiceId = null ): Charge { return $this->paymentService->chargeAuthorization($payment, $amount, $orderId, $invoiceId); @@ -798,9 +799,9 @@ public function chargeAuthorization( */ public function chargePayment( $payment, - float $amount = null, - string $orderId = null, - string $invoiceId = null + ?float $amount = null, + ?string $orderId = null, + ?string $invoiceId = null ): Charge { return $this->paymentService->chargePayment($payment, $amount, $orderId, $invoiceId); @@ -814,7 +815,7 @@ public function performChargeOnPayment($payment, Charge $charge): Charge /** * {@inheritDoc} */ - public function cancelAuthorization(Authorization $authorization, float $amount = null): Cancellation + public function cancelAuthorization(Authorization $authorization, ?float $amount = null): Cancellation { return $this->cancelService->cancelAuthorization($authorization, $amount); } @@ -822,7 +823,7 @@ public function cancelAuthorization(Authorization $authorization, float $amount /** * {@inheritDoc} */ - public function cancelAuthorizationByPayment($payment, float $amount = null): Cancellation + public function cancelAuthorizationByPayment($payment, ?float $amount = null): Cancellation { return $this->cancelService->cancelAuthorizationByPayment($payment, $amount); } @@ -832,11 +833,11 @@ public function cancelAuthorizationByPayment($payment, float $amount = null): Ca */ public function cancelPayment( $payment, - float $amount = null, + ?float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, - string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?string $referenceText = null, + ?float $amountNet = null, + ?float $amountVat = null ): array { return $this->cancelService @@ -846,7 +847,7 @@ public function cancelPayment( /** * {@inheritDoc} */ - public function cancelPaymentAuthorization($payment, float $amount = null): ?Cancellation + public function cancelPaymentAuthorization($payment, ?float $amount = null): ?Cancellation { return $this->cancelService->cancelPaymentAuthorization($payment, $amount); } @@ -857,11 +858,11 @@ public function cancelPaymentAuthorization($payment, float $amount = null): ?Can public function cancelChargeById( $payment, string $chargeId, - float $amount = null, - string $reasonCode = null, - string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amount = null, + ?string $reasonCode = null, + ?string $referenceText = null, + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { return $this->cancelService @@ -873,11 +874,11 @@ public function cancelChargeById( */ public function cancelCharge( Charge $charge, - float $amount = null, - string $reasonCode = null, - string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amount = null, + ?string $reasonCode = null, + ?string $referenceText = null, + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { return $this->cancelService @@ -916,7 +917,7 @@ public function createAuthToken(): Token /** * {@inheritDoc} */ - public function ship($payment, string $invoiceId = null, string $orderId = null): Shipment + public function ship($payment, ?string $invoiceId = null, ?string $orderId = null): Shipment { return $this->paymentService->ship($payment, $invoiceId, $orderId); } @@ -930,11 +931,11 @@ public function payout( $paymentType, string $returnUrl, $customer = null, - string $orderId = null, - Metadata $metadata = null, - Basket $basket = null, - string $invoiceId = null, - string $referenceText = null + ?string $orderId = null, + ?Metadata $metadata = null, + ?Basket $basket = null, + ?string $invoiceId = null, + ?string $referenceText = null ): Payout { return $this->paymentService->payout( @@ -1003,9 +1004,9 @@ public function fetchPaypageV2($paypage): PaypageV2 */ public function initPayPageCharge( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { return $this->paymentService->initPayPageCharge($paypage, $customer, $basket, $metadata); @@ -1016,9 +1017,9 @@ public function initPayPageCharge( */ public function initPayPageAuthorize( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { return $this->paymentService->initPayPageAuthorize($paypage, $customer, $basket, $metadata); @@ -1031,7 +1032,7 @@ public function fetchInstallmentPlans( float $amount, string $currency, float $effectiveInterest, - DateTime $orderDate = null + ?DateTime $orderDate = null ): InstalmentPlans { return $this->paymentService @@ -1070,16 +1071,24 @@ public function debugLog($message): void /** * Request a JWT token from the Token Service and stores it for following request. - * If the token is already set, it will not be requested again. + * Manual call of this method should only be necessary if already existing Token needs to be provided. + * If an active token is already set, it will not be requested again. + * Token will automaically be renewed if it is expired. * + * @param string|null $jwtToken If set, the given token will be used instead as long it is valid. * @throws UnzerApiException */ - public function prepareJwtToken() + public function prepareJwtToken(?string $jwtToken = null): string { + if ($jwtToken !== null && JwtService::validateExpiryTime($jwtToken)) { + $this->jwtToken = $jwtToken; + } + if ($this->jwtToken !== null && JwtService::validateExpiryTime($this->jwtToken)) { - return; + return $this->getJwtToken(); } $this->jwtToken = $this->createAuthToken()->getAccessToken(); + return $this->jwtToken; } public function getJwtToken() diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..06e42d4 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,30 @@ +const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); +const WooCommerceDependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' ); +const path = require( 'path' ); + +module.exports = { + ...defaultConfig, + entry: { + unzer_global: path.resolve( process.cwd(), 'assets/src', 'unzer_global.jsx' ), + unzer_simple: path.resolve( process.cwd(), 'assets/src', 'unzer_simple.jsx' ), + unzer_open_banking: path.resolve( process.cwd(), 'assets/src/payment_methods', 'unzer_open_banking.jsx' ), + unzer_apple_pay_v2: path.resolve( process.cwd(), 'assets/src/payment_methods', 'unzer_apple_pay_v2.jsx' ), + unzer_card: path.resolve( process.cwd(), 'assets/src/payment_methods', 'unzer_card.jsx' ), + unzer_direct_debit: path.resolve( process.cwd(), 'assets/src/payment_methods', 'unzer_direct_debit.jsx' ), + unzer_direct_debit_secured: path.resolve( process.cwd(), 'assets/src/payment_methods', 'unzer_direct_debit_secured.jsx' ), + unzer_google_pay: path.resolve( process.cwd(), 'assets/src/payment_methods', 'unzer_google_pay.jsx' ), + unzer_installment: path.resolve( process.cwd(), 'assets/src/payment_methods', 'unzer_installment.jsx' ), + unzer_invoice: path.resolve( process.cwd(), 'assets/src/payment_methods', 'unzer_invoice.jsx' ), + }, + output: { + path: path.resolve( process.cwd(), 'assets/build' ), + filename: '[name].js', + }, + plugins: [ + ...defaultConfig.plugins.filter( + (plugin) => + plugin.constructor.name !== 'DependencyExtractionWebpackPlugin' + ), + new WooCommerceDependencyExtractionWebpackPlugin(), + ], +};