@getopenpay/openpay-js 0.1.21-alpha.b1155fc → 0.1.21

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.
package/dist/index.umd.js CHANGED
@@ -21,4 +21,4 @@ ${r.message}`),r.message)}else return Vt(r.message);if(typeof r=="object")try{re
21
21
  Error: ${he(e)}`),new Error(t)}},na=r=>(r==null?void 0:r["op-pockyt-3ds-url"])!==void 0,sa=async(r,e)=>{const t=ra(e),n=await Ji({url:t["op-pockyt-3ds-url"],baseUrl:r});return{existing_cc:{vault_id:on(n.href??""),transaction_no:t["op-pockyt-txn-no"],reference_no:t["op-pockyt-ref-no"]}}},{log__:O,err__:an}=F("common-cc"),{log__:cn}=F("stripe-cc");i.array(i.object({our_existing_pm_id:i.string()})).length(1);const oa=Ct(async({context:r,checkoutPaymentMethod:e,nonCdeFormInputs:t,formCallbacks:n,customParams:s})=>{var u;O("├ Running common CC flow...",{checkoutPaymentMethod:e});const o=r.anyCdeConnection,a=await Ee(o);O(`├ Validating non-CDE form fields [Mode: ${a.mode}]`);const c=Tt(t,n.get.onValidationError),l={session_id:r.elementsSessionId,checkout_payment_method:e,non_cde_form_fields:c,extra_metadata:{}};try{O(`├ Tokenizing card info in CDE [Session: ${r.elementsSessionId}]`);const d=await wi(s.currentCdeConnections,{session_id:r.elementsSessionId});if(Zi(d,n.get.onValidationError),a.mode==="setup"){O(`├ Setting up payment method in CDE [Token: ${a.token}]`);const y=await ki(o,l);return O(`╰ Setup completed successfully [PM ID: ${y.payment_method_id}]`),{mode:"setup",result:y}}else{O(`├ Initial checkout flow. Checking out card info in CDE [Session: ${r.elementsSessionId}]`);const y=await Br(o,l);return O("╰ Checkout completed successfully."),{mode:"checkout",result:y}}}catch(d){if(d instanceof Fr&&d.originalErrorMessage.includes("3DS_REQUIRED")){O("├ Card requires 3DS, starting non-legacy payment flow"),O("Received 3DS error response headers:",d.response.headers);const y=na(d.response.headers);if(y){O("├ Pockyt 3DS case detected. Going through Pockyt 3DS flow.");const C=await sa(r.baseUrl,d.response.headers);l.extra_metadata.pockyt=C}const w=await yi(o,l);O("├ Payment flow result:",w);const m=((u=d.response.headers)==null?void 0:u["op-should-use-new-flow"])!=="true";y?O("├ Pockyt 3DS is successful, other 3DS flows will be skipped."):m?(O("├ Using stripe 3DS flow"),await ua(w)):(O("├ Using common 3DS flow"),await ca(w,r.baseUrl));const g=w.cc_pm_id;if(a.mode==="setup"){O(`├ Confirming payment flow [cc_pm_id: ${g}]`);const C=await wt(o,{secure_token:a.token,existing_cc_pm_id:g});O("├ Confirm payment flow result received Result:",C);const R=xt(C);return O(`╰ Setup completed successfully [PM ID: ${R.payment_method_id}]`),{mode:"setup",result:R}}else{O(`├ Checking out after 3DS flow [Flow: ${m?"legacy":"new"}]`);const C=await Br(o,{...l,existing_cc_pm_id:g,do_not_use_legacy_cc_flow:m});return O("╰ Checkout completed successfully."),{mode:"checkout",result:C}}}throw an("╰ Error checking out card info in CDE"),an(d),d}}),ia=r=>{const e=r.required_user_actions.find(t=>t.type==="stripe_3ds");if(!e)throw new Error("No stripe 3DS action found");return uo.parse(e)},aa=r=>{const e=r.required_user_actions.find(t=>t.type==="airwallex_payment_consent");if(!e)throw new Error("No common 3DS action found");return io.parse(e)},ca=async(r,e)=>{const t=aa(r);O(`├ Using common 3DS flow [URL: ${t.redirect_url}]`);const{status:n}=await nn({url:t.redirect_url,baseUrl:e});if(O(`╰ 3DS verification completed [Status: ${n}]`),n===we.CANCELLED)throw new Error("3DS verification cancelled");if(n===we.FAILURE)throw new Error("3DS verification failed")},ua=async r=>{const e=ia(r);cn(`├ Using stripe 3DS flow [Client Secret: ${e.client_secret.substring(0,8)}...]`),await go(e),cn("╰ Stripe 3DS flow completed successfully")},{log__:U,err__:la}=F("stripe-pr"),da=i.object({provider:i.union([i.literal("apple_pay"),i.literal("google_pay")]),processor_name:i.literal("stripe"),metadata:i.object({stripe_pk:i.string()})}),fa=Qr(async({context:r})=>{U("Checking if there are any CPMs for Stripe PR...");const e=en(r.checkoutPaymentMethods,da);U("Initializing Stripe PR flow...");const t=r.anyCdeConnection,n=await Ee(t),s=n.mode==="setup";U("Getting initial preview amount");const o=await zr(t,n.token,s,void 0),a=await po(e.metadata.stripe_pk,o.amountAtom,o.currency,s);U("Checking if can make payment");const c=await a.canMakePayment();return c===null?(la("canMakePayment returned null"),{isAvailable:!1,reason:"canMakePayment returned null"}):(U("Stripe PR flow initialized successfully. Can make payment",c),{isAvailable:!0,pr:a,availableProviders:{applePay:c.applePay,googlePay:c.googlePay}})}),ha=Ct(async({context:r,checkoutPaymentMethod:e,nonCdeFormInputs:t,formCallbacks:n,customParams:s,initResult:o})=>{if(U("Running Stripe PR flow..."),s.provider!==e.provider)throw new Error(`Provider mismatch. Expected ${s.provider}, got ${e.provider}`);const a=r.anyCdeConnection,c=o.pr;if(s!=null&&s.overridePaymentRequest){const g=s.overridePaymentRequest;U("Overriding PR amount with",g),ma(c,g.amount,g.pending,g.stripeApplePay)}U("Showing PR dialog..."),c.show();const l=await yo(c);U("Stripe PM added event:",l),U("Merging PM fields with form fields...");const u=pa(t,l),d=Tt(u,n.get.onValidationError);U("PR dialog finished. Starting payment flow...");const y=await _i(a,{fields:d,checkoutPaymentMethod:e}),w=ya(y);U("Confirming PR with Stripe..."),await _o(w,l);const m=await Ee(a);if(m.mode==="setup"){U("Confirming payment flow for setup...");const g=await wt(a,{secure_token:m.token});return{mode:"setup",result:xt(g)}}else{U("Performing checkout...");const g={secure_token:m.token,payment_input:{provider_type:e.provider},customer_first_name:d[E.FIRST_NAME],customer_last_name:d[E.LAST_NAME],customer_email:d[E.EMAIL],customer_zip_code:d[E.ZIP_CODE],customer_country:d[E.COUNTRY],promotion_code:d[E.PROMOTION_CODE],line_items:m.line_items,total_amount_atom:m.amount_total_atom,cancel_at_end:!1,checkout_payment_method:e};return{mode:"checkout",result:await qt(a,g)}}}),pa=(r,e)=>{var l,u,d,y;const t={...r},[n,...s]=((u=(l=e.payerName)==null?void 0:l.trim())==null?void 0:u.split(/\s+/))??[],o=s.join(" ")||void 0,a=(y=(d=e.paymentMethod)==null?void 0:d.billing_details)==null?void 0:y.address,c=e.shippingAddress;return t[E.FIRST_NAME]=t[E.FIRST_NAME]||n||"_OP_UNKNOWN",t[E.LAST_NAME]=t[E.LAST_NAME]||o||"_OP_UNKNOWN",t[E.EMAIL]=t[E.EMAIL]||e.payerEmail||"op_unfilled@getopenpay.com",t[E.ZIP_CODE]=t[E.ZIP_CODE]||(a==null?void 0:a.postal_code)||(c==null?void 0:c.postalCode)||"00000",t[E.COUNTRY]=t[E.COUNTRY]||(a==null?void 0:a.country)||(c==null?void 0:c.country)||"US",U("Final form inputs:",t),t},ma=(r,e,t,n)=>{r.update({total:{amount:e.amountAtom,label:"Total",pending:t},currency:e.currency,applePay:n})},ya=r=>{if(r.required_user_actions.length!==1)throw new Error(`Error occurred.
22
22
  Details: got ${r.required_user_actions.length} required user actions`);return lo.parse(r.required_user_actions[0])},{log__:oe}=F("pockyt-paypal"),_a=i.object({processor_name:i.literal("pockyt"),provider:i.literal("paypal")}),ga=i.array(i.object({paypal_iframe_url:i.string(),verify_token:i.string()})).length(1),va=Ct(async({context:r,checkoutPaymentMethod:e,nonCdeFormInputs:t,formCallbacks:n})=>{oe("Running Pockyt Paypal flow...");const s=r.anyCdeConnection,o=await Ee(s);oe("Verifying CPM...");const a=_a.parse(e);oe("├ Validating non-CDE form fields");const c=Tt(t,n.get.onValidationError),l=Li(c);oe("Starting payment flow...");const u=await Vr(s,{payment_provider:a.provider,checkout_payment_method:a,...l});oe("Start payment flow response",u);const d=ga.parse(u.required_user_actions)[0];oe("Opening paypal iframe...");const y=await Qi("PayPal",s,d.verify_token,d.paypal_iframe_url);oe("Paypal flow result",y);const w=on(y.href);oe(`Confirming payment flow using vault ID ${w}`);const m=await wt(s,{secure_token:o.token,their_pm_id:w});return oe("Confirm payment flow result",m),await Di("pockyt-paypal",s,a,c,m)}),Jt=(r,e,t)=>{const n=r.filter(s=>{const o=t===void 0?!0:s.processor_name===t,a=s.provider===e;return o&&a});if(n.length===0)throw console.error("CPMs list",r),new Error(`No CPMs found with provider '${e}' and processor '${t}'`);if(n.length!==1)throw console.error("CPMs list",r),new Error(`More than one CPM found with provider '${e}' and processor '${t}'`);return n[0]},Se={commonCC:{init:async()=>{},run:oa},stripePR:{init:fa,run:ha},stripeLink:{init:zi,run:Bi},pockytPaypal:{run:va}};var Xt=function(r,e){return Xt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])},Xt(r,e)};function me(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Xt(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function ba(r,e,t,n){function s(o){return o instanceof t?o:new t(function(a){a(o)})}return new(t||(t=Promise))(function(o,a){function c(d){try{u(n.next(d))}catch(y){a(y)}}function l(d){try{u(n.throw(d))}catch(y){a(y)}}function u(d){d.done?o(d.value):s(d.value).then(c,l)}u((n=n.apply(r,e||[])).next())})}function un(r,e){var t={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,s,o,a=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return a.next=c(0),a.throw=c(1),a.return=c(2),typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function c(u){return function(d){return l([u,d])}}function l(u){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(t=0)),t;)try{if(n=1,s&&(o=u[0]&2?s.return:u[0]?s.throw||((o=s.return)&&o.call(s),0):s.next)&&!(o=o.call(s,u[1])).done)return o;switch(s=0,o&&(u=[u[0]&2,o.value]),u[0]){case 0:case 1:o=u;break;case 4:return t.label++,{value:u[1],done:!1};case 5:t.label++,s=u[1],u=[0];continue;case 7:u=t.ops.pop(),t.trys.pop();continue;default:if(o=t.trys,!(o=o.length>0&&o[o.length-1])&&(u[0]===6||u[0]===2)){t=0;continue}if(u[0]===3&&(!o||u[1]>o[0]&&u[1]<o[3])){t.label=u[1];break}if(u[0]===6&&t.label<o[1]){t.label=o[1],o=u;break}if(o&&t.label<o[2]){t.label=o[2],t.ops.push(u);break}o[2]&&t.ops.pop(),t.trys.pop();continue}u=e.call(r,t)}catch(d){u=[6,d],s=0}finally{n=o=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function Ne(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Pt(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),s,o=[],a;try{for(;(e===void 0||e-- >0)&&!(s=n.next()).done;)o.push(s.value)}catch(c){a={error:c}}finally{try{s&&!s.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return o}function Ot(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))}function Me(r){return this instanceof Me?(this.v=r,this):new Me(r)}function wa(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),s,o=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",a),s[Symbol.asyncIterator]=function(){return this},s;function a(m){return function(g){return Promise.resolve(g).then(m,y)}}function c(m,g){n[m]&&(s[m]=function(C){return new Promise(function(R,q){o.push([m,C,R,q])>1||l(m,C)})},g&&(s[m]=g(s[m])))}function l(m,g){try{u(n[m](g))}catch(C){w(o[0][3],C)}}function u(m){m.value instanceof Me?Promise.resolve(m.value.v).then(d,y):w(o[0][2],m)}function d(m){l("next",m)}function y(m){l("throw",m)}function w(m,g){m(g),o.shift(),o.length&&l(o[0][0],o[0][1])}}function ka(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof Ne=="function"?Ne(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(o){t[o]=r[o]&&function(a){return new Promise(function(c,l){a=r[o](a),s(c,l,a.done,a.value)})}}function s(o,a,c,l){Promise.resolve(l).then(function(u){o({value:u,done:c})},a)}}typeof SuppressedError=="function"&&SuppressedError;function L(r){return typeof r=="function"}function Rt(r){var e=function(n){Error.call(n),n.stack=new Error().stack},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var Qt=Rt(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
23
23
  `+t.map(function(n,s){return s+1+") "+n.toString()}).join(`
24
- `):"",this.name="UnsubscriptionError",this.errors=t}});function It(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var ct=function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,s,o;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var c=Ne(a),l=c.next();!l.done;l=c.next()){var u=l.value;u.remove(this)}}catch(C){e={error:C}}finally{try{l&&!l.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else a.remove(this);var d=this.initialTeardown;if(L(d))try{d()}catch(C){o=C instanceof Qt?C.errors:[C]}var y=this._finalizers;if(y){this._finalizers=null;try{for(var w=Ne(y),m=w.next();!m.done;m=w.next()){var g=m.value;try{fn(g)}catch(C){o=o??[],C instanceof Qt?o=Ot(Ot([],Pt(o)),Pt(C.errors)):o.push(C)}}}catch(C){n={error:C}}finally{try{m&&!m.done&&(s=w.return)&&s.call(w)}finally{if(n)throw n.error}}}if(o)throw new Qt(o)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)fn(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&It(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&It(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=function(){var e=new r;return e.closed=!0,e}(),r}(),ln=ct.EMPTY;function dn(r){return r instanceof ct||r&&"closed"in r&&L(r.remove)&&L(r.add)&&L(r.unsubscribe)}function fn(r){L(r)?r():r.unsubscribe()}var hn={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},pn={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,Ot([r,e],Pt(t)))},clearTimeout:function(r){var e=pn.delegate;return((e==null?void 0:e.clearTimeout)||clearTimeout)(r)},delegate:void 0};function mn(r){pn.setTimeout(function(){throw r})}function yn(){}function At(r){r()}var er=function(r){me(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,dn(t)&&t.add(n)):n.destination=xa,n}return e.create=function(t,n,s){return new rr(t,n,s)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(ct),Ea=Function.prototype.bind;function tr(r,e){return Ea.call(r,e)}var Sa=function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){jt(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){jt(n)}else jt(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){jt(t)}},r}(),rr=function(r){me(e,r);function e(t,n,s){var o=r.call(this)||this,a;if(L(t)||!t)a={next:t??void 0,error:n??void 0,complete:s??void 0};else{var c;o&&hn.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return o.unsubscribe()},a={next:t.next&&tr(t.next,c),error:t.error&&tr(t.error,c),complete:t.complete&&tr(t.complete,c)}):a=t}return o.destination=new Sa(a),o}return e}(er);function jt(r){mn(r)}function Ca(r){throw r}var xa={closed:!0,next:yn,error:Ca,complete:yn},nr=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ta(r){return r}function Pa(r){return r.length===0?Ta:r.length===1?r[0]:function(t){return r.reduce(function(n,s){return s(n)},t)}}var ie=function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,n){var s=this,o=Ra(e)?e:new rr(e,t,n);return At(function(){var a=s,c=a.operator,l=a.source;o.add(c?c.call(o,l):l?s._subscribe(o):s._trySubscribe(o))}),o},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var n=this;return t=_n(t),new t(function(s,o){var a=new rr({next:function(c){try{e(c)}catch(l){o(l),a.unsubscribe()}},error:o,complete:s});n.subscribe(a)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[nr]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Pa(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=_n(e),new e(function(n,s){var o;t.subscribe(function(a){return o=a},function(a){return s(a)},function(){return n(o)})})},r.create=function(e){return new r(e)},r}();function _n(r){var e;return(e=r??hn.Promise)!==null&&e!==void 0?e:Promise}function Oa(r){return r&&L(r.next)&&L(r.error)&&L(r.complete)}function Ra(r){return r&&r instanceof er||Oa(r)&&dn(r)}function Ia(r){return L(r==null?void 0:r.lift)}function Aa(r){return function(e){if(Ia(e))return e.lift(function(t){try{return r(t,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function ja(r,e,t,n,s){return new Na(r,e,t,n,s)}var Na=function(r){me(e,r);function e(t,n,s,o,a,c){var l=r.call(this,t)||this;return l.onFinalize=a,l.shouldUnsubscribe=c,l._next=n?function(u){try{n(u)}catch(d){t.error(d)}}:r.prototype._next,l._error=o?function(u){try{o(u)}catch(d){t.error(d)}finally{this.unsubscribe()}}:r.prototype._error,l._complete=s?function(){try{s()}catch(u){t.error(u)}finally{this.unsubscribe()}}:r.prototype._complete,l}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e}(er),Ma=Rt(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),gn=function(r){me(e,r);function e(){var t=r.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return e.prototype.lift=function(t){var n=new vn(this,this);return n.operator=t,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new Ma},e.prototype.next=function(t){var n=this;At(function(){var s,o;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var a=Ne(n.currentObservers),c=a.next();!c.done;c=a.next()){var l=c.value;l.next(t)}}catch(u){s={error:u}}finally{try{c&&!c.done&&(o=a.return)&&o.call(a)}finally{if(s)throw s.error}}}})},e.prototype.error=function(t){var n=this;At(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=t;for(var s=n.observers;s.length;)s.shift().error(t)}})},e.prototype.complete=function(){var t=this;At(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var n=t.observers;n.length;)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var n=this,s=this,o=s.hasError,a=s.isStopped,c=s.observers;return o||a?ln:(this.currentObservers=null,c.push(t),new ct(function(){n.currentObservers=null,It(c,t)}))},e.prototype._checkFinalizedStatuses=function(t){var n=this,s=n.hasError,o=n.thrownError,a=n.isStopped;s?t.error(o):a&&t.complete()},e.prototype.asObservable=function(){var t=new ie;return t.source=this,t},e.create=function(t,n){return new vn(t,n)},e}(ie),vn=function(r){me(e,r);function e(t,n){var s=r.call(this)||this;return s.destination=t,s.source=n,s}return e.prototype.next=function(t){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.next)===null||s===void 0||s.call(n,t)},e.prototype.error=function(t){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.error)===null||s===void 0||s.call(n,t)},e.prototype.complete=function(){var t,n;(n=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||n===void 0||n.call(t)},e.prototype._subscribe=function(t){var n,s;return(s=(n=this.source)===null||n===void 0?void 0:n.subscribe(t))!==null&&s!==void 0?s:ln},e}(gn),La={now:function(){return Date.now()},delegate:void 0},Da=function(r){me(e,r);function e(t,n){return r.call(this)||this}return e.prototype.schedule=function(t,n){return this},e}(ct),bn={setInterval:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setInterval.apply(void 0,Ot([r,e],Pt(t)))},clearInterval:function(r){return clearInterval(r)},delegate:void 0},$a=function(r){me(e,r);function e(t,n){var s=r.call(this,t,n)||this;return s.scheduler=t,s.work=n,s.pending=!1,s}return e.prototype.schedule=function(t,n){var s;if(n===void 0&&(n=0),this.closed)return this;this.state=t;var o=this.id,a=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(a,o,n)),this.pending=!0,this.delay=n,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(a,this.id,n),this},e.prototype.requestAsyncId=function(t,n,s){return s===void 0&&(s=0),bn.setInterval(t.flush.bind(t,this),s)},e.prototype.recycleAsyncId=function(t,n,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return n;n!=null&&bn.clearInterval(n)},e.prototype.execute=function(t,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(t,n);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(t,n){var s=!1,o;try{this.work(t)}catch(a){s=!0,o=a||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),o},e.prototype.unsubscribe=function(){if(!this.closed){var t=this,n=t.id,s=t.scheduler,o=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,It(o,this),n!=null&&(this.id=this.recycleAsyncId(s,n,null)),this.delay=null,r.prototype.unsubscribe.call(this)}},e}(Da),wn=function(){function r(e,t){t===void 0&&(t=r.now),this.schedulerActionCtor=e,this.now=t}return r.prototype.schedule=function(e,t,n){return t===void 0&&(t=0),new this.schedulerActionCtor(this,e).schedule(n,t)},r.now=La.now,r}(),Za=function(r){me(e,r);function e(t,n){n===void 0&&(n=wn.now);var s=r.call(this,t,n)||this;return s.actions=[],s._active=!1,s}return e.prototype.flush=function(t){var n=this.actions;if(this._active){n.push(t);return}var s;this._active=!0;do if(s=t.execute(t.state,t.delay))break;while(t=n.shift());if(this._active=!1,s){for(;t=n.shift();)t.unsubscribe();throw s}},e}(wn),Ua=new Za($a),Fa=function(r){return r&&typeof r.length=="number"&&typeof r!="function"};function Va(r){return L(r==null?void 0:r.then)}function za(r){return L(r[nr])}function Ba(r){return Symbol.asyncIterator&&L(r==null?void 0:r[Symbol.asyncIterator])}function qa(r){return new TypeError("You provided "+(r!==null&&typeof r=="object"?"an invalid object":"'"+r+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Wa(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Ya=Wa();function Ha(r){return L(r==null?void 0:r[Ya])}function Ga(r){return wa(this,arguments,function(){var t,n,s,o;return un(this,function(a){switch(a.label){case 0:t=r.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,Me(t.read())];case 3:return n=a.sent(),s=n.value,o=n.done,o?[4,Me(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,Me(s)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function Ka(r){return L(r==null?void 0:r.getReader)}function Ja(r){if(r instanceof ie)return r;if(r!=null){if(za(r))return Xa(r);if(Fa(r))return Qa(r);if(Va(r))return ec(r);if(Ba(r))return kn(r);if(Ha(r))return tc(r);if(Ka(r))return rc(r)}throw qa(r)}function Xa(r){return new ie(function(e){var t=r[nr]();if(L(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Qa(r){return new ie(function(e){for(var t=0;t<r.length&&!e.closed;t++)e.next(r[t]);e.complete()})}function ec(r){return new ie(function(e){r.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,mn)})}function tc(r){return new ie(function(e){var t,n;try{for(var s=Ne(r),o=s.next();!o.done;o=s.next()){var a=o.value;if(e.next(a),e.closed)return}}catch(c){t={error:c}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}e.complete()})}function kn(r){return new ie(function(e){nc(r,e).catch(function(t){return e.error(t)})})}function rc(r){return kn(Ga(r))}function nc(r,e){var t,n,s,o;return ba(this,void 0,void 0,function(){var a,c;return un(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),t=ka(r),l.label=1;case 1:return[4,t.next()];case 2:if(n=l.sent(),!!n.done)return[3,4];if(a=n.value,e.next(a),e.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return c=l.sent(),s={error:c},[3,11];case 6:return l.trys.push([6,,9,10]),n&&!n.done&&(o=t.return)?[4,o.call(t)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function sc(r,e,t,n,s){n===void 0&&(n=0),s===void 0&&(s=!1);var o=e.schedule(function(){t(),s?r.add(this.schedule(null,n)):this.unsubscribe()},n);if(r.add(o),!s)return o}function oc(r,e){var t=L(r)?r:function(){return r},n=function(s){return s.error(t())};return new ie(n)}var ic=Rt(function(r){return function(){r(this),this.name="EmptyError",this.message="no elements in sequence"}});function ac(r,e){return new Promise(function(t,n){var s=!1,o;r.subscribe({next:function(a){o=a,s=!0},error:n,complete:function(){s?t(o):n(new ic)}})})}function cc(r){return r instanceof Date&&!isNaN(r)}var uc=Rt(function(r){return function(t){t===void 0&&(t=null),r(this),this.message="Timeout has occurred",this.name="TimeoutError",this.info=t}});function lc(r,e){var t=cc(r)?{first:r}:typeof r=="number"?{each:r}:r,n=t.first,s=t.each,o=t.with,a=o===void 0?dc:o,c=t.scheduler,l=c===void 0?Ua:c,u=t.meta,d=u===void 0?null:u;if(n==null&&s==null)throw new TypeError("No timeout provided.");return Aa(function(y,w){var m,g,C=null,R=0,q=function(B){g=sc(w,l,function(){try{m.unsubscribe(),Ja(a({meta:d,lastValue:C,seen:R})).subscribe(w)}catch(j){w.error(j)}},B)};m=y.subscribe(ja(w,function(B){g==null||g.unsubscribe(),R++,w.next(C=B),s>0&&q(s)},void 0,void 0,function(){g!=null&&g.closed||g==null||g.unsubscribe(),C=null})),!R&&q(n!=null?typeof n=="number"?n:+n-l.now():s)})}function dc(r){throw new uc(r)}class Nt{constructor(){this.set=e=>{if(this._current.status==="success")throw new Error("LoadedOnce is already in success state");this._current={status:"success",isSuccess:!0,loadedValue:e},this._subject.next(e),this._subject.complete()},this.throw=(e,t)=>{if(this._current.status==="success")throw new Error("LoadedOnce is already in success state");this._current={status:"error",isSuccess:!1,error:e,errMsg:t},this._subject.error(e)},this.getValueIfLoadedElse=e=>this._current.status==="success"?this._current.loadedValue:e,this.subscribe=e=>{if(this._current.status==="success"){e(this._current);return}this._current.status==="error"&&e(this._current);const t=this._subject.subscribe({next:()=>{if(this._current.status!=="success")throw new Error("Invalid state (next): please make sure to update _current before the subject");e(this._current),t.unsubscribe()},error:()=>{if(this._current.status!=="error")throw new Error("Invalid state (error): please make sure to update _current before the subject");e(this._current)}})},this.waitForLoad=e=>{if(this._current.status==="success")return Promise.resolve(this._current.loadedValue);if(this._current.status==="error")return Promise.reject(this._current.error);this._current.status!=="initial"&&Wt(this._current);const t={first:e.timeoutSec*1e3,with:()=>oc(()=>new Error(e.timeoutErrMsg))};return ac(this._subject.pipe(lc(t)))},this._current={status:"initial",isSuccess:!1},this._subject=new gn}get current(){return this._current}}const{log__:fc,err__:hc}=F("init-flows"),En=(r,e)=>{const t=new Nt;return{publisher:t,initialize:async n=>{try{if(t.current.isSuccess)throw new Error("This flow has already been initialized.");const s=await e(n);fc(`✔ ${r} flow initialized successfully. Result:`,s),t.set(s)}catch(s){hc(`𝙭 ${r} flow initialization failed. Error:`,he(s),"Details:",s),t.throw(s,he(s))}}}},pc=async(r,e,t)=>{await Promise.all(Object.values(r).map(n=>n.initialize({context:e,formCallbacks:t})))},mc=()=>({stripePR:En("Stripe PR",Se.stripePR.init),stripeLink:En("Stripe Link",Se.stripeLink.init)}),{err__:yc}=F("form-callbacks"),K=i.function().optional(),Sn=i.object({onFocus:K,onBlur:K,onChange:K,onLoad:K,onLoadError:K,onValidationError:K,onCheckoutStarted:K,onCheckoutSuccess:K,onSetupPaymentMethodSuccess:K,onCheckoutError:K,onPaymentRequestLoad:K}),re=class re{constructor(){this.setCallbacks=e=>{this._callbacks=re.createEmptyCallbacks(),Object.entries(e).forEach(([t,n])=>{const s=js(t,n??re.NOOP,yc);this._callbacks[t]=s})},this._callbacks=re.createEmptyCallbacks()}get get(){return{...this._callbacks}}};re.NOOP=()=>{},re.createEmptyCallbacks=()=>{const e={};return Object.keys(Sn.keyof().enum).forEach(t=>{e[t]=re.NOOP}),e},re.fromObject=e=>{const t=new re;return t.setCallbacks(Sn.parse(e)),t};let sr=re;class _c{constructor(e,t,n,s){this.handleMessage=o=>{if(!o.source)throw new Error("No source found");if(Cn(o.origin)!==Cn(this.baseUrl)||typeof o.data=="object"&&o.data.penpal)return;const a=Co(JSON.parse(o.data));if(!this.validateEvent(a))return;const{elementId:l,payload:u}=a,d=u.type;switch(d){case"LAYOUT":this.internalCallbacks.setFormHeight(u.height?`${u.height}px`:"100%");break;case"FOCUS":this.formCallbacks.get.onFocus(l,u.elementType);break;case"BLUR":this.formCallbacks.get.onBlur(l,u.elementType);break;case"CHANGE":this.formCallbacks.get.onChange(l,u.elementType,u.errors);break;case"LOADED":this.eventTargets[l]=o.source,this.internalCallbacks.onCdeLoaded(u);break;case"LOAD_ERROR":this.internalCallbacks.onCdeLoadError(u.message);break;case"VALIDATION_ERROR":this.formCallbacks.get.onValidationError(u.elementType,u.errors,l);break;default:console.warn("[form] Unhandled event type:",d)}},this.validateEvent=o=>o.formId!==this.formId||!o.elementId?(console.log("[OJS] formId",this.formId,o.formId),console.warn("[form] Ignoring unknown event:",o),!1):this.nonces.has(o.nonce)?(console.warn("[form] Ignoring duplicate event:",o),!1):(this.nonces.add(o.nonce),!0),this.eventTargets={},this.nonces=new Set,this.formId=e,this.baseUrl=t,this.formCallbacks=n,this.internalCallbacks=s}}const Cn=r=>new URL(r).origin;async function gc(r,e){const n=await Rr({iframe:r,debug:!1,childOrigin:e}).promise,s=await Yo(n);if(!Ho(n,s))throw new Error("Got invalid CDE connection object");return n}class vc{constructor(){this.connections=new Map}addConnection(e,t){this.connections.set(e,t)}getConnection(){const e=this.connections.values().next().value;if(!e)throw new Error("Connection not found");return e}getAllConnections(){return this.connections}}const bc=(r,e,t)=>{const{stripePR:n}=r;n.publisher.subscribe(s=>{if(s.isSuccess){const o=s.loadedValue,a=o.isAvailable&&o.availableProviders.applePay,c=o.isAvailable&&o.availableProviders.googlePay,l={apple_pay:{isLoading:!1,isAvailable:a,startFlow:async u=>{a&&xn("apple_pay",o,e,t,u)}},google_pay:{isLoading:!1,isAvailable:c,startFlow:async u=>{c&&xn("google_pay",o,e,t,u)}}};t.get.onPaymentRequestLoad(l)}})},xn=(r,e,t,n,s)=>Se.stripePR.run({context:t,checkoutPaymentMethod:Jt(t.checkoutPaymentMethods,r),nonCdeFormInputs:bt(t.formDiv),formCallbacks:n,customParams:{provider:r,overridePaymentRequest:s==null?void 0:s.overridePaymentRequest},initResult:e}),Tn="The secure form failed to load properly. Please check your internet connection, or try again later.",{log__:ye,err__:Mt}=F("op-form"),ae=class ae{constructor(e){this.cdeLoadEvent=new Nt,this.anyCdeConn=new Nt,this.context=new Nt,this.initFlows=mc(),this.startFormInit=async()=>{try{ye("Initializing OpenPay form:"),ye("├ Waiting for CDE load event...");const t=await this.cdeLoadEvent.waitForLoad({timeoutSec:120,timeoutErrMsg:Tn});ye("├ CDE load event received"),ye("├ Waiting for CDE connection...");const n=await this.anyCdeConn.waitForLoad({timeoutSec:120,timeoutErrMsg:Tn});ye("├ CDE connection received"),ye("├ Creating OJS context, setting up handlers...");const s=ae.buildOjsFlowContext(this.config,t,n,this.getFormDiv());this.context.set(s),bc(this.initFlows,s,this.formCallbacks),ye("├ Starting OJS init flows..."),await pc(this.initFlows,s,this.formCallbacks),this.formCallbacks.get.onLoad(t.totalAmountAtoms,t.currency),ye("╰ Done initializing OJS flows.")}catch(t){const n=he(t);Mt("╰ Error initializing OP form:",n),this.formCallbacks.get.onLoadError(n)}},this.setFormHeight=t=>{this.formProperties.height=t,this.registeredElements&&Object.values(this.registeredElements).forEach(n=>{n&&(n.node.style.height=t)})},this.onCdeLoaded=t=>{this.cdeLoadEvent.current.isSuccess||this.cdeLoadEvent.set(t)},this.onCdeLoadError=t=>{this.cdeLoadEvent.current.isSuccess||this.cdeLoadEvent.throw(new Error(t),t)},this.createElement=(t,n={})=>{if(!this.config)throw new Error("OpenPay form not initialized");const s=Ns.parse(t),o=document.createElement("iframe"),a=this.buildQueryString(n);o.name=`${s}-element`;const c=new URL(`/app/v1/${o.name}/`,this.config.baseUrl);return c.search=a.toString(),o.src=c.href,o.style.border="none",o.style.width="100%",this.registerIframe(s,o)},this.registerIframe=(t,n)=>{const s={type:t,node:n,mount:o=>{var a;return(a=document.querySelector(o))==null?void 0:a.appendChild(n)}};return this.connectToElement({type:s.type,node:s.node}),this.registeredElements||(this.registeredElements={[Ie.CARD]:void 0,[Ie.CARD_NUMBER]:void 0,[Ie.CARD_EXPIRY]:void 0,[Ie.CARD_CVC]:void 0}),this.registeredElements[t]=s,s},this.buildQueryString=t=>{const n=new URLSearchParams;return n.append("referer",this.referrer),n.append("formId",this.formId),t.styles&&n.append("styles",vo(t.styles)),n.append("secureToken",this.config.checkoutSecureToken),n},this.connectToElement=t=>{gc(t.node).then(n=>{this.connectionManager.addConnection(t.type,n),this.anyCdeConn.current.isSuccess||this.anyCdeConn.set(n)}).catch(n=>Mt("[FORM] Error connecting to CDE iframe",n))},this.getFormDiv=()=>document.querySelector(this.formTarget)??document.body,this.submitCard=()=>{const t=this.context.getValueIfLoadedElse(null);if(!t){Mt("Please wait for the form to finish loading before submitting.");return}Se.commonCC.run({context:t,checkoutPaymentMethod:Jt(t.checkoutPaymentMethods,"credit_card"),nonCdeFormInputs:bt(t.formDiv),formCallbacks:this.formCallbacks,customParams:{currentCdeConnections:this.connectionManager.getAllConnections()},initResult:void 0})},this.generalSubmit=t=>{const n=this.context.getValueIfLoadedElse(null);if(!n){Mt("Please wait for the form to finish loading before submitting.");return}t==="pockyt-paypal"?Se.pockytPaypal.run({context:n,checkoutPaymentMethod:Jt(n.checkoutPaymentMethods,"paypal","pockyt"),nonCdeFormInputs:bt(n.formDiv),formCallbacks:this.formCallbacks,customParams:void 0,initResult:void 0}):Wt(t)},this.submit=this.submitCard,this.destroy=()=>{for(const t of Object.values(this.registeredElements??{}))t&&t.node.remove();window.removeEventListener("message",this.eventHandler.handleMessage.bind(this.eventHandler)),this.registeredElements=null,delete window.ojs},this.updateCallbacks=t=>{this.formCallbacks.setCallbacks(t)},ae.assignAsSingleton(this),this.ojsVersion="0.1.21",this.ojsReleaseVersion="0.1.21-alpha.b1155fc",this.baseUrl=e.baseUrl??"https://cde.getopenpay.com",this.config={...e,baseUrl:this.baseUrl},this.formCallbacks=sr.fromObject(e),this.registeredElements=null,this.formId=`opjs-form-${So()}`,this.referrer=window.location.origin,this.formTarget=e.formTarget??"body",this.formProperties={height:"1px"},this.connectionManager=new vc,this.eventHandler=new _c(this.formId,this.baseUrl,this.formCallbacks,{setFormHeight:this.setFormHeight,onCdeLoaded:this.onCdeLoaded,onCdeLoadError:this.onCdeLoadError}),window.addEventListener("message",this.eventHandler.handleMessage.bind(this.eventHandler)),this.startFormInit()}get checkoutSecureToken(){return this.config.checkoutSecureToken}};ae.ojsFlows=Se,ae.assignAsSingleton=e=>{if(ae.getInstance())throw new Error("OpenPay instance already exists. Only one instance is allowed.");window.ojs=e},ae.getInstance=()=>window.ojs??null,ae.buildOjsFlowContext=(e,t,n,s)=>({checkoutSecureToken:e.checkoutSecureToken,baseUrl:new URL(e.baseUrl??$e).origin,formDiv:s,elementsSessionId:t.sessionId,checkoutPaymentMethods:t.checkoutPaymentMethods,anyCdeConnection:n,customInitParams:e.customInitParams??{}});let or=ae;_e.FieldName=E,_e.OpenPayForm=or,Object.defineProperty(_e,Symbol.toStringTag,{value:"Module"})});
24
+ `):"",this.name="UnsubscriptionError",this.errors=t}});function It(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var ct=function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,s,o;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var c=Ne(a),l=c.next();!l.done;l=c.next()){var u=l.value;u.remove(this)}}catch(C){e={error:C}}finally{try{l&&!l.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else a.remove(this);var d=this.initialTeardown;if(L(d))try{d()}catch(C){o=C instanceof Qt?C.errors:[C]}var y=this._finalizers;if(y){this._finalizers=null;try{for(var w=Ne(y),m=w.next();!m.done;m=w.next()){var g=m.value;try{fn(g)}catch(C){o=o??[],C instanceof Qt?o=Ot(Ot([],Pt(o)),Pt(C.errors)):o.push(C)}}}catch(C){n={error:C}}finally{try{m&&!m.done&&(s=w.return)&&s.call(w)}finally{if(n)throw n.error}}}if(o)throw new Qt(o)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)fn(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&It(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&It(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=function(){var e=new r;return e.closed=!0,e}(),r}(),ln=ct.EMPTY;function dn(r){return r instanceof ct||r&&"closed"in r&&L(r.remove)&&L(r.add)&&L(r.unsubscribe)}function fn(r){L(r)?r():r.unsubscribe()}var hn={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},pn={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,Ot([r,e],Pt(t)))},clearTimeout:function(r){var e=pn.delegate;return((e==null?void 0:e.clearTimeout)||clearTimeout)(r)},delegate:void 0};function mn(r){pn.setTimeout(function(){throw r})}function yn(){}function At(r){r()}var er=function(r){me(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,dn(t)&&t.add(n)):n.destination=xa,n}return e.create=function(t,n,s){return new rr(t,n,s)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(ct),Ea=Function.prototype.bind;function tr(r,e){return Ea.call(r,e)}var Sa=function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){jt(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){jt(n)}else jt(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){jt(t)}},r}(),rr=function(r){me(e,r);function e(t,n,s){var o=r.call(this)||this,a;if(L(t)||!t)a={next:t??void 0,error:n??void 0,complete:s??void 0};else{var c;o&&hn.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return o.unsubscribe()},a={next:t.next&&tr(t.next,c),error:t.error&&tr(t.error,c),complete:t.complete&&tr(t.complete,c)}):a=t}return o.destination=new Sa(a),o}return e}(er);function jt(r){mn(r)}function Ca(r){throw r}var xa={closed:!0,next:yn,error:Ca,complete:yn},nr=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ta(r){return r}function Pa(r){return r.length===0?Ta:r.length===1?r[0]:function(t){return r.reduce(function(n,s){return s(n)},t)}}var ie=function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,n){var s=this,o=Ra(e)?e:new rr(e,t,n);return At(function(){var a=s,c=a.operator,l=a.source;o.add(c?c.call(o,l):l?s._subscribe(o):s._trySubscribe(o))}),o},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var n=this;return t=_n(t),new t(function(s,o){var a=new rr({next:function(c){try{e(c)}catch(l){o(l),a.unsubscribe()}},error:o,complete:s});n.subscribe(a)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[nr]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Pa(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=_n(e),new e(function(n,s){var o;t.subscribe(function(a){return o=a},function(a){return s(a)},function(){return n(o)})})},r.create=function(e){return new r(e)},r}();function _n(r){var e;return(e=r??hn.Promise)!==null&&e!==void 0?e:Promise}function Oa(r){return r&&L(r.next)&&L(r.error)&&L(r.complete)}function Ra(r){return r&&r instanceof er||Oa(r)&&dn(r)}function Ia(r){return L(r==null?void 0:r.lift)}function Aa(r){return function(e){if(Ia(e))return e.lift(function(t){try{return r(t,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function ja(r,e,t,n,s){return new Na(r,e,t,n,s)}var Na=function(r){me(e,r);function e(t,n,s,o,a,c){var l=r.call(this,t)||this;return l.onFinalize=a,l.shouldUnsubscribe=c,l._next=n?function(u){try{n(u)}catch(d){t.error(d)}}:r.prototype._next,l._error=o?function(u){try{o(u)}catch(d){t.error(d)}finally{this.unsubscribe()}}:r.prototype._error,l._complete=s?function(){try{s()}catch(u){t.error(u)}finally{this.unsubscribe()}}:r.prototype._complete,l}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e}(er),Ma=Rt(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),gn=function(r){me(e,r);function e(){var t=r.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return e.prototype.lift=function(t){var n=new vn(this,this);return n.operator=t,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new Ma},e.prototype.next=function(t){var n=this;At(function(){var s,o;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var a=Ne(n.currentObservers),c=a.next();!c.done;c=a.next()){var l=c.value;l.next(t)}}catch(u){s={error:u}}finally{try{c&&!c.done&&(o=a.return)&&o.call(a)}finally{if(s)throw s.error}}}})},e.prototype.error=function(t){var n=this;At(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=t;for(var s=n.observers;s.length;)s.shift().error(t)}})},e.prototype.complete=function(){var t=this;At(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var n=t.observers;n.length;)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var n=this,s=this,o=s.hasError,a=s.isStopped,c=s.observers;return o||a?ln:(this.currentObservers=null,c.push(t),new ct(function(){n.currentObservers=null,It(c,t)}))},e.prototype._checkFinalizedStatuses=function(t){var n=this,s=n.hasError,o=n.thrownError,a=n.isStopped;s?t.error(o):a&&t.complete()},e.prototype.asObservable=function(){var t=new ie;return t.source=this,t},e.create=function(t,n){return new vn(t,n)},e}(ie),vn=function(r){me(e,r);function e(t,n){var s=r.call(this)||this;return s.destination=t,s.source=n,s}return e.prototype.next=function(t){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.next)===null||s===void 0||s.call(n,t)},e.prototype.error=function(t){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.error)===null||s===void 0||s.call(n,t)},e.prototype.complete=function(){var t,n;(n=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||n===void 0||n.call(t)},e.prototype._subscribe=function(t){var n,s;return(s=(n=this.source)===null||n===void 0?void 0:n.subscribe(t))!==null&&s!==void 0?s:ln},e}(gn),La={now:function(){return Date.now()},delegate:void 0},Da=function(r){me(e,r);function e(t,n){return r.call(this)||this}return e.prototype.schedule=function(t,n){return this},e}(ct),bn={setInterval:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setInterval.apply(void 0,Ot([r,e],Pt(t)))},clearInterval:function(r){return clearInterval(r)},delegate:void 0},$a=function(r){me(e,r);function e(t,n){var s=r.call(this,t,n)||this;return s.scheduler=t,s.work=n,s.pending=!1,s}return e.prototype.schedule=function(t,n){var s;if(n===void 0&&(n=0),this.closed)return this;this.state=t;var o=this.id,a=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(a,o,n)),this.pending=!0,this.delay=n,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(a,this.id,n),this},e.prototype.requestAsyncId=function(t,n,s){return s===void 0&&(s=0),bn.setInterval(t.flush.bind(t,this),s)},e.prototype.recycleAsyncId=function(t,n,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return n;n!=null&&bn.clearInterval(n)},e.prototype.execute=function(t,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(t,n);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(t,n){var s=!1,o;try{this.work(t)}catch(a){s=!0,o=a||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),o},e.prototype.unsubscribe=function(){if(!this.closed){var t=this,n=t.id,s=t.scheduler,o=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,It(o,this),n!=null&&(this.id=this.recycleAsyncId(s,n,null)),this.delay=null,r.prototype.unsubscribe.call(this)}},e}(Da),wn=function(){function r(e,t){t===void 0&&(t=r.now),this.schedulerActionCtor=e,this.now=t}return r.prototype.schedule=function(e,t,n){return t===void 0&&(t=0),new this.schedulerActionCtor(this,e).schedule(n,t)},r.now=La.now,r}(),Za=function(r){me(e,r);function e(t,n){n===void 0&&(n=wn.now);var s=r.call(this,t,n)||this;return s.actions=[],s._active=!1,s}return e.prototype.flush=function(t){var n=this.actions;if(this._active){n.push(t);return}var s;this._active=!0;do if(s=t.execute(t.state,t.delay))break;while(t=n.shift());if(this._active=!1,s){for(;t=n.shift();)t.unsubscribe();throw s}},e}(wn),Ua=new Za($a),Fa=function(r){return r&&typeof r.length=="number"&&typeof r!="function"};function Va(r){return L(r==null?void 0:r.then)}function za(r){return L(r[nr])}function Ba(r){return Symbol.asyncIterator&&L(r==null?void 0:r[Symbol.asyncIterator])}function qa(r){return new TypeError("You provided "+(r!==null&&typeof r=="object"?"an invalid object":"'"+r+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Wa(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Ya=Wa();function Ha(r){return L(r==null?void 0:r[Ya])}function Ga(r){return wa(this,arguments,function(){var t,n,s,o;return un(this,function(a){switch(a.label){case 0:t=r.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,Me(t.read())];case 3:return n=a.sent(),s=n.value,o=n.done,o?[4,Me(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,Me(s)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function Ka(r){return L(r==null?void 0:r.getReader)}function Ja(r){if(r instanceof ie)return r;if(r!=null){if(za(r))return Xa(r);if(Fa(r))return Qa(r);if(Va(r))return ec(r);if(Ba(r))return kn(r);if(Ha(r))return tc(r);if(Ka(r))return rc(r)}throw qa(r)}function Xa(r){return new ie(function(e){var t=r[nr]();if(L(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Qa(r){return new ie(function(e){for(var t=0;t<r.length&&!e.closed;t++)e.next(r[t]);e.complete()})}function ec(r){return new ie(function(e){r.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,mn)})}function tc(r){return new ie(function(e){var t,n;try{for(var s=Ne(r),o=s.next();!o.done;o=s.next()){var a=o.value;if(e.next(a),e.closed)return}}catch(c){t={error:c}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}e.complete()})}function kn(r){return new ie(function(e){nc(r,e).catch(function(t){return e.error(t)})})}function rc(r){return kn(Ga(r))}function nc(r,e){var t,n,s,o;return ba(this,void 0,void 0,function(){var a,c;return un(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),t=ka(r),l.label=1;case 1:return[4,t.next()];case 2:if(n=l.sent(),!!n.done)return[3,4];if(a=n.value,e.next(a),e.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return c=l.sent(),s={error:c},[3,11];case 6:return l.trys.push([6,,9,10]),n&&!n.done&&(o=t.return)?[4,o.call(t)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function sc(r,e,t,n,s){n===void 0&&(n=0),s===void 0&&(s=!1);var o=e.schedule(function(){t(),s?r.add(this.schedule(null,n)):this.unsubscribe()},n);if(r.add(o),!s)return o}function oc(r,e){var t=L(r)?r:function(){return r},n=function(s){return s.error(t())};return new ie(n)}var ic=Rt(function(r){return function(){r(this),this.name="EmptyError",this.message="no elements in sequence"}});function ac(r,e){return new Promise(function(t,n){var s=!1,o;r.subscribe({next:function(a){o=a,s=!0},error:n,complete:function(){s?t(o):n(new ic)}})})}function cc(r){return r instanceof Date&&!isNaN(r)}var uc=Rt(function(r){return function(t){t===void 0&&(t=null),r(this),this.message="Timeout has occurred",this.name="TimeoutError",this.info=t}});function lc(r,e){var t=cc(r)?{first:r}:typeof r=="number"?{each:r}:r,n=t.first,s=t.each,o=t.with,a=o===void 0?dc:o,c=t.scheduler,l=c===void 0?Ua:c,u=t.meta,d=u===void 0?null:u;if(n==null&&s==null)throw new TypeError("No timeout provided.");return Aa(function(y,w){var m,g,C=null,R=0,q=function(B){g=sc(w,l,function(){try{m.unsubscribe(),Ja(a({meta:d,lastValue:C,seen:R})).subscribe(w)}catch(j){w.error(j)}},B)};m=y.subscribe(ja(w,function(B){g==null||g.unsubscribe(),R++,w.next(C=B),s>0&&q(s)},void 0,void 0,function(){g!=null&&g.closed||g==null||g.unsubscribe(),C=null})),!R&&q(n!=null?typeof n=="number"?n:+n-l.now():s)})}function dc(r){throw new uc(r)}class Nt{constructor(){this.set=e=>{if(this._current.status==="success")throw new Error("LoadedOnce is already in success state");this._current={status:"success",isSuccess:!0,loadedValue:e},this._subject.next(e),this._subject.complete()},this.throw=(e,t)=>{if(this._current.status==="success")throw new Error("LoadedOnce is already in success state");this._current={status:"error",isSuccess:!1,error:e,errMsg:t},this._subject.error(e)},this.getValueIfLoadedElse=e=>this._current.status==="success"?this._current.loadedValue:e,this.subscribe=e=>{if(this._current.status==="success"){e(this._current);return}this._current.status==="error"&&e(this._current);const t=this._subject.subscribe({next:()=>{if(this._current.status!=="success")throw new Error("Invalid state (next): please make sure to update _current before the subject");e(this._current),t.unsubscribe()},error:()=>{if(this._current.status!=="error")throw new Error("Invalid state (error): please make sure to update _current before the subject");e(this._current)}})},this.waitForLoad=e=>{if(this._current.status==="success")return Promise.resolve(this._current.loadedValue);if(this._current.status==="error")return Promise.reject(this._current.error);this._current.status!=="initial"&&Wt(this._current);const t={first:e.timeoutSec*1e3,with:()=>oc(()=>new Error(e.timeoutErrMsg))};return ac(this._subject.pipe(lc(t)))},this._current={status:"initial",isSuccess:!1},this._subject=new gn}get current(){return this._current}}const{log__:fc,err__:hc}=F("init-flows"),En=(r,e)=>{const t=new Nt;return{publisher:t,initialize:async n=>{try{if(t.current.isSuccess)throw new Error("This flow has already been initialized.");const s=await e(n);fc(`✔ ${r} flow initialized successfully. Result:`,s),t.set(s)}catch(s){hc(`𝙭 ${r} flow initialization failed. Error:`,he(s),"Details:",s),t.throw(s,he(s))}}}},pc=async(r,e,t)=>{await Promise.all(Object.values(r).map(n=>n.initialize({context:e,formCallbacks:t})))},mc=()=>({stripePR:En("Stripe PR",Se.stripePR.init),stripeLink:En("Stripe Link",Se.stripeLink.init)}),{err__:yc}=F("form-callbacks"),K=i.function().optional(),Sn=i.object({onFocus:K,onBlur:K,onChange:K,onLoad:K,onLoadError:K,onValidationError:K,onCheckoutStarted:K,onCheckoutSuccess:K,onSetupPaymentMethodSuccess:K,onCheckoutError:K,onPaymentRequestLoad:K}),re=class re{constructor(){this.setCallbacks=e=>{this._callbacks=re.createEmptyCallbacks(),Object.entries(e).forEach(([t,n])=>{const s=js(t,n??re.NOOP,yc);this._callbacks[t]=s})},this._callbacks=re.createEmptyCallbacks()}get get(){return{...this._callbacks}}};re.NOOP=()=>{},re.createEmptyCallbacks=()=>{const e={};return Object.keys(Sn.keyof().enum).forEach(t=>{e[t]=re.NOOP}),e},re.fromObject=e=>{const t=new re;return t.setCallbacks(Sn.parse(e)),t};let sr=re;class _c{constructor(e,t,n,s){this.handleMessage=o=>{if(!o.source)throw new Error("No source found");if(Cn(o.origin)!==Cn(this.baseUrl)||typeof o.data=="object"&&o.data.penpal)return;const a=Co(JSON.parse(o.data));if(!this.validateEvent(a))return;const{elementId:l,payload:u}=a,d=u.type;switch(d){case"LAYOUT":this.internalCallbacks.setFormHeight(u.height?`${u.height}px`:"100%");break;case"FOCUS":this.formCallbacks.get.onFocus(l,u.elementType);break;case"BLUR":this.formCallbacks.get.onBlur(l,u.elementType);break;case"CHANGE":this.formCallbacks.get.onChange(l,u.elementType,u.errors);break;case"LOADED":this.eventTargets[l]=o.source,this.internalCallbacks.onCdeLoaded(u);break;case"LOAD_ERROR":this.internalCallbacks.onCdeLoadError(u.message);break;case"VALIDATION_ERROR":this.formCallbacks.get.onValidationError(u.elementType,u.errors,l);break;default:console.warn("[form] Unhandled event type:",d)}},this.validateEvent=o=>o.formId!==this.formId||!o.elementId?(console.log("[OJS] formId",this.formId,o.formId),console.warn("[form] Ignoring unknown event:",o),!1):this.nonces.has(o.nonce)?(console.warn("[form] Ignoring duplicate event:",o),!1):(this.nonces.add(o.nonce),!0),this.eventTargets={},this.nonces=new Set,this.formId=e,this.baseUrl=t,this.formCallbacks=n,this.internalCallbacks=s}}const Cn=r=>new URL(r).origin;async function gc(r,e){const n=await Rr({iframe:r,debug:!1,childOrigin:e}).promise,s=await Yo(n);if(!Ho(n,s))throw new Error("Got invalid CDE connection object");return n}class vc{constructor(){this.connections=new Map}addConnection(e,t){this.connections.set(e,t)}getConnection(){const e=this.connections.values().next().value;if(!e)throw new Error("Connection not found");return e}getAllConnections(){return this.connections}}const bc=(r,e,t)=>{const{stripePR:n}=r;n.publisher.subscribe(s=>{if(s.isSuccess){const o=s.loadedValue,a=o.isAvailable&&o.availableProviders.applePay,c=o.isAvailable&&o.availableProviders.googlePay,l={apple_pay:{isLoading:!1,isAvailable:a,startFlow:async u=>{a&&xn("apple_pay",o,e,t,u)}},google_pay:{isLoading:!1,isAvailable:c,startFlow:async u=>{c&&xn("google_pay",o,e,t,u)}}};t.get.onPaymentRequestLoad(l)}})},xn=(r,e,t,n,s)=>Se.stripePR.run({context:t,checkoutPaymentMethod:Jt(t.checkoutPaymentMethods,r),nonCdeFormInputs:bt(t.formDiv),formCallbacks:n,customParams:{provider:r,overridePaymentRequest:s==null?void 0:s.overridePaymentRequest},initResult:e}),Tn="The secure form failed to load properly. Please check your internet connection, or try again later.",{log__:ye,err__:Mt}=F("op-form"),ae=class ae{constructor(e){this.cdeLoadEvent=new Nt,this.anyCdeConn=new Nt,this.context=new Nt,this.initFlows=mc(),this.startFormInit=async()=>{try{ye("Initializing OpenPay form:"),ye("├ Waiting for CDE load event...");const t=await this.cdeLoadEvent.waitForLoad({timeoutSec:120,timeoutErrMsg:Tn});ye("├ CDE load event received"),ye("├ Waiting for CDE connection...");const n=await this.anyCdeConn.waitForLoad({timeoutSec:120,timeoutErrMsg:Tn});ye("├ CDE connection received"),ye("├ Creating OJS context, setting up handlers...");const s=ae.buildOjsFlowContext(this.config,t,n,this.getFormDiv());this.context.set(s),bc(this.initFlows,s,this.formCallbacks),ye("├ Starting OJS init flows..."),await pc(this.initFlows,s,this.formCallbacks),this.formCallbacks.get.onLoad(t.totalAmountAtoms,t.currency),ye("╰ Done initializing OJS flows.")}catch(t){const n=he(t);Mt("╰ Error initializing OP form:",n),this.formCallbacks.get.onLoadError(n)}},this.setFormHeight=t=>{this.formProperties.height=t,this.registeredElements&&Object.values(this.registeredElements).forEach(n=>{n&&(n.node.style.height=t)})},this.onCdeLoaded=t=>{this.cdeLoadEvent.current.isSuccess||this.cdeLoadEvent.set(t)},this.onCdeLoadError=t=>{this.cdeLoadEvent.current.isSuccess||this.cdeLoadEvent.throw(new Error(t),t)},this.createElement=(t,n={})=>{if(!this.config)throw new Error("OpenPay form not initialized");const s=Ns.parse(t),o=document.createElement("iframe"),a=this.buildQueryString(n);o.name=`${s}-element`;const c=new URL(`/app/v1/${o.name}/`,this.config.baseUrl);return c.search=a.toString(),o.src=c.href,o.style.border="none",o.style.width="100%",this.registerIframe(s,o)},this.registerIframe=(t,n)=>{const s={type:t,node:n,mount:o=>{var a;return(a=document.querySelector(o))==null?void 0:a.appendChild(n)}};return this.connectToElement({type:s.type,node:s.node}),this.registeredElements||(this.registeredElements={[Ie.CARD]:void 0,[Ie.CARD_NUMBER]:void 0,[Ie.CARD_EXPIRY]:void 0,[Ie.CARD_CVC]:void 0}),this.registeredElements[t]=s,s},this.buildQueryString=t=>{const n=new URLSearchParams;return n.append("referer",this.referrer),n.append("formId",this.formId),t.styles&&n.append("styles",vo(t.styles)),n.append("secureToken",this.config.checkoutSecureToken),n},this.connectToElement=t=>{gc(t.node).then(n=>{this.connectionManager.addConnection(t.type,n),this.anyCdeConn.current.isSuccess||this.anyCdeConn.set(n)}).catch(n=>Mt("[FORM] Error connecting to CDE iframe",n))},this.getFormDiv=()=>document.querySelector(this.formTarget)??document.body,this.submitCard=()=>{const t=this.context.getValueIfLoadedElse(null);if(!t){Mt("Please wait for the form to finish loading before submitting.");return}Se.commonCC.run({context:t,checkoutPaymentMethod:Jt(t.checkoutPaymentMethods,"credit_card"),nonCdeFormInputs:bt(t.formDiv),formCallbacks:this.formCallbacks,customParams:{currentCdeConnections:this.connectionManager.getAllConnections()},initResult:void 0})},this.generalSubmit=t=>{const n=this.context.getValueIfLoadedElse(null);if(!n){Mt("Please wait for the form to finish loading before submitting.");return}t==="pockyt-paypal"?Se.pockytPaypal.run({context:n,checkoutPaymentMethod:Jt(n.checkoutPaymentMethods,"paypal","pockyt"),nonCdeFormInputs:bt(n.formDiv),formCallbacks:this.formCallbacks,customParams:void 0,initResult:void 0}):Wt(t)},this.submit=this.submitCard,this.destroy=()=>{for(const t of Object.values(this.registeredElements??{}))t&&t.node.remove();window.removeEventListener("message",this.eventHandler.handleMessage.bind(this.eventHandler)),this.registeredElements=null,delete window.ojs},this.updateCallbacks=t=>{this.formCallbacks.setCallbacks(t)},ae.assignAsSingleton(this),this.ojsVersion="0.1.21",this.ojsReleaseVersion="0.1.21",this.baseUrl=e.baseUrl??"https://cde.getopenpay.com",this.config={...e,baseUrl:this.baseUrl},this.formCallbacks=sr.fromObject(e),this.registeredElements=null,this.formId=`opjs-form-${So()}`,this.referrer=window.location.origin,this.formTarget=e.formTarget??"body",this.formProperties={height:"1px"},this.connectionManager=new vc,this.eventHandler=new _c(this.formId,this.baseUrl,this.formCallbacks,{setFormHeight:this.setFormHeight,onCdeLoaded:this.onCdeLoaded,onCdeLoadError:this.onCdeLoadError}),window.addEventListener("message",this.eventHandler.handleMessage.bind(this.eventHandler)),this.startFormInit()}get checkoutSecureToken(){return this.config.checkoutSecureToken}};ae.ojsFlows=Se,ae.assignAsSingleton=e=>{if(ae.getInstance())throw new Error("OpenPay instance already exists. Only one instance is allowed.");window.ojs=e},ae.getInstance=()=>window.ojs??null,ae.buildOjsFlowContext=(e,t,n,s)=>({checkoutSecureToken:e.checkoutSecureToken,baseUrl:new URL(e.baseUrl??$e).origin,formDiv:s,elementsSessionId:t.sessionId,checkoutPaymentMethods:t.checkoutPaymentMethods,anyCdeConnection:n,customInitParams:e.customInitParams??{}});let or=ae;_e.FieldName=E,_e.OpenPayForm=or,Object.defineProperty(_e,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getopenpay/openpay-js",
3
- "version": "0.1.21-alpha.b1155fc",
3
+ "version": "0.1.21",
4
4
  "description": "Accept payments through OpenPay, right on your site",
5
5
  "author": "OpenPay <info@getopenpay.com> (https://getopenpay.com)",
6
6
  "license": "ISC",