@foxy.io/elements 1.23.0-beta.1 → 1.23.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{L as e}from"./shared-7f33a83a.js";import{F as t}from"./shared-64657919.js";import{aJ as a,_ as s,am as n}from"./shared-98755831.js";import{A as r}from"./shared-509a2f52.js";async function o(e){const t=await e;if(!t.ok)throw new Error(await t.text());return t.json()}async function i(e){var t;let s,n;try{const{hostedPaymentGatewaysHelperUrl:r,paymentGatewaysHelperUrl:i,getPaymentMethodSetUrl:l,request:d,fetch:m}=e;if("GET"!==d.method)throw s=405,new Error("Method not allowed. Allowed methods: GET.");const p=a(/\/payment_presets\/(.+)\/available_payment_methods/,{presetId:1}).exec(new URL(d.url).pathname).groups.presetId,h=o(m(r)),y=o(m(i)),f=null===(t=(await o(m(l(p))))._links["fx:payment_gateway"])||void 0===t?void 0:t.href,c=f?await o(m(f)):void 0,u=function(e){const{hostedPaymentGatewaysHelper:t,paymentGatewaysHelper:a,paymentPresetId:s,paymentGateway:n,base:r}=e,o=new URL(`./payment_presets/${s}/available_payment_methods`,r),i={};return Object.entries(t.values).forEach((([e,t])=>{i[e]=t})),Object.entries(a.values).forEach((([e,t])=>{i[e]=t,n&&(i[e].conflict={type:n.type,name:n.description})})),{_links:{self:{href:o.toString()}},values:i}}({hostedPaymentGatewaysHelper:await h,paymentGatewaysHelper:await y,paymentPresetId:p,paymentGateway:c,base:new URL(d.url).origin});n=JSON.stringify(u),s=200}catch(e){n=e instanceof Error?e.message:String(e),s=null!=s?s:500}return new Response(n,{status:s})}function l(e){const{paymentPresetId:t,base:a}=e;return{_links:{self:{href:new URL(`./payment_presets/${t}/available_fraud_protections`,a).toString()}},values:{minfraud:{name:"MaxMind minFraud",uses_rejection_threshold:!0,json:null},google_recaptcha:{name:"Google reCAPTCHA",uses_rejection_threshold:!1,json:{blocks:[{id:"",parent_id:"",fields:[{id:"config",name:"Configuration",type:"select",description:"Determines how reCAPTCHA is configured to operate.",default_value:"disabled",options:[{name:"Disabled",value:"disabled"},{name:"Always enabled",value:"enabled_always"},{name:"Enabled by errors",value:"enabled_by_errors"}]},{id:"private_key",name:"Private Key",type:"text",optional:!0,description:"If using a custom subdomain, enter your Private Key here.",default_value:""},{id:"site_key",name:"Site Key",type:"text",optional:!0,description:"If using a custom subdomain, enter your Site Key here.",default_value:""}]}]}},custom_precheckout_hook:{name:"Pre-Checkout Webhook",uses_rejection_threshold:!1,json:{blocks:[{id:"",parent_id:"",fields:[{id:"enabled",name:"Enabled",type:"checkbox",default_value:!1},{id:"url",name:"URL",type:"text",description:"Url of your Pre-Checkout Hook",default_value:""},{id:"failure_handling",name:"Failure handling",type:"select",description:"Determines what happens to the checkout if your webhook fails.",default_value:"",options:[{name:"Reject",value:"reject"},{name:"Approve",value:"approve"}]}]}]}}}}}async function d(e){let t,s;try{const{request:n}=e;if("GET"!==n.method)throw t=405,new Error("Method not allowed. Allowed methods: GET.");const r=l({paymentPresetId:a(/\/payment_presets\/(.+)\/available_fraud_protections/,{presetId:1}).exec(new URL(n.url).pathname).groups.presetId,base:new URL(n.url).origin});s=JSON.stringify(r),t=200}catch(e){s=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(s,{status:t})}const m=["_links"];function p(e){const{paymentMethodSetFraudProtectionId:t,paymentPresetId:a,fraudProtection:r,base:o}=e,{_links:i}=r,d=n(r,m),p=l({paymentPresetId:a,base:o}),h=`${new URL(i.self.href).pathname.split("/").pop()}C${t}`,y=new URL(`./payment_presets/${a}`,o),f=new URL(`./payment_presets/${a}/fraud_protections/${h}`,o);return s(s({_links:{self:{href:f.toString()},"fx:store":i["fx:store"],"fx:payment_preset":{href:y.toString()}}},d),{},{helper:p.values[r.type]})}async function h(e){var t,s;let n,r;try{const{fraudProtectionsUrl:i,getPaymentMethodSetUrl:l,request:d,fetch:m}=e;if(!["GET","POST"].includes(d.method))throw n=405,new Error("Method not allowed. Allowed methods: GET, POST.");const h=new URL(d.url),y=a(/\/payment_presets\/(.+)\/fraud_protections/,{presetId:1}).exec(h.pathname).groups.presetId,f=await o(m(l(y)));if("GET"===d.method){const e=parseInt(null!==(t=h.searchParams.get("offset"))&&void 0!==t?t:"0"),a=parseInt(null!==(s=h.searchParams.get("limit"))&&void 0!==s?s:"20"),i=new URL(f._links["fx:payment_method_set_fraud_protections"].href);i.searchParams.set("offset",String(Math.max(0,e-1))),i.searchParams.set("limit",String(a));const l=await o(m(i.toString())),c=await Promise.all(l._embedded["fx:payment_method_set_fraud_protections"].map((async e=>o(m(e._links["fx:fraud_protection"].href))))),u=function(e){const{paymentMethodSetFraudProtections:t,fraudProtections:a,paymentPresetId:s,base:n}=e,r=new URL(`/payment_presets/${s}/fraud_protections`,n);r.search=new URL(t._links.self.href).search;const o=new URL(r.toString());o.search=new URL(t._links.first.href).search;const i=new URL(r.toString());i.search=new URL(t._links.last.href).search;const l=new URL(r.toString());l.search=new URL(t._links.prev.href).search;const d=new URL(r.toString());d.search=new URL(t._links.next.href).search;const m=a.map((e=>{const a=t._embedded["fx:payment_method_set_fraud_protections"].find((t=>t.fraud_protection_uri===e._links.self.href));return p({paymentMethodSetFraudProtectionId:new URL(a._links.self.href).pathname.split("/").pop(),fraudProtection:e,paymentPresetId:s,base:n})}));return{_links:{first:{href:o.toString()},last:{href:i.toString()},prev:{href:l.toString()},next:{href:d.toString()},self:{href:r.toString()}},_embedded:{"fx:fraud_protections":m},returned_items:t.returned_items,total_items:t.total_items,offset:t.offset,limit:t.limit}}({paymentMethodSetFraudProtections:l,fraudProtections:c,paymentPresetId:y,base:new URL(d.url).origin});n=200,r=JSON.stringify(u)}else{const e=await d.json();delete e.helper;const t=m(i,{method:"POST",body:JSON.stringify(e)}),a=await o(t),s=await o(m(f._links["fx:payment_method_set_fraud_protections"].href,{method:"POST",body:JSON.stringify({payment_method_set_uri:f._links.self.href,fraud_protection_uri:a._links.self.href})})),l=p({paymentMethodSetFraudProtectionId:new URL(s._links.self.href).pathname.split("/").pop(),fraudProtection:a,paymentPresetId:y,base:new URL(d.url).origin});n=200,r=JSON.stringify(l)}}catch(e){r=e instanceof Error?e.message:String(e),n=null!=n?n:500}return new Response(r,{status:n})}async function y(e){let t,s;try{const{getPaymentMethodSetUrl:n,getFraudProtectionUrl:r,request:i,fetch:l}=e;if(!["GET","PATCH","DELETE"].includes(i.method))throw t=405,new Error("Method not allowed. Allowed methods: GET, PATCH, DELETE.");const d=a(/\/payment_presets\/(.+)\/fraud_protections\/(.+)/,{presetId:1,protectionId:2}),{presetId:m,protectionId:h}=d.exec(i.url).groups,y=n(m),f=h.substring(0,h.indexOf("C"));if("DELETE"===i.method){const e=(await o(l(y)))._links["fx:payment_method_set_fraud_protections"].href,t=new URL(e);t.searchParams.set("fraud_protection_id",f);const a=await o(l(t.toString())),s=a._embedded["fx:payment_method_set_fraud_protections"].map((e=>o(l(e._links.self.href,{method:"DELETE"}))));await Promise.all(s)}let c=await i.text();try{const e=JSON.parse(c);delete e.helper,c=JSON.stringify(e)}catch(e){}const u=l(r(f),{method:i.method,body:"PATCH"===i.method?c:null}),_=await o(u);s="DELETE"===i.method?JSON.stringify({message:"Fraud protection was successfully deleted."}):JSON.stringify(p({paymentMethodSetFraudProtectionId:h.substring(h.indexOf("C")+1),fraudProtection:_,paymentPresetId:m,base:new URL(i.url).origin}))}catch(e){s=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(s,{status:t})}const f=["_links"];function c(e){const{paymentPresetId:t,helper:a,base:r}=e,o="paymentGateway"in e?e.paymentGateway:e.hostedPaymentGateway,{_links:i}=o,l=n(o,f),d=new URL(i.self.href).pathname.split("/").pop();let m;m="paymentMethodSetHostedPaymentGatewayId"in e?`H${d}C${e.paymentMethodSetHostedPaymentGatewayId}`:`R${d}`;const p=new URL(`./payment_presets/${t}`,r),h=new URL(`./payment_presets/${t}/payment_methods/${m}`,r);return s(s({_links:{self:{href:h.toString()},"fx:store":i["fx:store"],"fx:payment_preset":{href:p.toString()}}},l),{},{helper:a})}async function u(e){var t,s,n,r;let i,l;try{const{hostedPaymentGatewaysHelperUrl:d,paymentGatewaysHelperUrl:m,hostedPaymentGatewaysUrl:p,getPaymentMethodSetUrl:h,paymentGatewaysUrl:y,request:f,fetch:u}=e;if(!["GET","POST"].includes(f.method))throw i=405,new Error("Method not allowed. Allowed methods: GET, POST.");const _=new URL(f.url),w=a(/\/payment_presets\/(.+)\/payment_methods/,{presetId:1}).exec(_.pathname).groups.presetId,[g,P,S]=await Promise.all([o(u(d)),o(u(m)),o(u(h(w)))]);if("GET"===f.method){const e=parseInt(null!==(t=_.searchParams.get("offset"))&&void 0!==t?t:"0"),a=parseInt(null!==(s=_.searchParams.get("limit"))&&void 0!==s?s:"20"),r=new URL(S._links["fx:payment_method_set_hosted_payment_gateways"].href);r.searchParams.set("offset",String(Math.max(0,e-1))),r.searchParams.set("limit",String(a));const d=null===(n=S._links["fx:payment_gateway"])||void 0===n?void 0:n.href,[m,p]=await Promise.all([d&&0===e?o(u(d)):null,o(u(r.toString()))]),h=await Promise.all(p._embedded["fx:payment_method_set_hosted_payment_gateways"].map((async e=>o(u(e._links["fx:hosted_payment_gateway"].href))))),y=function(e){var t,a;const{paymentMethodSetHostedPaymentGateways:s,hostedPaymentGatewaysHelper:n,hostedPaymentGateways:r,paymentGatewaysHelper:o,paymentPresetId:i,paymentGateway:l,query:d,base:m}=e,p=new URLSearchParams(d),h=parseInt(null!==(t=p.get("offset"))&&void 0!==t?t:"0"),y=parseInt(null!==(a=p.get("limit"))&&void 0!==a?a:"20"),f=s.total_items+(l?1:0),u=s.returned_items+(l&&"not-on-page"!==l?1:0),_=new URL(`/payment_presets/${i}/payment_methods`,m);_.search=d;const w=new URL(_.toString()),g=new URL(_.toString()),P=new URL(_.toString()),S=new URL(_.toString());w.searchParams.set("limit",String(y)),w.searchParams.set("offset",String(h)),g.searchParams.set("limit",String(y)),g.searchParams.set("offset",String(Math.max(0,f-y))),P.searchParams.set("limit",String(y)),P.searchParams.set("offset",String(Math.max(0,h-y))),S.searchParams.set("limit",String(y)),S.searchParams.set("offset",String(Math.min(h+y,Math.max(0,f-y))));const U=[...l&&"not-on-page"!==l?[l]:[],...r].map((e=>{const t=s._embedded["fx:payment_method_set_hosted_payment_gateways"].find((t=>t.hosted_payment_gateway_uri===e._links.self.href));return c(t?{paymentMethodSetHostedPaymentGatewayId:new URL(t._links.self.href).pathname.split("/").pop(),hostedPaymentGateway:e,paymentPresetId:i,helper:n.values[e.type],base:m}:{paymentPresetId:i,paymentGateway:e,helper:o.values[e.type],base:m})}));return{_links:{first:{href:w.toString()},last:{href:g.toString()},prev:{href:P.toString()},next:{href:S.toString()},self:{href:_.toString()}},_embedded:{"fx:payment_methods":U},returned_items:u,total_items:f,offset:h,limit:y}}({paymentMethodSetHostedPaymentGateways:p,hostedPaymentGatewaysHelper:g,paymentGatewaysHelper:P,hostedPaymentGateways:h,paymentPresetId:w,paymentGateway:m||(d?"not-on-page":void 0),query:new URL(f.url).search,base:new URL(f.url).origin});i=200,l=JSON.stringify(y)}else{const e=await f.clone().json(),t=!!g.values[null!==(r=e.type)&&void 0!==r?r:""];if(delete e.helper,t){const t=await o(u(p,{method:"POST",body:JSON.stringify(e)})),a=await o(u(S._links["fx:payment_method_set_hosted_payment_gateways"].href,{method:"POST",body:JSON.stringify({payment_method_set_uri:S._links.self.href,hosted_payment_gateway_uri:t._links.self.href})})),s=c({paymentMethodSetHostedPaymentGatewayId:new URL(a._links.self.href).pathname.split("/").pop(),hostedPaymentGateway:t,paymentPresetId:w,helper:g.values[t.type],base:new URL(f.url).origin});i=200,l=JSON.stringify(s)}else{const t=u(y,{method:f.method,body:JSON.stringify(e)}),a=await o(t),s={gateway_uri:a._links.self.href};await Promise.all([o(u(S._links.self.href,{method:"PATCH",body:JSON.stringify(s)})),S.gateway_uri?o(u(S.gateway_uri,{method:"DELETE"})):null]);const n=c({paymentPresetId:w,paymentGateway:a,helper:P.values[a.type],base:new URL(f.url).origin});i=200,l=JSON.stringify(n)}}}catch(e){l=e instanceof Error?e.message:String(e),i=null!=i?i:500}return new Response(l,{status:i})}const _=["_links"];function w(e){const{paymentMethodSet:t,base:a}=e,{_links:r}=t,o=n(t,_),i=new URL(t._links.self.href).pathname.split("/").pop(),l=new URL(`./payment_presets/${i}`,a),d=new URL(`./payment_presets/${i}/payment_methods`,a),m=new URL(`./payment_presets/${i}/fraud_protections`,a),p=new URL(`./payment_presets/${i}/available_payment_methods`,a),h=new URL(`./payment_presets/${i}/available_fraud_protections`,a);return s({_links:{self:{href:l.toString()},"fx:store":r["fx:store"],"fx:payment_methods":{href:d.toString()},"fx:fraud_protections":{href:m.toString()},"fx:available_payment_methods":{href:p.toString()},"fx:available_fraud_protections":{href:h.toString()}}},o)}const g=["_embedded","_links"];async function P(e){let t,a;try{const{paymentMethodSetsUrl:r,request:i,fetch:l}=e;if(!["GET","POST"].includes(i.method))throw t=405,new Error("Method not allowed. Allowed methods: GET, POST.");const d=new URL(i.url),m=new URL(r);let p;if(m.search=d.search,"POST"===i.method){const e=l(m.toString(),{method:"POST",body:await i.text()});p=w({paymentMethodSet:await o(e),base:d.origin})}else p=function(e){const{paymentMethodSets:t,base:a}=e,{_embedded:r,_links:o}=t,i=n(t,g),l=new URL("./payment_presets",a),d=new URL(o.first.href);l.search=d.search;const m=new URL("./payment_presets",a),p=new URL(o.last.href);m.search=p.search;const h=new URL("./payment_presets",a),y=new URL(o.prev.href);h.search=y.search;const f=new URL("./payment_presets",a),c=new URL(o.next.href);f.search=c.search;const u=new URL("./payment_presets",a),_=new URL(o.self.href);return u.search=_.search,s(s({},i),{},{_links:{first:{href:l.toString()},last:{href:m.toString()},prev:{href:h.toString()},next:{href:f.toString()},self:{href:u.toString()}},_embedded:{"fx:payment_presets":r["fx:payment_method_sets"].map((e=>w({paymentMethodSet:e,base:a})))}})}({paymentMethodSets:await o(l(m.toString())),base:d.origin});a=JSON.stringify(p),t=200}catch(e){a=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(a,{status:t})}async function S(e){let t,s;try{const{getPaymentMethodSetUrl:n,request:r,fetch:i}=e;if(!["GET","PATCH","DELETE"].includes(r.method))throw t=405,new Error("Method not allowed. Allowed methods: GET, PATCH, DELETE.");const l=a(/payment_presets\/(.+)/,{presetId:1}).exec(r.url).groups.presetId,d=new URL(r.url),m=new URL(n(l));m.search=d.search;const p=await o(i(m.toString(),{method:r.method,body:"PATCH"===r.method?await r.text():null}));s="DELETE"===r.method?JSON.stringify({message:"Payment preset was successfully deleted."}):JSON.stringify(w({paymentMethodSet:p,base:new URL(r.url).origin}))}catch(e){s=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(s,{status:t})}async function U(e){let t,s;try{const{hostedPaymentGatewaysHelperUrl:n,paymentGatewaysHelperUrl:r,getPaymentMethodSetHostedPaymentGatewayUrl:i,getHostedPaymentGatewayUrl:l,getPaymentMethodSetUrl:d,getPaymentGatewayUrl:m,request:p,fetch:h}=e;if(!["GET","PATCH","DELETE"].includes(p.method))throw t=405,new Error("Method not allowed. Allowed methods: GET, PATCH, DELETE.");const y=a(/\/payment_presets\/(.+)\/payment_methods\/(.+)/,{presetId:1,methodId:2}),{presetId:f,methodId:u}=y.exec(p.url).groups,_=u.startsWith("H"),w=d(f),g=u.substring(1,_?u.indexOf("C"):void 0),P=o(h(n)),S=o(h(r));if("DELETE"===p.method)if(_){const e=i(u.substring(u.indexOf("C")+1));await o(h(e,{method:"DELETE"}))}else{const e={gateway_uri:""},t=JSON.stringify(e);await o(h(w,{method:"PATCH",body:t}))}let U=await p.text();try{const e=JSON.parse(U);delete e.helper,U=JSON.stringify(e)}catch(e){}if(_){const e=h(l(g),{method:p.method,body:"PATCH"===p.method?U:null}),t=await P,a=await o(e);s="DELETE"===p.method?JSON.stringify({message:"Payment method was successfully deleted."}):JSON.stringify(c({paymentMethodSetHostedPaymentGatewayId:u.substring(u.indexOf("C")+1),hostedPaymentGateway:a,paymentPresetId:f,helper:t.values[a.type],base:new URL(p.url).origin}))}else{const e=h(m(g),{method:p.method,body:"PATCH"===p.method?U:null}),t=await S,a=await o(e);s="DELETE"===p.method?JSON.stringify({message:"Payment method was successfully deleted."}):JSON.stringify(c({paymentGateway:a,paymentPresetId:f,helper:t.values[a.type],base:new URL(p.url).origin}))}}catch(e){s=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(s,{status:t})}class b extends e{constructor(){super(...arguments),this.paymentMethodSetHostedPaymentGatewaysUrl=null,this.hostedPaymentGatewaysHelperUrl=null,this.hostedPaymentGatewaysUrl=null,this.paymentGatewaysHelperUrl=null,this.paymentMethodSetsUrl=null,this.fraudProtectionsUrl=null,this.paymentGatewaysUrl=null,this.__api=new r(this),this.__fetch=this.__api.fetch.bind(this.__api),this.__handleFetch=e=>{if(!(e instanceof t))return;if(!e.request.url.startsWith("https://foxy-payments-api.element/"))return;if(e.defaultPrevented)return;const{paymentMethodSetHostedPaymentGatewaysUrl:s,hostedPaymentGatewaysHelperUrl:n,paymentGatewaysHelperUrl:r,hostedPaymentGatewaysUrl:o,paymentMethodSetsUrl:l,fraudProtectionsUrl:m,paymentGatewaysUrl:p}=this;if(null===s)return;if(null===n)return;if(null===r)return;if(null===o)return;if(null===l)return;if(null===m)return;if(null===p)return;const f=e=>t=>{const a=new URL(e);return a.pathname.endsWith("/")||(a.pathname+="/"),a.pathname+=t,a.toString()},c=function(e){const t=[[a(/\/payment_presets\/(.+)\/payment_methods\/(.+)/,{presetId:1,methodId:2}),U],[a(/\/payment_presets\/(.+)\/available_fraud_protections/,{presetId:1}),d],[a(/\/payment_presets\/(.+)\/available_payment_methods/,{presetId:1}),i],[a(/\/payment_presets\/(.+)\/fraud_protections\/(.+)/,{presetId:1,protectionId:2}),y],[a(/\/payment_presets\/(.+)\/fraud_protections/,{presetId:1}),h],[a(/\/payment_presets\/(.+)\/payment_methods/,{presetId:1}),u],[a(/\/payment_presets\/(.+)/,{presetId:1}),S],[/\/payment_presets/,P]];for(const[a,s]of t)if(a.test(new URL(e.request.url).pathname))return s(e);return null}({hostedPaymentGatewaysHelperUrl:n,paymentGatewaysHelperUrl:r,hostedPaymentGatewaysUrl:o,paymentMethodSetsUrl:l,fraudProtectionsUrl:m,paymentGatewaysUrl:p,getPaymentMethodSetHostedPaymentGatewayUrl:f(s),getHostedPaymentGatewayUrl:f(o),getPaymentMethodSetUrl:f(l),getFraudProtectionUrl:f(m),getPaymentGatewayUrl:f(p),request:e.request,fetch:this.__fetch});c&&(e.preventDefault(),e.respondWith(c))}}static get properties(){return{paymentMethodSetHostedPaymentGatewaysUrl:{attribute:"payment-method-set-hosted-payment-gateways-url"},hostedPaymentGatewaysHelperUrl:{attribute:"hosted-payment-gateways-helper-url"},hostedPaymentGatewaysUrl:{attribute:"hosted-payment-gateways-url"},paymentGatewaysHelperUrl:{attribute:"payment-gateways-helper-url"},paymentMethodSetsUrl:{attribute:"payment-method-sets-url"},fraudProtectionsUrl:{attribute:"fraud-protections-url"},paymentGatewaysUrl:{attribute:"payment-gateways-url"}}}connectedCallback(){super.connectedCallback(),this.addEventListener("fetch",this.__handleFetch)}createRenderRoot(){return this}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("fetch",this.__handleFetch)}}customElements.define("foxy-payments-api",b);export{b as PaymentsApi};
1
+ import{L as e}from"./shared-7f33a83a.js";import{F as t}from"./shared-64657919.js";import{aJ as a,_ as s,am as n}from"./shared-98755831.js";import{A as r}from"./shared-509a2f52.js";async function o(e){const t=await e;if(!t.ok)throw new Error(await t.text());return t.json()}async function i(e){var t;let s,n;try{const{hostedPaymentGatewaysHelperUrl:r,paymentGatewaysHelperUrl:i,getPaymentMethodSetUrl:l,request:d,fetch:m}=e;if("GET"!==d.method)throw s=405,new Error("Method not allowed. Allowed methods: GET.");const p=a(/\/payment_presets\/(.+)\/available_payment_methods/,{presetId:1}).exec(new URL(d.url).pathname).groups.presetId,y=o(m(r)),h=o(m(i)),f=null===(t=(await o(m(l(p))))._links["fx:payment_gateway"])||void 0===t?void 0:t.href,u=f?await o(m(f)):void 0,c=function(e){const{hostedPaymentGatewaysHelper:t,paymentGatewaysHelper:a,paymentPresetId:s,paymentGateway:n,base:r}=e,o=new URL(`./payment_presets/${s}/available_payment_methods`,r),i={};return Object.entries(t.values).forEach((([e,t])=>{i[e]=t})),Object.entries(a.values).forEach((([e,t])=>{i[e]=t,n&&(i[e].conflict={type:n.type,name:n.description})})),{_links:{self:{href:o.toString()}},values:i}}({hostedPaymentGatewaysHelper:await y,paymentGatewaysHelper:await h,paymentPresetId:p,paymentGateway:u,base:new URL(d.url).origin});n=JSON.stringify(c),s=200}catch(e){n=e instanceof Error?e.message:String(e),s=null!=s?s:500}return new Response(n,{status:s})}function l(e){const{paymentPresetId:t,base:a}=e;return{_links:{self:{href:new URL(`./payment_presets/${t}/available_fraud_protections`,a).toString()}},values:{minfraud:{name:"MaxMind minFraud",uses_rejection_threshold:!0,json:null},google_recaptcha:{name:"Google reCAPTCHA",uses_rejection_threshold:!1,json:{blocks:[{id:"",parent_id:"",fields:[{id:"config",name:"Configuration",type:"select",description:"Determines how reCAPTCHA is configured to operate.",default_value:"disabled",options:[{name:"Disabled",value:"disabled"},{name:"Always enabled",value:"enabled_always"},{name:"Enabled by errors",value:"enabled_by_errors"}]},{id:"private_key",name:"Private Key",type:"text",optional:!0,description:"If using a custom subdomain, enter your Private Key here.",default_value:""},{id:"site_key",name:"Site Key",type:"text",optional:!0,description:"If using a custom subdomain, enter your Site Key here.",default_value:""}]}]}},custom_precheckout_hook:{name:"Pre-Checkout Webhook",uses_rejection_threshold:!1,json:{blocks:[{id:"",parent_id:"",fields:[{id:"enabled",name:"Enabled",type:"checkbox",default_value:!1},{id:"url",name:"URL",type:"text",description:"Url of your Pre-Checkout Hook",default_value:""},{id:"failure_handling",name:"Failure handling",type:"select",description:"Determines what happens to the checkout if your webhook fails.",default_value:"",options:[{name:"Reject",value:"reject"},{name:"Approve",value:"approve"}]}]}]}}}}}async function d(e){let t,s;try{const{request:n}=e;if("GET"!==n.method)throw t=405,new Error("Method not allowed. Allowed methods: GET.");const r=l({paymentPresetId:a(/\/payment_presets\/(.+)\/available_fraud_protections/,{presetId:1}).exec(new URL(n.url).pathname).groups.presetId,base:new URL(n.url).origin});s=JSON.stringify(r),t=200}catch(e){s=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(s,{status:t})}const m=["_links"];function p(e){const{paymentMethodSetFraudProtectionId:t,paymentPresetId:a,fraudProtection:r,base:o}=e,{_links:i}=r,d=n(r,m),p=l({paymentPresetId:a,base:o}),y=`${new URL(i.self.href).pathname.split("/").pop()}C${t}`,h=new URL(`./payment_presets/${a}`,o),f=new URL(`./payment_presets/${a}/fraud_protections/${y}`,o);return s(s({_links:{self:{href:f.toString()},"fx:store":i["fx:store"],"fx:payment_preset":{href:h.toString()}}},d),{},{helper:p.values[r.type]})}async function y(e){var t,s;let n,r;try{const{fraudProtectionsUrl:i,getPaymentMethodSetUrl:l,request:d,fetch:m}=e;if(!["GET","POST"].includes(d.method))throw n=405,new Error("Method not allowed. Allowed methods: GET, POST.");const y=new URL(d.url),h=a(/\/payment_presets\/(.+)\/fraud_protections/,{presetId:1}).exec(y.pathname).groups.presetId,f=await o(m(l(h)));if("GET"===d.method){const e=parseInt(null!==(t=y.searchParams.get("offset"))&&void 0!==t?t:"0"),a=parseInt(null!==(s=y.searchParams.get("limit"))&&void 0!==s?s:"20"),i=new URL(f._links["fx:payment_method_set_fraud_protections"].href);i.searchParams.set("offset",String(Math.max(0,e-1))),i.searchParams.set("limit",String(a));const l=await o(m(i.toString())),u=await Promise.all(l._embedded["fx:payment_method_set_fraud_protections"].map((async e=>o(m(e._links["fx:fraud_protection"].href))))),c=function(e){const{paymentMethodSetFraudProtections:t,fraudProtections:a,paymentPresetId:s,base:n}=e,r=new URL(`/payment_presets/${s}/fraud_protections`,n);r.search=new URL(t._links.self.href).search;const o=new URL(r.toString());o.search=new URL(t._links.first.href).search;const i=new URL(r.toString());i.search=new URL(t._links.last.href).search;const l=new URL(r.toString());l.search=new URL(t._links.prev.href).search;const d=new URL(r.toString());d.search=new URL(t._links.next.href).search;const m=a.map((e=>{const a=t._embedded["fx:payment_method_set_fraud_protections"].find((t=>t.fraud_protection_uri===e._links.self.href));return p({paymentMethodSetFraudProtectionId:new URL(a._links.self.href).pathname.split("/").pop(),fraudProtection:e,paymentPresetId:s,base:n})}));return{_links:{first:{href:o.toString()},last:{href:i.toString()},prev:{href:l.toString()},next:{href:d.toString()},self:{href:r.toString()}},_embedded:{"fx:fraud_protections":m},returned_items:t.returned_items,total_items:t.total_items,offset:t.offset,limit:t.limit}}({paymentMethodSetFraudProtections:l,fraudProtections:u,paymentPresetId:h,base:new URL(d.url).origin});n=200,r=JSON.stringify(c)}else{const e=await d.json();delete e.helper;const t=m(i,{method:"POST",body:JSON.stringify(e)}),a=await o(t),s=await o(m(f._links["fx:payment_method_set_fraud_protections"].href,{method:"POST",body:JSON.stringify({payment_method_set_uri:f._links.self.href,fraud_protection_uri:a._links.self.href})})),l=p({paymentMethodSetFraudProtectionId:new URL(s._links.self.href).pathname.split("/").pop(),fraudProtection:a,paymentPresetId:h,base:new URL(d.url).origin});n=200,r=JSON.stringify(l)}}catch(e){r=e instanceof Error?e.message:String(e),n=null!=n?n:500}return new Response(r,{status:n})}async function h(e){let t,s;try{const{getPaymentMethodSetUrl:n,getFraudProtectionUrl:r,request:i,fetch:l}=e;if(!["GET","PATCH","DELETE"].includes(i.method))throw t=405,new Error("Method not allowed. Allowed methods: GET, PATCH, DELETE.");const d=a(/\/payment_presets\/(.+)\/fraud_protections\/(.+)/,{presetId:1,protectionId:2}),{presetId:m,protectionId:y}=d.exec(i.url).groups,h=n(m),f=y.substring(0,y.indexOf("C"));if("DELETE"===i.method){const e=(await o(l(h)))._links["fx:payment_method_set_fraud_protections"].href,t=new URL(e);t.searchParams.set("fraud_protection_id",f);const a=await o(l(t.toString())),s=a._embedded["fx:payment_method_set_fraud_protections"].map((e=>o(l(e._links.self.href,{method:"DELETE"}))));await Promise.all(s)}let u=await i.text();try{const e=JSON.parse(u);delete e.helper,u=JSON.stringify(e)}catch(e){}const c=l(r(f),{method:i.method,body:"PATCH"===i.method?u:null}),w=await o(c);s="DELETE"===i.method?JSON.stringify({message:"Fraud protection was successfully deleted."}):JSON.stringify(p({paymentMethodSetFraudProtectionId:y.substring(y.indexOf("C")+1),fraudProtection:w,paymentPresetId:m,base:new URL(i.url).origin}))}catch(e){s=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(s,{status:t})}const f=["_links"];function u(e){const{paymentPresetId:t,helper:a,base:r}=e,o="paymentGateway"in e?e.paymentGateway:e.hostedPaymentGateway,{_links:i}=o,l=n(o,f),d=new URL(i.self.href).pathname.split("/").pop();let m;m="paymentMethodSetHostedPaymentGatewayId"in e?`H${d}C${e.paymentMethodSetHostedPaymentGatewayId}`:`R${d}`;const p=new URL(`./payment_presets/${t}`,r),y=new URL(`./payment_presets/${t}/payment_methods/${m}`,r);return s(s({_links:{self:{href:y.toString()},"fx:store":i["fx:store"],"fx:payment_preset":{href:p.toString()}}},l),{},{helper:a})}async function c(e){var t,s,n,r;let i,l;try{const{hostedPaymentGatewaysHelperUrl:d,paymentGatewaysHelperUrl:m,hostedPaymentGatewaysUrl:p,getPaymentMethodSetUrl:y,paymentGatewaysUrl:h,request:f,fetch:c}=e;if(!["GET","POST"].includes(f.method))throw i=405,new Error("Method not allowed. Allowed methods: GET, POST.");const w=new URL(f.url),_=a(/\/payment_presets\/(.+)\/payment_methods/,{presetId:1}).exec(w.pathname).groups.presetId,[g,P,S]=await Promise.all([o(c(d)),o(c(m)),o(c(y(_)))]);if("GET"===f.method){const e=parseInt(null!==(t=w.searchParams.get("offset"))&&void 0!==t?t:"0"),a=parseInt(null!==(s=w.searchParams.get("limit"))&&void 0!==s?s:"20"),r=new URL(S._links["fx:payment_method_set_hosted_payment_gateways"].href);r.searchParams.set("offset",String(Math.max(0,e-1))),r.searchParams.set("limit",String(a));const d=null===(n=S._links["fx:payment_gateway"])||void 0===n?void 0:n.href,[m,p]=await Promise.all([d&&0===e?o(c(d)):null,o(c(r.toString()))]),y=await Promise.all(p._embedded["fx:payment_method_set_hosted_payment_gateways"].map((async e=>o(c(e._links["fx:hosted_payment_gateway"].href))))),h=function(e){var t,a;const{paymentMethodSetHostedPaymentGateways:s,hostedPaymentGatewaysHelper:n,hostedPaymentGateways:r,paymentGatewaysHelper:o,paymentPresetId:i,paymentGateway:l,query:d,base:m}=e,p=new URLSearchParams(d),y=parseInt(null!==(t=p.get("offset"))&&void 0!==t?t:"0"),h=parseInt(null!==(a=p.get("limit"))&&void 0!==a?a:"20"),f=s.total_items+(l?1:0),c=s.returned_items+(l&&"not-on-page"!==l?1:0),w=new URL(`/payment_presets/${i}/payment_methods`,m);w.search=d;const _=new URL(w.toString()),g=new URL(w.toString()),P=new URL(w.toString()),S=new URL(w.toString());_.searchParams.set("limit",String(h)),_.searchParams.set("offset",String(y)),g.searchParams.set("limit",String(h)),g.searchParams.set("offset",String(Math.max(0,f-h))),P.searchParams.set("limit",String(h)),P.searchParams.set("offset",String(Math.max(0,y-h))),S.searchParams.set("limit",String(h)),S.searchParams.set("offset",String(Math.min(y+h,Math.max(0,f-h))));const U=[...l&&"not-on-page"!==l?[l]:[],...r].map((e=>{const t=s._embedded["fx:payment_method_set_hosted_payment_gateways"].find((t=>t.hosted_payment_gateway_uri===e._links.self.href));return u(t?{paymentMethodSetHostedPaymentGatewayId:new URL(t._links.self.href).pathname.split("/").pop(),hostedPaymentGateway:e,paymentPresetId:i,helper:n.values[e.type],base:m}:{paymentPresetId:i,paymentGateway:e,helper:o.values[e.type],base:m})}));return{_links:{first:{href:_.toString()},last:{href:g.toString()},prev:{href:P.toString()},next:{href:S.toString()},self:{href:w.toString()}},_embedded:{"fx:payment_methods":U},returned_items:c,total_items:f,offset:y,limit:h}}({paymentMethodSetHostedPaymentGateways:p,hostedPaymentGatewaysHelper:g,paymentGatewaysHelper:P,hostedPaymentGateways:y,paymentPresetId:_,paymentGateway:m||(d?"not-on-page":void 0),query:new URL(f.url).search,base:new URL(f.url).origin});i=200,l=JSON.stringify(h)}else{const e=await f.clone().json(),t=!!g.values[null!==(r=e.type)&&void 0!==r?r:""];if(delete e.helper,t){const t=await o(c(p,{method:"POST",body:JSON.stringify(e)})),a=await o(c(S._links["fx:payment_method_set_hosted_payment_gateways"].href,{method:"POST",body:JSON.stringify({payment_method_set_uri:S._links.self.href,hosted_payment_gateway_uri:t._links.self.href})})),s=u({paymentMethodSetHostedPaymentGatewayId:new URL(a._links.self.href).pathname.split("/").pop(),hostedPaymentGateway:t,paymentPresetId:_,helper:g.values[t.type],base:new URL(f.url).origin});i=200,l=JSON.stringify(s)}else{const t=c(h,{method:f.method,body:JSON.stringify(e)}),a=await o(t),s={gateway_uri:a._links.self.href};await Promise.all([o(c(S._links.self.href,{method:"PATCH",body:JSON.stringify(s)})),S.gateway_uri?o(c(S.gateway_uri,{method:"DELETE"})):null]);const n=u({paymentPresetId:_,paymentGateway:a,helper:P.values[a.type],base:new URL(f.url).origin});i=200,l=JSON.stringify(n)}}}catch(e){l=e instanceof Error?e.message:String(e),i=null!=i?i:500}return new Response(l,{status:i})}const w=["_links"];function _(e){const{paymentMethodSet:t,base:a}=e,{_links:r}=t,o=n(t,w),i=new URL(t._links.self.href).pathname.split("/").pop(),l=new URL(`./payment_presets/${i}`,a),d=new URL(`./payment_presets/${i}/payment_methods`,a),m=new URL(`./payment_presets/${i}/fraud_protections`,a),p=new URL(`./payment_presets/${i}/available_payment_methods`,a),y=new URL(`./payment_presets/${i}/available_fraud_protections`,a);return s({_links:{self:{href:l.toString()},"fx:store":r["fx:store"],"fx:payment_methods":{href:d.toString()},"fx:fraud_protections":{href:m.toString()},"fx:available_payment_methods":{href:p.toString()},"fx:available_fraud_protections":{href:y.toString()}}},o)}const g=["_embedded","_links"];async function P(e){let t,a;try{const{paymentMethodSetsUrl:r,request:i,fetch:l}=e;if(!["GET","POST"].includes(i.method))throw t=405,new Error("Method not allowed. Allowed methods: GET, POST.");const d=new URL(i.url),m=new URL(r);let p;if(m.search=d.search,"POST"===i.method){const e=l(m.toString(),{method:"POST",body:await i.text()});p=_({paymentMethodSet:await o(e),base:d.origin})}else p=function(e){const{paymentMethodSets:t,base:a}=e,{_embedded:r,_links:o}=t,i=n(t,g),l=new URL("./payment_presets",a),d=new URL(o.first.href);l.search=d.search;const m=new URL("./payment_presets",a),p=new URL(o.last.href);m.search=p.search;const y=new URL("./payment_presets",a),h=new URL(o.prev.href);y.search=h.search;const f=new URL("./payment_presets",a),u=new URL(o.next.href);f.search=u.search;const c=new URL("./payment_presets",a),w=new URL(o.self.href);return c.search=w.search,s(s({},i),{},{_links:{first:{href:l.toString()},last:{href:m.toString()},prev:{href:y.toString()},next:{href:f.toString()},self:{href:c.toString()}},_embedded:{"fx:payment_presets":r["fx:payment_method_sets"].map((e=>_({paymentMethodSet:e,base:a})))}})}({paymentMethodSets:await o(l(m.toString())),base:d.origin});a=JSON.stringify(p),t=200}catch(e){a=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(a,{status:t})}async function S(e){let t,s;try{const{getPaymentMethodSetUrl:n,request:r,fetch:i}=e;if(!["GET","PATCH","DELETE"].includes(r.method))throw t=405,new Error("Method not allowed. Allowed methods: GET, PATCH, DELETE.");const l=a(/payment_presets\/(.+)/,{presetId:1}).exec(r.url).groups.presetId,d=new URL(r.url),m=new URL(n(l));m.search=d.search;const p=await o(i(m.toString(),{method:r.method,body:"PATCH"===r.method?await r.text():null}));s="DELETE"===r.method?JSON.stringify({message:"Payment preset was successfully deleted."}):JSON.stringify(_({paymentMethodSet:p,base:new URL(r.url).origin}))}catch(e){s=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(s,{status:t})}async function U(e){let t,s;try{const{hostedPaymentGatewaysHelperUrl:n,paymentGatewaysHelperUrl:r,getPaymentMethodSetHostedPaymentGatewayUrl:i,getHostedPaymentGatewayUrl:l,getPaymentMethodSetUrl:d,getPaymentGatewayUrl:m,request:p,fetch:y}=e;if(!["GET","PATCH","DELETE"].includes(p.method))throw t=405,new Error("Method not allowed. Allowed methods: GET, PATCH, DELETE.");const h=a(/\/payment_presets\/(.+)\/payment_methods\/(.+)/,{presetId:1,methodId:2}),{presetId:f,methodId:c}=h.exec(p.url).groups,w=c.startsWith("H"),_=d(f),g=c.substring(1,w?c.indexOf("C"):void 0),P=o(y(n)),S=o(y(r));if("DELETE"===p.method)if(w){const e=i(c.substring(c.indexOf("C")+1));await o(y(e,{method:"DELETE"}))}else{const e={gateway_uri:""},t=JSON.stringify(e);await o(y(_,{method:"PATCH",body:t}))}let U=await p.text();try{const e=JSON.parse(U);delete e.helper,U=JSON.stringify(e)}catch(e){}if(w){const e=y(l(g),{method:p.method,body:"PATCH"===p.method?U:null}),t=await P,a=await o(e);s="DELETE"===p.method?JSON.stringify({message:"Payment method was successfully deleted."}):JSON.stringify(u({paymentMethodSetHostedPaymentGatewayId:c.substring(c.indexOf("C")+1),hostedPaymentGateway:a,paymentPresetId:f,helper:t.values[a.type],base:new URL(p.url).origin}))}else{const e=y(m(g),{method:p.method,body:"PATCH"===p.method?U:null}),t=await S,a=await o(e);s="DELETE"===p.method?JSON.stringify({message:"Payment method was successfully deleted."}):JSON.stringify(u({paymentGateway:a,paymentPresetId:f,helper:t.values[a.type],base:new URL(p.url).origin}))}}catch(e){s=e instanceof Error?e.message:String(e),t=null!=t?t:500}return new Response(s,{status:t})}class b extends e{constructor(){super(...arguments),this.paymentMethodSetHostedPaymentGatewayBaseUrl=null,this.paymentMethodSetHostedPaymentGatewaysUrl=null,this.hostedPaymentGatewaysHelperUrl=null,this.hostedPaymentGatewayBaseUrl=null,this.hostedPaymentGatewaysUrl=null,this.paymentGatewaysHelperUrl=null,this.paymentMethodSetBaseUrl=null,this.paymentMethodSetsUrl=null,this.fraudProtectionBaseUrl=null,this.fraudProtectionsUrl=null,this.paymentGatewayBaseUrl=null,this.paymentGatewaysUrl=null,this.__api=new r(this),this.__fetch=this.__api.fetch.bind(this.__api),this.__handleFetch=e=>{if(!(e instanceof t))return;if(!e.request.url.startsWith("https://foxy-payments-api.element/"))return;if(e.defaultPrevented)return;const{paymentMethodSetHostedPaymentGatewaysUrl:s,paymentMethodSetHostedPaymentGatewayBaseUrl:n=s,hostedPaymentGatewaysHelperUrl:r,paymentGatewaysHelperUrl:o,hostedPaymentGatewaysUrl:l,hostedPaymentGatewayBaseUrl:m=l,paymentMethodSetsUrl:p,paymentMethodSetBaseUrl:f=p,fraudProtectionsUrl:u,fraudProtectionBaseUrl:w=u,paymentGatewaysUrl:_,paymentGatewayBaseUrl:g=_}=this;if(null===s)return;if(null===n)return;if(null===r)return;if(null===o)return;if(null===l)return;if(null===m)return;if(null===p)return;if(null===f)return;if(null===u)return;if(null===w)return;if(null===_)return;if(null===g)return;const b=e=>t=>{const a=new URL(e);return a.pathname.endsWith("/")||(a.pathname+="/"),a.pathname+=t,a.toString()},G=function(e){const t=[[a(/\/payment_presets\/(.+)\/payment_methods\/(.+)/,{presetId:1,methodId:2}),U],[a(/\/payment_presets\/(.+)\/available_fraud_protections/,{presetId:1}),d],[a(/\/payment_presets\/(.+)\/available_payment_methods/,{presetId:1}),i],[a(/\/payment_presets\/(.+)\/fraud_protections\/(.+)/,{presetId:1,protectionId:2}),h],[a(/\/payment_presets\/(.+)\/fraud_protections/,{presetId:1}),y],[a(/\/payment_presets\/(.+)\/payment_methods/,{presetId:1}),c],[a(/\/payment_presets\/(.+)/,{presetId:1}),S],[/\/payment_presets/,P]];for(const[a,s]of t)if(a.test(new URL(e.request.url).pathname))return s(e);return null}({hostedPaymentGatewaysHelperUrl:r,paymentGatewaysHelperUrl:o,hostedPaymentGatewaysUrl:l,paymentMethodSetsUrl:p,fraudProtectionsUrl:u,paymentGatewaysUrl:_,getPaymentMethodSetHostedPaymentGatewayUrl:b(s),getHostedPaymentGatewayUrl:b(m),getPaymentMethodSetUrl:b(f),getFraudProtectionUrl:b(w),getPaymentGatewayUrl:b(g),request:e.request,fetch:this.__fetch});G&&(e.preventDefault(),e.respondWith(G))}}static get properties(){return{paymentMethodSetHostedPaymentGatewayBaseUrl:{attribute:"payment-method-set-hosted-payment-gateway-base-url"},paymentMethodSetHostedPaymentGatewaysUrl:{attribute:"payment-method-set-hosted-payment-gateways-url"},hostedPaymentGatewaysHelperUrl:{attribute:"hosted-payment-gateways-helper-url"},hostedPaymentGatewayBaseUrl:{attribute:"hosted-payment-gateway-base-url"},hostedPaymentGatewaysUrl:{attribute:"hosted-payment-gateways-url"},paymentGatewaysHelperUrl:{attribute:"payment-gateways-helper-url"},paymentMethodSetBaseUrl:{attribute:"payment-method-set-base-url"},paymentMethodSetsUrl:{attribute:"payment-method-sets-url"},fraudProtectionBaseUrl:{attribute:"fraud-protection-base-url"},fraudProtectionsUrl:{attribute:"fraud-protections-url"},paymentGatewayBaseUrl:{attribute:"payment-gateway-base-url"},paymentGatewaysUrl:{attribute:"payment-gateways-url"}}}connectedCallback(){super.connectedCallback(),this.addEventListener("fetch",this.__handleFetch)}createRenderRoot(){return this}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("fetch",this.__handleFetch)}}customElements.define("foxy-payments-api",b);export{b as PaymentsApi};
@@ -14,19 +14,65 @@ import { LitElement } from 'lit-element';
14
14
  */
15
15
  export declare class PaymentsApi extends LitElement {
16
16
  static get properties(): PropertyDeclarations;
17
- /** URL of the `fx:payment_method_set_hosted_payment_gateways` collection. */
17
+ /**
18
+ * Base URL of the `fx:payment_method_set_hosted_payment_gateway` resource (without ID).
19
+ * @example https://api.foxy.io/payment_method_set_hosted_payment_gateways/
20
+ */
21
+ paymentMethodSetHostedPaymentGatewayBaseUrl: string | null;
22
+ /**
23
+ * URL of the `fx:payment_method_set_hosted_payment_gateways` collection.
24
+ * @example https://api.foxy.io/stores/0/payment_method_set_hosted_payment_gateways
25
+ */
18
26
  paymentMethodSetHostedPaymentGatewaysUrl: string | null;
19
- /** URL of the `fx:hosted_payment_gateways` property helper. */
27
+ /**
28
+ * URL of the `fx:hosted_payment_gateways` property helper.
29
+ * @example https://api.foxy.io/property_helpers/hosted_payment_gateways
30
+ */
20
31
  hostedPaymentGatewaysHelperUrl: string | null;
21
- /** URL of the `fx:hosted_payment_gateways` collection. */
32
+ /**
33
+ * Base URL of the `fx:hosted_payment_gateway` resource (without ID).
34
+ * @example https://api.foxy.io/hosted_payment_gateways/
35
+ */
36
+ hostedPaymentGatewayBaseUrl: string | null;
37
+ /**
38
+ * URL of the `fx:hosted_payment_gateways` collection.
39
+ * @example https://api.foxy.io/stores/0/hosted_payment_gateways
40
+ */
22
41
  hostedPaymentGatewaysUrl: string | null;
23
- /** URL of the `fx:payment_gateways` property helper. */
42
+ /**
43
+ * URL of the `fx:payment_gateways` property helper.
44
+ * @example https://api.foxy.io/property_helpers/payment_gateways
45
+ */
24
46
  paymentGatewaysHelperUrl: string | null;
25
- /** URL of the `fx:payment_method_sets` collection. */
47
+ /**
48
+ * Base URL of the `fx:payment_method_set` resource (without ID).
49
+ * @example https://api.foxy.io/payment_method_sets/
50
+ */
51
+ paymentMethodSetBaseUrl: string | null;
52
+ /**
53
+ * URL of the `fx:payment_method_sets` collection.
54
+ * @example https://api.foxy.io/stores/0/payment_method_sets
55
+ */
26
56
  paymentMethodSetsUrl: string | null;
27
- /** URL of the `fx:fraud_protections` collection. */
57
+ /**
58
+ * Base URL of the `fx:fraud_protection` resource (without ID).
59
+ * @example https://api.foxy.io/fraud_protections/
60
+ */
61
+ fraudProtectionBaseUrl: string | null;
62
+ /**
63
+ * URL of the `fx:fraud_protections` collection.
64
+ * @example https://api.foxy.io/stores/0/fraud_protections
65
+ */
28
66
  fraudProtectionsUrl: string | null;
29
- /** URL of the `fx:payment_gateways` collection. */
67
+ /**
68
+ * Base URL of the `fx:payment_gateway` resource (without ID).
69
+ * @example https://api.foxy.io/payment_gateways/
70
+ */
71
+ paymentGatewayBaseUrl: string | null;
72
+ /**
73
+ * URL of the `fx:payment_gateways` collection.
74
+ * @example https://api.foxy.io/stores/0/payment_gateways
75
+ */
30
76
  paymentGatewaysUrl: string | null;
31
77
  private readonly __api;
32
78
  private readonly __fetch;
@@ -17,19 +17,65 @@ import { API } from "../NucleonElement/API.js";
17
17
  export class PaymentsApi extends LitElement {
18
18
  constructor() {
19
19
  super(...arguments);
20
- /** URL of the `fx:payment_method_set_hosted_payment_gateways` collection. */
20
+ /**
21
+ * Base URL of the `fx:payment_method_set_hosted_payment_gateway` resource (without ID).
22
+ * @example https://api.foxy.io/payment_method_set_hosted_payment_gateways/
23
+ */
24
+ this.paymentMethodSetHostedPaymentGatewayBaseUrl = null;
25
+ /**
26
+ * URL of the `fx:payment_method_set_hosted_payment_gateways` collection.
27
+ * @example https://api.foxy.io/stores/0/payment_method_set_hosted_payment_gateways
28
+ */
21
29
  this.paymentMethodSetHostedPaymentGatewaysUrl = null;
22
- /** URL of the `fx:hosted_payment_gateways` property helper. */
30
+ /**
31
+ * URL of the `fx:hosted_payment_gateways` property helper.
32
+ * @example https://api.foxy.io/property_helpers/hosted_payment_gateways
33
+ */
23
34
  this.hostedPaymentGatewaysHelperUrl = null;
24
- /** URL of the `fx:hosted_payment_gateways` collection. */
35
+ /**
36
+ * Base URL of the `fx:hosted_payment_gateway` resource (without ID).
37
+ * @example https://api.foxy.io/hosted_payment_gateways/
38
+ */
39
+ this.hostedPaymentGatewayBaseUrl = null;
40
+ /**
41
+ * URL of the `fx:hosted_payment_gateways` collection.
42
+ * @example https://api.foxy.io/stores/0/hosted_payment_gateways
43
+ */
25
44
  this.hostedPaymentGatewaysUrl = null;
26
- /** URL of the `fx:payment_gateways` property helper. */
45
+ /**
46
+ * URL of the `fx:payment_gateways` property helper.
47
+ * @example https://api.foxy.io/property_helpers/payment_gateways
48
+ */
27
49
  this.paymentGatewaysHelperUrl = null;
28
- /** URL of the `fx:payment_method_sets` collection. */
50
+ /**
51
+ * Base URL of the `fx:payment_method_set` resource (without ID).
52
+ * @example https://api.foxy.io/payment_method_sets/
53
+ */
54
+ this.paymentMethodSetBaseUrl = null;
55
+ /**
56
+ * URL of the `fx:payment_method_sets` collection.
57
+ * @example https://api.foxy.io/stores/0/payment_method_sets
58
+ */
29
59
  this.paymentMethodSetsUrl = null;
30
- /** URL of the `fx:fraud_protections` collection. */
60
+ /**
61
+ * Base URL of the `fx:fraud_protection` resource (without ID).
62
+ * @example https://api.foxy.io/fraud_protections/
63
+ */
64
+ this.fraudProtectionBaseUrl = null;
65
+ /**
66
+ * URL of the `fx:fraud_protections` collection.
67
+ * @example https://api.foxy.io/stores/0/fraud_protections
68
+ */
31
69
  this.fraudProtectionsUrl = null;
32
- /** URL of the `fx:payment_gateways` collection. */
70
+ /**
71
+ * Base URL of the `fx:payment_gateway` resource (without ID).
72
+ * @example https://api.foxy.io/payment_gateways/
73
+ */
74
+ this.paymentGatewayBaseUrl = null;
75
+ /**
76
+ * URL of the `fx:payment_gateways` collection.
77
+ * @example https://api.foxy.io/stores/0/payment_gateways
78
+ */
33
79
  this.paymentGatewaysUrl = null;
34
80
  this.__api = new API(this);
35
81
  this.__fetch = this.__api.fetch.bind(this.__api);
@@ -40,21 +86,31 @@ export class PaymentsApi extends LitElement {
40
86
  return;
41
87
  if (evt.defaultPrevented)
42
88
  return;
43
- const { paymentMethodSetHostedPaymentGatewaysUrl, hostedPaymentGatewaysHelperUrl, paymentGatewaysHelperUrl, hostedPaymentGatewaysUrl, paymentMethodSetsUrl, fraudProtectionsUrl, paymentGatewaysUrl, } = this;
89
+ const { paymentMethodSetHostedPaymentGatewaysUrl, paymentMethodSetHostedPaymentGatewayBaseUrl = paymentMethodSetHostedPaymentGatewaysUrl, hostedPaymentGatewaysHelperUrl, paymentGatewaysHelperUrl, hostedPaymentGatewaysUrl, hostedPaymentGatewayBaseUrl = hostedPaymentGatewaysUrl, paymentMethodSetsUrl, paymentMethodSetBaseUrl = paymentMethodSetsUrl, fraudProtectionsUrl, fraudProtectionBaseUrl = fraudProtectionsUrl, paymentGatewaysUrl, paymentGatewayBaseUrl = paymentGatewaysUrl, } = this;
44
90
  if (paymentMethodSetHostedPaymentGatewaysUrl === null)
45
91
  return;
92
+ if (paymentMethodSetHostedPaymentGatewayBaseUrl === null)
93
+ return;
46
94
  if (hostedPaymentGatewaysHelperUrl === null)
47
95
  return;
48
96
  if (paymentGatewaysHelperUrl === null)
49
97
  return;
50
98
  if (hostedPaymentGatewaysUrl === null)
51
99
  return;
100
+ if (hostedPaymentGatewayBaseUrl === null)
101
+ return;
52
102
  if (paymentMethodSetsUrl === null)
53
103
  return;
104
+ if (paymentMethodSetBaseUrl === null)
105
+ return;
54
106
  if (fraudProtectionsUrl === null)
55
107
  return;
108
+ if (fraudProtectionBaseUrl === null)
109
+ return;
56
110
  if (paymentGatewaysUrl === null)
57
111
  return;
112
+ if (paymentGatewayBaseUrl === null)
113
+ return;
58
114
  const createGetter = (link) => (id) => {
59
115
  const url = new URL(link);
60
116
  if (!url.pathname.endsWith('/'))
@@ -70,10 +126,10 @@ export class PaymentsApi extends LitElement {
70
126
  fraudProtectionsUrl,
71
127
  paymentGatewaysUrl,
72
128
  getPaymentMethodSetHostedPaymentGatewayUrl: createGetter(paymentMethodSetHostedPaymentGatewaysUrl),
73
- getHostedPaymentGatewayUrl: createGetter(hostedPaymentGatewaysUrl),
74
- getPaymentMethodSetUrl: createGetter(paymentMethodSetsUrl),
75
- getFraudProtectionUrl: createGetter(fraudProtectionsUrl),
76
- getPaymentGatewayUrl: createGetter(paymentGatewaysUrl),
129
+ getHostedPaymentGatewayUrl: createGetter(hostedPaymentGatewayBaseUrl),
130
+ getPaymentMethodSetUrl: createGetter(paymentMethodSetBaseUrl),
131
+ getFraudProtectionUrl: createGetter(fraudProtectionBaseUrl),
132
+ getPaymentGatewayUrl: createGetter(paymentGatewayBaseUrl),
77
133
  request: evt.request,
78
134
  fetch: this.__fetch,
79
135
  });
@@ -85,14 +141,21 @@ export class PaymentsApi extends LitElement {
85
141
  }
86
142
  static get properties() {
87
143
  return {
144
+ paymentMethodSetHostedPaymentGatewayBaseUrl: {
145
+ attribute: 'payment-method-set-hosted-payment-gateway-base-url',
146
+ },
88
147
  paymentMethodSetHostedPaymentGatewaysUrl: {
89
148
  attribute: 'payment-method-set-hosted-payment-gateways-url',
90
149
  },
91
150
  hostedPaymentGatewaysHelperUrl: { attribute: 'hosted-payment-gateways-helper-url' },
151
+ hostedPaymentGatewayBaseUrl: { attribute: 'hosted-payment-gateway-base-url' },
92
152
  hostedPaymentGatewaysUrl: { attribute: 'hosted-payment-gateways-url' },
93
153
  paymentGatewaysHelperUrl: { attribute: 'payment-gateways-helper-url' },
154
+ paymentMethodSetBaseUrl: { attribute: 'payment-method-set-base-url' },
94
155
  paymentMethodSetsUrl: { attribute: 'payment-method-sets-url' },
156
+ fraudProtectionBaseUrl: { attribute: 'fraud-protection-base-url' },
95
157
  fraudProtectionsUrl: { attribute: 'fraud-protections-url' },
158
+ paymentGatewayBaseUrl: { attribute: 'payment-gateway-base-url' },
96
159
  paymentGatewaysUrl: { attribute: 'payment-gateways-url' },
97
160
  };
98
161
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PaymentsApi.js","sourceRoot":"","sources":["../../../../src/elements/public/PaymentsApi/PaymentsApi.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,wCAAqC;AAC1D,OAAO,EAAE,UAAU,EAAE,uBAAoB;AACzC,OAAO,EAAE,GAAG,EAAE,iCAA8B;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,WAAY,SAAQ,UAAU;IAA3C;;QAgBE,6EAA6E;QAC7E,6CAAwC,GAAkB,IAAI,CAAC;QAE/D,+DAA+D;QAC/D,mCAA8B,GAAkB,IAAI,CAAC;QAErD,0DAA0D;QAC1D,6BAAwB,GAAkB,IAAI,CAAC;QAE/C,wDAAwD;QACxD,6BAAwB,GAAkB,IAAI,CAAC;QAE/C,sDAAsD;QACtD,yBAAoB,GAAkB,IAAI,CAAC;QAE3C,oDAA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CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB;QAClB,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAC7B,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC;CACF","sourcesContent":["import type { PropertyDeclarations } from 'lit-element';\n\nimport { LitElement } from 'lit-element';\nimport { FetchEvent } from '../NucleonElement/FetchEvent';\nimport { getHandler } from './api/index';\nimport { API } from '../NucleonElement/API';\n\n/**\n * Adapter element for Payments API. This element requires an additional hAPI adapter\n * that will handle authentication and session management.\n *\n * _Payments API is a client-side virtual API layer built on top of hAPI\n * in an attempt to streamline access to stores' payment method settings\n * that is currently a bit quirky due to the legacy functionality. To use\n * Payments API elements with hAPI, wrap them into this node._\n *\n * @element foxy-payments-api\n * @since 1.21.0\n */\nexport class PaymentsApi extends LitElement {\n static get properties(): PropertyDeclarations {\n return {\n paymentMethodSetHostedPaymentGatewaysUrl: {\n attribute: 'payment-method-set-hosted-payment-gateways-url',\n },\n\n hostedPaymentGatewaysHelperUrl: { attribute: 'hosted-payment-gateways-helper-url' },\n hostedPaymentGatewaysUrl: { attribute: 'hosted-payment-gateways-url' },\n paymentGatewaysHelperUrl: { attribute: 'payment-gateways-helper-url' },\n paymentMethodSetsUrl: { attribute: 'payment-method-sets-url' },\n fraudProtectionsUrl: { attribute: 'fraud-protections-url' },\n paymentGatewaysUrl: { attribute: 'payment-gateways-url' },\n };\n }\n\n /** URL of the `fx:payment_method_set_hosted_payment_gateways` collection. */\n paymentMethodSetHostedPaymentGatewaysUrl: string | null = null;\n\n /** URL of the `fx:hosted_payment_gateways` property helper. */\n hostedPaymentGatewaysHelperUrl: string | null = null;\n\n /** URL of the `fx:hosted_payment_gateways` collection. */\n hostedPaymentGatewaysUrl: string | null = null;\n\n /** URL of the `fx:payment_gateways` property helper. */\n paymentGatewaysHelperUrl: string | null = null;\n\n /** URL of the `fx:payment_method_sets` collection. */\n paymentMethodSetsUrl: string | null = null;\n\n /** URL of the `fx:fraud_protections` collection. */\n fraudProtectionsUrl: string | null = null;\n\n /** URL of the `fx:payment_gateways` collection. */\n paymentGatewaysUrl: string | null = null;\n\n private readonly __api = new API(this);\n\n private readonly __fetch = this.__api.fetch.bind(this.__api);\n\n private readonly __handleFetch = (evt: Event) => {\n if (!(evt instanceof FetchEvent)) return;\n if (!evt.request.url.startsWith('https://foxy-payments-api.element/')) return;\n if (evt.defaultPrevented) return;\n\n const {\n paymentMethodSetHostedPaymentGatewaysUrl,\n hostedPaymentGatewaysHelperUrl,\n paymentGatewaysHelperUrl,\n hostedPaymentGatewaysUrl,\n paymentMethodSetsUrl,\n fraudProtectionsUrl,\n paymentGatewaysUrl,\n } = this;\n\n if (paymentMethodSetHostedPaymentGatewaysUrl === null) return;\n if (hostedPaymentGatewaysHelperUrl === null) return;\n if (paymentGatewaysHelperUrl === null) return;\n if (hostedPaymentGatewaysUrl === null) return;\n if (paymentMethodSetsUrl === null) return;\n if (fraudProtectionsUrl === null) return;\n if (paymentGatewaysUrl === null) return;\n\n const createGetter = (link: string) => (id: string) => {\n const url = new URL(link);\n if (!url.pathname.endsWith('/')) url.pathname += '/';\n url.pathname += id;\n return url.toString();\n };\n\n const handler = getHandler({\n hostedPaymentGatewaysHelperUrl,\n paymentGatewaysHelperUrl,\n hostedPaymentGatewaysUrl,\n paymentMethodSetsUrl,\n fraudProtectionsUrl,\n paymentGatewaysUrl,\n\n getPaymentMethodSetHostedPaymentGatewayUrl: createGetter(\n paymentMethodSetHostedPaymentGatewaysUrl\n ),\n\n getHostedPaymentGatewayUrl: createGetter(hostedPaymentGatewaysUrl),\n getPaymentMethodSetUrl: createGetter(paymentMethodSetsUrl),\n getFraudProtectionUrl: createGetter(fraudProtectionsUrl),\n getPaymentGatewayUrl: createGetter(paymentGatewaysUrl),\n\n request: evt.request,\n fetch: this.__fetch,\n });\n\n if (handler) {\n evt.preventDefault();\n evt.respondWith(handler);\n }\n };\n\n connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('fetch', this.__handleFetch);\n }\n\n createRenderRoot(): Element | ShadowRoot {\n return this;\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.removeEventListener('fetch', this.__handleFetch);\n }\n}\n"]}
1
+ {"version":3,"file":"PaymentsApi.js","sourceRoot":"","sources":["../../../../src/elements/public/PaymentsApi/PaymentsApi.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,wCAAqC;AAC1D,OAAO,EAAE,UAAU,EAAE,uBAAoB;AACzC,OAAO,EAAE,GAAG,EAAE,iCAA8B;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,WAAY,SAAQ,UAAU;IAA3C;;QAwBE;;;WAGG;QACH,gDAA2C,GAAkB,IAAI,CAAC;QAElE;;;WAGG;QACH,6CAAwC,GAAkB,IAAI,CAAC;QAE/D;;;WAGG;QACH,mCAA8B,GAAkB,IAAI,CAAC;QAErD;;;WAGG;QACH,gCAA2B,GAAkB,IAAI,CAAC;QAElD;;;WAGG;QACH,6BAAwB,GAAkB,IAAI,CAAC;QAE/C;;;WAGG;QACH,6BAAwB,GAAkB,IAAI,CAAC;QAE/C;;;WAGG;QACH,4BAAuB,GAAkB,IAAI,CAAC;QAE9C;;;WAGG;QACH,yBAAoB,GAAkB,IAAI,CAAC;QAE3C;;;WAGG;QACH,2BAAsB,GAAkB,IAAI,CAAC;QAE7C;;;WAGG;QACH,wBAAmB,GAAkB,IAAI,CAAC;QAE1C;;;WAGG;QACH,0BAAqB,GAAkB,IAAI,CAAC;QAE5C;;;WAGG;QACH,uBAAkB,GAAkB,IAAI,CAAC;QAExB,UAAK,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;QAEtB,YAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAA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ACtE,uBAAuB,EAAE,EAAE,SAAS,EAAE,6BAA6B,EAAE;YACrE,oBAAoB,EAAE,EAAE,SAAS,EAAE,yBAAyB,EAAE;YAC9D,sBAAsB,EAAE,EAAE,SAAS,EAAE,2BAA2B,EAAE;YAClE,mBAAmB,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE;YAC3D,qBAAqB,EAAE,EAAE,SAAS,EAAE,0BAA0B,EAAE;YAChE,kBAAkB,EAAE,EAAE,SAAS,EAAE,sBAAsB,EAAE;SAC1D,CAAC;IACJ,CAAC;IAiJD,iBAAiB;QACf,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB;QAClB,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAC7B,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC;CACF","sourcesContent":["import type { PropertyDeclarations } from 'lit-element';\n\nimport { LitElement } from 'lit-element';\nimport { FetchEvent } from '../NucleonElement/FetchEvent';\nimport { getHandler } from './api/index';\nimport { API } from '../NucleonElement/API';\n\n/**\n * Adapter element for Payments API. This element requires an additional hAPI adapter\n * that will handle authentication and session management.\n *\n * _Payments API is a client-side virtual API layer built on top of hAPI\n * in an attempt to streamline access to stores' payment method settings\n * that is currently a bit quirky due to the legacy functionality. To use\n * Payments API elements with hAPI, wrap them into this node._\n *\n * @element foxy-payments-api\n * @since 1.21.0\n */\nexport class PaymentsApi extends LitElement {\n static get properties(): PropertyDeclarations {\n return {\n paymentMethodSetHostedPaymentGatewayBaseUrl: {\n attribute: 'payment-method-set-hosted-payment-gateway-base-url',\n },\n\n paymentMethodSetHostedPaymentGatewaysUrl: {\n attribute: 'payment-method-set-hosted-payment-gateways-url',\n },\n\n hostedPaymentGatewaysHelperUrl: { attribute: 'hosted-payment-gateways-helper-url' },\n hostedPaymentGatewayBaseUrl: { attribute: 'hosted-payment-gateway-base-url' },\n hostedPaymentGatewaysUrl: { attribute: 'hosted-payment-gateways-url' },\n paymentGatewaysHelperUrl: { attribute: 'payment-gateways-helper-url' },\n paymentMethodSetBaseUrl: { attribute: 'payment-method-set-base-url' },\n paymentMethodSetsUrl: { attribute: 'payment-method-sets-url' },\n fraudProtectionBaseUrl: { attribute: 'fraud-protection-base-url' },\n fraudProtectionsUrl: { attribute: 'fraud-protections-url' },\n paymentGatewayBaseUrl: { attribute: 'payment-gateway-base-url' },\n paymentGatewaysUrl: { attribute: 'payment-gateways-url' },\n };\n }\n\n /**\n * Base URL of the `fx:payment_method_set_hosted_payment_gateway` resource (without ID).\n * @example https://api.foxy.io/payment_method_set_hosted_payment_gateways/\n */\n paymentMethodSetHostedPaymentGatewayBaseUrl: string | null = null;\n\n /**\n * URL of the `fx:payment_method_set_hosted_payment_gateways` collection.\n * @example https://api.foxy.io/stores/0/payment_method_set_hosted_payment_gateways\n */\n paymentMethodSetHostedPaymentGatewaysUrl: string | null = null;\n\n /**\n * URL of the `fx:hosted_payment_gateways` property helper.\n * @example https://api.foxy.io/property_helpers/hosted_payment_gateways\n */\n hostedPaymentGatewaysHelperUrl: string | null = null;\n\n /**\n * Base URL of the `fx:hosted_payment_gateway` resource (without ID).\n * @example https://api.foxy.io/hosted_payment_gateways/\n */\n hostedPaymentGatewayBaseUrl: string | null = null;\n\n /**\n * URL of the `fx:hosted_payment_gateways` collection.\n * @example https://api.foxy.io/stores/0/hosted_payment_gateways\n */\n hostedPaymentGatewaysUrl: string | null = null;\n\n /**\n * URL of the `fx:payment_gateways` property helper.\n * @example https://api.foxy.io/property_helpers/payment_gateways\n */\n paymentGatewaysHelperUrl: string | null = null;\n\n /**\n * Base URL of the `fx:payment_method_set` resource (without ID).\n * @example https://api.foxy.io/payment_method_sets/\n */\n paymentMethodSetBaseUrl: string | null = null;\n\n /**\n * URL of the `fx:payment_method_sets` collection.\n * @example https://api.foxy.io/stores/0/payment_method_sets\n */\n paymentMethodSetsUrl: string | null = null;\n\n /**\n * Base URL of the `fx:fraud_protection` resource (without ID).\n * @example https://api.foxy.io/fraud_protections/\n */\n fraudProtectionBaseUrl: string | null = null;\n\n /**\n * URL of the `fx:fraud_protections` collection.\n * @example https://api.foxy.io/stores/0/fraud_protections\n */\n fraudProtectionsUrl: string | null = null;\n\n /**\n * Base URL of the `fx:payment_gateway` resource (without ID).\n * @example https://api.foxy.io/payment_gateways/\n */\n paymentGatewayBaseUrl: string | null = null;\n\n /**\n * URL of the `fx:payment_gateways` collection.\n * @example https://api.foxy.io/stores/0/payment_gateways\n */\n paymentGatewaysUrl: string | null = null;\n\n private readonly __api = new API(this);\n\n private readonly __fetch = this.__api.fetch.bind(this.__api);\n\n private readonly __handleFetch = (evt: Event) => {\n if (!(evt instanceof FetchEvent)) return;\n if (!evt.request.url.startsWith('https://foxy-payments-api.element/')) return;\n if (evt.defaultPrevented) return;\n\n const {\n paymentMethodSetHostedPaymentGatewaysUrl,\n paymentMethodSetHostedPaymentGatewayBaseUrl = paymentMethodSetHostedPaymentGatewaysUrl,\n hostedPaymentGatewaysHelperUrl,\n paymentGatewaysHelperUrl,\n hostedPaymentGatewaysUrl,\n hostedPaymentGatewayBaseUrl = hostedPaymentGatewaysUrl,\n paymentMethodSetsUrl,\n paymentMethodSetBaseUrl = paymentMethodSetsUrl,\n fraudProtectionsUrl,\n fraudProtectionBaseUrl = fraudProtectionsUrl,\n paymentGatewaysUrl,\n paymentGatewayBaseUrl = paymentGatewaysUrl,\n } = this;\n\n if (paymentMethodSetHostedPaymentGatewaysUrl === null) return;\n if (paymentMethodSetHostedPaymentGatewayBaseUrl === null) return;\n if (hostedPaymentGatewaysHelperUrl === null) return;\n if (paymentGatewaysHelperUrl === null) return;\n if (hostedPaymentGatewaysUrl === null) return;\n if (hostedPaymentGatewayBaseUrl === null) return;\n if (paymentMethodSetsUrl === null) return;\n if (paymentMethodSetBaseUrl === null) return;\n if (fraudProtectionsUrl === null) return;\n if (fraudProtectionBaseUrl === null) return;\n if (paymentGatewaysUrl === null) return;\n if (paymentGatewayBaseUrl === null) return;\n\n const createGetter = (link: string) => (id: string) => {\n const url = new URL(link);\n if (!url.pathname.endsWith('/')) url.pathname += '/';\n url.pathname += id;\n return url.toString();\n };\n\n const handler = getHandler({\n hostedPaymentGatewaysHelperUrl,\n paymentGatewaysHelperUrl,\n hostedPaymentGatewaysUrl,\n paymentMethodSetsUrl,\n fraudProtectionsUrl,\n paymentGatewaysUrl,\n\n getPaymentMethodSetHostedPaymentGatewayUrl: createGetter(\n paymentMethodSetHostedPaymentGatewaysUrl\n ),\n\n getHostedPaymentGatewayUrl: createGetter(hostedPaymentGatewayBaseUrl),\n getPaymentMethodSetUrl: createGetter(paymentMethodSetBaseUrl),\n getFraudProtectionUrl: createGetter(fraudProtectionBaseUrl),\n getPaymentGatewayUrl: createGetter(paymentGatewayBaseUrl),\n\n request: evt.request,\n fetch: this.__fetch,\n });\n\n if (handler) {\n evt.preventDefault();\n evt.respondWith(handler);\n }\n };\n\n connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('fetch', this.__handleFetch);\n }\n\n createRenderRoot(): Element | ShadowRoot {\n return this;\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.removeEventListener('fetch', this.__handleFetch);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@foxy.io/elements",
3
3
  "type": "module",
4
- "version": "1.23.0-beta.1",
4
+ "version": "1.23.0-beta.2",
5
5
  "description": "E-commerce web components by Foxy.",
6
6
  "repository": {
7
7
  "type": "git",