@rinnebr/js 0.1.0-alpha.18 → 0.1.0-alpha.19
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/README.md +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -306,12 +306,16 @@ Both `applePay()` and `googlePay()` accept the same configuration structure:
|
|
|
306
306
|
```typescript
|
|
307
307
|
interface MountOptions {
|
|
308
308
|
button?: WalletButtonOptions
|
|
309
|
+
/** Root color-scheme for the iframe (Google Pay only). Use same as your page for seamless background. */
|
|
310
|
+
colorScheme?: 'light' | 'dark'
|
|
309
311
|
onCapture?: (payload: WalletSuccessPayload, fail: (error) => void) => void
|
|
310
312
|
onError?: (error: WalletError) => void
|
|
311
313
|
onCancel?: () => void
|
|
312
314
|
}
|
|
313
315
|
```
|
|
314
316
|
|
|
317
|
+
**Note:** `colorScheme` is supported on Google Pay; it sets the root color-scheme for the payment iframe so it matches your page (e.g. use `'dark'` on a dark-themed page).
|
|
318
|
+
|
|
315
319
|
### Button Options
|
|
316
320
|
|
|
317
321
|
Customize the appearance of wallet buttons:
|
|
@@ -375,6 +379,7 @@ Configure the card input element:
|
|
|
375
379
|
```typescript
|
|
376
380
|
interface CardElementOptions {
|
|
377
381
|
theme?: ThemeOption // Visual theme (see below)
|
|
382
|
+
colorScheme?: 'light' | 'dark' // Root color-scheme for iframe; use same as your page
|
|
378
383
|
locale?: 'pt' | 'en' | 'es' // Field labels, placeholders, and error messages (default: 'pt')
|
|
379
384
|
icons?: boolean // Show card brand icons
|
|
380
385
|
fields?: CardField[] // Fields to display (default: ['number', 'expiry', 'cvc'])
|
|
@@ -574,6 +579,7 @@ interface ThreeDSecureElementOptions {
|
|
|
574
579
|
width: string // Default: '500px'
|
|
575
580
|
height: string // Default: '600px'
|
|
576
581
|
}
|
|
582
|
+
colorScheme?: 'light' | 'dark' // Root color-scheme for iframe; use same as your page
|
|
577
583
|
theme?: ThemeOption // Visual theme
|
|
578
584
|
locale?: 'pt' | 'en' | 'es' // Error messages locale (default: 'pt')
|
|
579
585
|
onReady?: () => void // Challenge UI displayed
|
|
@@ -982,6 +988,7 @@ import type {
|
|
|
982
988
|
WalletErrorCode,
|
|
983
989
|
WalletButtonOptions,
|
|
984
990
|
WalletButtonType,
|
|
991
|
+
ColorScheme,
|
|
985
992
|
Locale,
|
|
986
993
|
WalletType,
|
|
987
994
|
CardData,
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let e=null;async function r(){if(window.Evervault)return window.Evervault;try{return await async function(){return e||(e=new Promise((r,o)=>{const t=document.createElement("script");if(t.src="https://js.evervault.com/v2",t.onload=()=>r(),t.onerror=()=>{e=null,o()},!document.head)throw new Error("Expected document.head not to be null. Evervault.js requires a <head> element.");document.head.appendChild(t)}),e)}(),window.Evervault}catch{throw new Error("Failed to load Evervault.js")}}Promise.resolve().then(()=>{r()});const o={pt:{name:{label:"Nome no cartão",placeholder:"Nome completo",errors:{invalid:"Nome inválido"}},number:{label:"Número do cartão",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de cartão inválido"}},expiry:{label:"Validade",placeholder:"MM/AA",errors:{invalid:"Data de validade inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}},en:{name:{label:"Name on card",placeholder:"Full name",errors:{invalid:"Invalid name"}},number:{label:"Card number",placeholder:"1234 5678 9012 3456",errors:{invalid:"Invalid card number"}},expiry:{label:"Expiry",placeholder:"MM/YY",errors:{invalid:"Invalid expiry date"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"Invalid CVC"}}},es:{name:{label:"Nombre en la tarjeta",placeholder:"Nombre completo",errors:{invalid:"Nombre inválido"}},number:{label:"Número de tarjeta",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de tarjeta inválido"}},expiry:{label:"Vencimiento",placeholder:"MM/AA",errors:{invalid:"Fecha de vencimiento inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}}},t={pt:{errors:{targetElementNotFound:"Elemento alvo não encontrado",failedToInitialize:"Falha ao inicializar Rinne SDK",failedToProcessApplePay:"Falha ao processar dados do Apple Pay",failedToProcessGooglePay:"Falha ao processar dados do Google Pay",applePayError:"Erro do Apple Pay",googlePayError:"Erro do Google Pay",failedToMountApplePay:"Falha ao montar botão do Apple Pay",failedToMountGooglePay:"Falha ao montar botão do Google Pay",failedToFetchConfig:"Falha ao buscar configuração do comerciante",invalidConfig:"Configuração de comerciante inválida: campos obrigatórios ausentes",configFetchFailed:"Falha ao buscar configuração",unknownError:"Erro desconhecido",failedToMountCard:"Falha ao montar formulário de cartão",cardError:"Erro no formulário de cartão",failedToMount3DS:"Falha ao montar autenticação 3D Secure",threeDSecureError:"Erro na autenticação 3D Secure",threeDSecureFailed:"Autenticação 3D Secure falhou",threeDSecureSessionRequired:"ID da sessão 3D Secure é obrigatório"}},en:{errors:{targetElementNotFound:"Target element not found",failedToInitialize:"Failed to initialize Rinne SDK",failedToProcessApplePay:"Failed to process Apple Pay data",failedToProcessGooglePay:"Failed to process Google Pay data",applePayError:"Apple Pay error occurred",googlePayError:"Google Pay error occurred",failedToMountApplePay:"Failed to mount Apple Pay button",failedToMountGooglePay:"Failed to mount Google Pay button",failedToFetchConfig:"Failed to fetch merchant config",invalidConfig:"Invalid merchant config: missing required fields",configFetchFailed:"Configuration fetch failed",unknownError:"Unknown error",failedToMountCard:"Failed to mount card form",cardError:"Card form error",failedToMount3DS:"Failed to mount 3D Secure authentication",threeDSecureError:"3D Secure authentication error",threeDSecureFailed:"3D Secure authentication failed",threeDSecureSessionRequired:"3D Secure session ID is required"}},es:{errors:{targetElementNotFound:"Elemento objetivo no encontrado",failedToInitialize:"Error al inicializar Rinne SDK",failedToProcessApplePay:"Error al procesar datos de Apple Pay",failedToProcessGooglePay:"Error al procesar datos de Google Pay",applePayError:"Error de Apple Pay",googlePayError:"Error de Google Pay",failedToMountApplePay:"Error al montar botón de Apple Pay",failedToMountGooglePay:"Error al montar botón de Google Pay",failedToFetchConfig:"Error al obtener configuración del comerciante",invalidConfig:"Configuración de comerciante inválida: faltan campos requeridos",configFetchFailed:"Error al obtener configuración",unknownError:"Error desconocido",failedToMountCard:"Error al montar formulario de tarjeta",cardError:"Error en el formulario de tarjeta",failedToMount3DS:"Error al montar autenticación 3D Secure",threeDSecureError:"Error en la autenticación 3D Secure",threeDSecureFailed:"La autenticación 3D Secure falló",threeDSecureSessionRequired:"Se requiere el ID de sesión 3D Secure"}}};function n(e="pt"){return t[e]}const a={sandbox:"https://api-sandbox.rinne.com.br/core/v1",production:"https://api.rinne.com.br/core/v1"};function i(e){return String(e).padStart(2,"0")}function s(e){const r=String(e);return 2===r.length?`20${r}`:r}function c(e,r,o){const t=(e.card.funding??"credit").toLowerCase(),n="APPLE_PAY"===o?function(e){const{networkToken:r,card:o,cryptogram:t,eci:n,paymentDataType:a,deviceManufacturerIdentifier:c}=e;return{network_token:r.number,expiry_month:i(r.expiry.month),expiry_year:s(r.expiry.year),cryptogram:t,eci:n,token_provider:r.tokenServiceProvider,brand:o.brand,device_id:c,authentication_type:"3DSecure"===a?"3DS":void 0,last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"APPLE_PAY",display_name:o.displayName}}(e):function(e){if(!function(e){return"token"in e&&"tokenServiceProvider"in e.token}(e))throw new Error("Google Pay response must contain a network token (3DS authentication)");const{token:r,card:o,cryptogram:t,eci:n}=e;return{network_token:r.number,expiry_month:i(r.expiry.month),expiry_year:s(r.expiry.year),cryptogram:t,eci:n??null,token_provider:r.tokenServiceProvider,brand:o.brand,authentication_type:"3DS",last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"GOOGLE_PAY",display_name:o.displayName}}(e);return{card_data:n,payment_method:"debit"===t?"DEBIT_CARD":"CREDIT_CARD",transaction:r}}function l(e){if(void 0!==e)return 0===e?"0":e}function u(e){return{pt:"pt-BR",en:"en-US",es:"es-ES"}[e]}function d(e,r="pt"){if("string"==typeof e){const o=document.querySelector(e);if(!o){const o=n(r).errors.targetElementNotFound;throw new Error(`${o}: ${e}`)}return o}return e}function m(e,r,o){return{code:e,message:r,details:o}}function p(e){if(!e)return{};const r=e;return{number:r.number,expiry:r.expiry,cvc:r.cvc,name:r.name}}function h(e){return{isValid:e.isValid,isComplete:e.isComplete,errors:p(e.errors)}}function f(e,r,t){const n={};void 0!==r.icons&&(n.icons=r.icons),r.fields&&(n.fields=r.fields);const a=function(e,r){if("function"==typeof r)return r;const{preset:o,customStyles:t,customFonts:n}=function(e){return"string"==typeof e?{preset:e}:{preset:e?.preset??"material",customStyles:e?.styles,customFonts:e?.fonts}}(r),a=e[o];if(a){if(t||n){const e={};return t&&(e.styles=t),n&&(e.fonts=n),a(e)}return a()}}(e,r.theme);return void 0!==a&&(n.theme=a),n.translations=function(e="pt"){return o[e]}(t),n}function y(e,r){return{field:e,state:r}}exports.Rinne=class{constructor(e){this.options=e,this.transaction=this.createTransactionNamespace(),this.elements=this.createElementsNamespace()}config=null;evervault=null;initPromise=null;transaction;elements;async initialize(){return this.initPromise||(this.initPromise=(async()=>{try{const e=await async function(e){const r=n("pt"),o=`${e.baseUrl??a[e.environment??"production"]}/merchants/${e.merchantId}/public-settings`;try{const e=await fetch(o);if(!e.ok){const o=String(e.status);throw new Error(`${r.errors.failedToFetchConfig}: ${o} ${e.statusText}`)}const t=await e.json();if(!t.merchant_id||!t.team_id||!t.app_id)throw new Error(r.errors.invalidConfig);return{merchantId:t.merchant_id,teamId:t.team_id,appId:t.app_id,availableMethods:t.available_methods,name:t.name}}catch(t){if(t instanceof Error)throw new Error(`${r.errors.configFetchFailed}: ${t.message}`);throw new Error(`${r.errors.configFetchFailed}: ${r.errors.unknownError}`)}}({merchantId:this.options.merchantId,environment:this.options.environment??"production",baseUrl:this.options.rinneUrl});this.config=e,this.evervault=await async function(e,o,t){return new(await r())(e,o,t)}(this.config.teamId,this.config.appId)}catch(e){throw this.initPromise=null,e}})()),this.initPromise}createElementsNamespace(){return{applePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=n(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,a=!1;const i=r.button?.locale??"pt",s=n(i),p=r.button?.size??{width:"100%",height:"40px"},{width:h,height:f}=p,y={locale:u(r.button?.locale??"pt"),type:(g=r.button?.type??"plain",{book:"book",buy:"buy",checkout:"check-out",donate:"donate",order:"order",pay:"pay",plain:"plain",subscribe:"subscribe"}[g]),style:(v=r.button?.color??"black","white"===v?"white-outline":v),borderRadius:l(r.button?.borderRadius),...!!h&&!!f&&{size:{width:h,height:f}},process:async(t,n)=>{if(a||o)return Promise.resolve();try{o=!0;const i=c(t,e,"APPLE_PAY");let s=!1;const l=e=>{s=!0,n.fail(e)};return await(r.onCapture?.(i,l)),void(s||(a=!0))}catch(i){return n.fail({message:i instanceof Error?i.message:s.errors.failedToProcessApplePay}),Promise.resolve()}finally{a||(o=!1)}}};var v,g;const E=t.ui.applePay(e,y);return E.on("error",(...e)=>{if(o)return;o=!0;const t="string"==typeof e[0]?e[0]:void 0;if("CANCELLED"===t?.toUpperCase())return o=!1,void r.onCancel?.();const n={code:"PROVIDER_ERROR",message:t??s.errors.applePayError};r.onError?.(n)}),E.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({async mount(e){try{const r=d(e,i);return await E.mount(r),{unmount:()=>{E.unmount()}}}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:s.errors.failedToMountApplePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},googlePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=n(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,a=!1;const i=r.button?.locale??"pt",s=n(i),u=r.button?.size??{width:"100%",height:"40px"},{width:p,height:h}=u,f={locale:r.button?.locale??"pt",type:r.button?.type??"plain",color:r.button?.color??"black",borderRadius:l(r.button?.borderRadius),...!!p&&!!h&&{size:{width:p,height:h}},allowedAuthMethods:["CRYPTOGRAM_3DS"],process:async(t,n)=>{if(a||o)return Promise.resolve();try{o=!0;const i=c(t,e,"GOOGLE_PAY");let s=!1;const l=e=>{s=!0,n.fail(e)};return await(r.onCapture?.(i,l)),void(s||(a=!0))}catch(i){return n.fail({message:i instanceof Error?i.message:s.errors.failedToProcessGooglePay}),Promise.resolve()}finally{a||(o=!1)}}},y=t.ui.googlePay(e,f);return y.on("error",(...e)=>{if(o)return;o=!0;const t={code:"PROVIDER_ERROR",message:("string"==typeof e[0]?e[0]:void 0)??s.errors.googlePayError};r.onError?.(t)}),y.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({mount(e){try{const r=d(e,i);return y.mount(r),Promise.resolve({unmount:()=>{y.unmount()}})}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:s.errors.failedToMountGooglePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},card:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=n(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=n(r);let a={isValid:!1,isComplete:!1,errors:{}},i={card:{number:"",cvc:"",expiry:{month:"",year:""}}};const s=f(o.ui.themes,e,r),c=o.ui.card(s);return e.onReady&&c.on("ready",e.onReady),c.on("change",r=>{var o;a=h(r),o=r.card,i={card:{number:o.number??"",cvc:o.cvc??"",expiry:{month:o.expiry.month??"",year:o.expiry.year??""},name:o.name??void 0,brand:o.brand??void 0,lastFour:o.lastFour??void 0}},e.onChange?.(a)}),e.onComplete&&c.on("complete",r=>{e.onComplete?.(h(r))}),e.onFocus&&c.on("focus",r=>{e.onFocus?.(y(r.field,h(r.data)))}),e.onBlur&&c.on("blur",r=>{e.onBlur?.(y(r.field,h(r.data)))}),Promise.resolve({async mount(e){try{const o=d(e,r);return await Promise.resolve(c.mount(o)),{get values(){return i},get isComplete(){return a.isComplete},get isValid(){return a.isValid},unmount(){c.unmount()}}}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:t.errors.failedToMountCard,o);throw new Error(e.message,{cause:e})}}})});var o;return r(e)},threeDSecure:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=n(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=n(r),a=e.target,i=function(e){const r={};if(e.size&&(r.size=e.size),e.theme)if("function"==typeof e.theme)r.theme=e.theme;else{const o="string"==typeof e.theme?e.theme:e.theme.preset;o&&(r.theme=o)}return r}(e);let s=null;return Promise.resolve({async mount(n){const c=n.trim();if(!c)throw new Error(t.errors.threeDSecureSessionRequired);!function(e){if(e)try{e.unmount()}catch{}}(s),s=null;try{const t=o.ui.threeDSecure(c,i);if(s=t,function(e,r){r.onReady&&e.on("ready",r.onReady),r.onSuccess&&e.on("success",r.onSuccess),r.onFailure&&e.on("failure",e=>{r.onFailure?.(e)}),r.onError&&e.on("error",e=>{r.onError?.(e)})}(t,e),a){const e=d(a,r);await Promise.resolve(t.mount(e))}else await Promise.resolve(t.mount());return{unmount(){t.unmount(),s===t&&(s=null)}}}catch(l){const e=m("PROVIDER_ERROR",l instanceof Error?l.message:t.errors.failedToMount3DS,l);throw new Error(e.message,{cause:e})}}})});var o;return r(e)}}}createTransactionNamespace(){return{create:async e=>{if(await this.initialize(),!this.evervault||!this.config?.merchantId){const e=n("pt");throw new Error(e.errors.failedToInitialize)}return this.evervault.transactions.create({type:"payment",...e,country:e.country??"BR",currency:e.currency??"BRL",merchantId:this.config.merchantId,priceLabel:this.config.name})}}}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let e=null;async function r(){if(window.Evervault)return window.Evervault;try{return await async function(){return e||(e=new Promise((r,o)=>{const t=document.createElement("script");if(t.src="https://js.evervault.com/v2",t.onload=()=>r(),t.onerror=()=>{e=null,o()},!document.head)throw new Error("Expected document.head not to be null. Evervault.js requires a <head> element.");document.head.appendChild(t)}),e)}(),window.Evervault}catch{throw new Error("Failed to load Evervault.js")}}Promise.resolve().then(()=>{r()});const o={pt:{name:{label:"Nome no cartão",placeholder:"Nome completo",errors:{invalid:"Nome inválido"}},number:{label:"Número do cartão",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de cartão inválido"}},expiry:{label:"Validade",placeholder:"MM/AA",errors:{invalid:"Data de validade inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}},en:{name:{label:"Name on card",placeholder:"Full name",errors:{invalid:"Invalid name"}},number:{label:"Card number",placeholder:"1234 5678 9012 3456",errors:{invalid:"Invalid card number"}},expiry:{label:"Expiry",placeholder:"MM/YY",errors:{invalid:"Invalid expiry date"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"Invalid CVC"}}},es:{name:{label:"Nombre en la tarjeta",placeholder:"Nombre completo",errors:{invalid:"Nombre inválido"}},number:{label:"Número de tarjeta",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de tarjeta inválido"}},expiry:{label:"Vencimiento",placeholder:"MM/AA",errors:{invalid:"Fecha de vencimiento inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}}},t={pt:{errors:{targetElementNotFound:"Elemento alvo não encontrado",failedToInitialize:"Falha ao inicializar Rinne SDK",failedToProcessApplePay:"Falha ao processar dados do Apple Pay",failedToProcessGooglePay:"Falha ao processar dados do Google Pay",applePayError:"Erro do Apple Pay",googlePayError:"Erro do Google Pay",failedToMountApplePay:"Falha ao montar botão do Apple Pay",failedToMountGooglePay:"Falha ao montar botão do Google Pay",failedToFetchConfig:"Falha ao buscar configuração do comerciante",invalidConfig:"Configuração de comerciante inválida: campos obrigatórios ausentes",configFetchFailed:"Falha ao buscar configuração",unknownError:"Erro desconhecido",failedToMountCard:"Falha ao montar formulário de cartão",cardError:"Erro no formulário de cartão",failedToMount3DS:"Falha ao montar autenticação 3D Secure",threeDSecureError:"Erro na autenticação 3D Secure",threeDSecureFailed:"Autenticação 3D Secure falhou",threeDSecureSessionRequired:"ID da sessão 3D Secure é obrigatório"}},en:{errors:{targetElementNotFound:"Target element not found",failedToInitialize:"Failed to initialize Rinne SDK",failedToProcessApplePay:"Failed to process Apple Pay data",failedToProcessGooglePay:"Failed to process Google Pay data",applePayError:"Apple Pay error occurred",googlePayError:"Google Pay error occurred",failedToMountApplePay:"Failed to mount Apple Pay button",failedToMountGooglePay:"Failed to mount Google Pay button",failedToFetchConfig:"Failed to fetch merchant config",invalidConfig:"Invalid merchant config: missing required fields",configFetchFailed:"Configuration fetch failed",unknownError:"Unknown error",failedToMountCard:"Failed to mount card form",cardError:"Card form error",failedToMount3DS:"Failed to mount 3D Secure authentication",threeDSecureError:"3D Secure authentication error",threeDSecureFailed:"3D Secure authentication failed",threeDSecureSessionRequired:"3D Secure session ID is required"}},es:{errors:{targetElementNotFound:"Elemento objetivo no encontrado",failedToInitialize:"Error al inicializar Rinne SDK",failedToProcessApplePay:"Error al procesar datos de Apple Pay",failedToProcessGooglePay:"Error al procesar datos de Google Pay",applePayError:"Error de Apple Pay",googlePayError:"Error de Google Pay",failedToMountApplePay:"Error al montar botón de Apple Pay",failedToMountGooglePay:"Error al montar botón de Google Pay",failedToFetchConfig:"Error al obtener configuración del comerciante",invalidConfig:"Configuración de comerciante inválida: faltan campos requeridos",configFetchFailed:"Error al obtener configuración",unknownError:"Error desconocido",failedToMountCard:"Error al montar formulario de tarjeta",cardError:"Error en el formulario de tarjeta",failedToMount3DS:"Error al montar autenticación 3D Secure",threeDSecureError:"Error en la autenticación 3D Secure",threeDSecureFailed:"La autenticación 3D Secure falló",threeDSecureSessionRequired:"Se requiere el ID de sesión 3D Secure"}}};function n(e="pt"){return t[e]}const a={sandbox:"https://api-sandbox.rinne.com.br/core/v1",production:"https://api.rinne.com.br/core/v1"};function i(e){return String(e).padStart(2,"0")}function c(e){const r=String(e);return 2===r.length?`20${r}`:r}function s(e,r,o){const t=(e.card.funding??"credit").toLowerCase(),n="APPLE_PAY"===o?function(e){const{networkToken:r,card:o,cryptogram:t,eci:n,paymentDataType:a,deviceManufacturerIdentifier:s}=e;return{network_token:r.number,expiry_month:i(r.expiry.month),expiry_year:c(r.expiry.year),cryptogram:t,eci:n,token_provider:r.tokenServiceProvider,brand:o.brand,device_id:s,authentication_type:"3DSecure"===a?"3DS":void 0,last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"APPLE_PAY",display_name:o.displayName}}(e):function(e){if(!function(e){return"token"in e&&"tokenServiceProvider"in e.token}(e))throw new Error("Google Pay response must contain a network token (3DS authentication)");const{token:r,card:o,cryptogram:t,eci:n}=e;return{network_token:r.number,expiry_month:i(r.expiry.month),expiry_year:c(r.expiry.year),cryptogram:t,eci:n??null,token_provider:r.tokenServiceProvider,brand:o.brand,authentication_type:"3DS",last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"GOOGLE_PAY",display_name:o.displayName}}(e);return{card_data:n,payment_method:"debit"===t?"DEBIT_CARD":"CREDIT_CARD",transaction:r}}function l(e){if(void 0!==e)return 0===e?"0":e}function u(e){return{pt:"pt-BR",en:"en-US",es:"es-ES"}[e]}function d(e,r="pt"){if("string"==typeof e){const o=document.querySelector(e);if(!o){const o=n(r).errors.targetElementNotFound;throw new Error(`${o}: ${e}`)}return o}return e}function m(e,r,o){return{code:e,message:r,details:o}}function h(e){if(!e)return{};const r=e;return{number:r.number,expiry:r.expiry,cvc:r.cvc,name:r.name}}function p(e){return{isValid:e.isValid,isComplete:e.isComplete,errors:h(e.errors)}}function f(e,r,t){const n={};void 0!==r.icons&&(n.icons=r.icons),r.fields&&(n.fields=r.fields);const a=function(e,r){if("function"==typeof r)return r;const{preset:o,customStyles:t,customFonts:n}=function(e){return"string"==typeof e?{preset:e}:{preset:e?.preset??"material",customStyles:e?.styles,customFonts:e?.fonts}}(r),a=e[o];if(a){if(t||n){const e={};return t&&(e.styles=t),n&&(e.fonts=n),a(e)}return a()}}(e,r.theme);return void 0!==a&&(n.theme=a),void 0!==r.colorScheme&&(n.colorScheme=r.colorScheme),n.translations=function(e="pt"){return o[e]}(t),n}function y(e,r){return{field:e,state:r}}exports.Rinne=class{constructor(e){this.options=e,this.transaction=this.createTransactionNamespace(),this.elements=this.createElementsNamespace()}config=null;evervault=null;initPromise=null;transaction;elements;async initialize(){return this.initPromise||(this.initPromise=(async()=>{try{const e=await async function(e){const r=n("pt"),o=`${e.baseUrl??a[e.environment??"production"]}/merchants/${e.merchantId}/public-settings`;try{const e=await fetch(o);if(!e.ok){const o=String(e.status);throw new Error(`${r.errors.failedToFetchConfig}: ${o} ${e.statusText}`)}const t=await e.json();if(!t.merchant_id||!t.team_id||!t.app_id)throw new Error(r.errors.invalidConfig);return{merchantId:t.merchant_id,teamId:t.team_id,appId:t.app_id,availableMethods:t.available_methods,name:t.name}}catch(t){if(t instanceof Error)throw new Error(`${r.errors.configFetchFailed}: ${t.message}`);throw new Error(`${r.errors.configFetchFailed}: ${r.errors.unknownError}`)}}({merchantId:this.options.merchantId,environment:this.options.environment??"production",baseUrl:this.options.rinneUrl});this.config=e,this.evervault=await async function(e,o,t){return new(await r())(e,o,t)}(this.config.teamId,this.config.appId)}catch(e){throw this.initPromise=null,e}})()),this.initPromise}createElementsNamespace(){return{applePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=n(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,a=!1;const i=r.button?.locale??"pt",c=n(i),h=r.button?.size??{width:"100%",height:"40px"},{width:p,height:f}=h,y={locale:u(r.button?.locale??"pt"),type:(g=r.button?.type??"plain",{book:"book",buy:"buy",checkout:"check-out",donate:"donate",order:"order",pay:"pay",plain:"plain",subscribe:"subscribe"}[g]),style:(v=r.button?.color??"black","white"===v?"white-outline":v),borderRadius:l(r.button?.borderRadius),...!!p&&!!f&&{size:{width:p,height:f}},process:async(t,n)=>{if(a||o)return Promise.resolve();try{o=!0;const i=s(t,e,"APPLE_PAY");let c=!1;const l=e=>{c=!0,n.fail(e)};return await(r.onCapture?.(i,l)),void(c||(a=!0))}catch(i){return n.fail({message:i instanceof Error?i.message:c.errors.failedToProcessApplePay}),Promise.resolve()}finally{a||(o=!1)}}};var v,g;const E=t.ui.applePay(e,y);return E.on("error",(...e)=>{if(o)return;o=!0;const t="string"==typeof e[0]?e[0]:void 0;if("CANCELLED"===t?.toUpperCase())return o=!1,void r.onCancel?.();const n={code:"PROVIDER_ERROR",message:t??c.errors.applePayError};r.onError?.(n)}),E.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({async mount(e){try{const r=d(e,i);return await E.mount(r),{unmount:()=>{E.unmount()}}}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:c.errors.failedToMountApplePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},googlePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=n(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,a=!1;const i=r.button?.locale??"pt",c=n(i),u=r.button?.size??{width:"100%",height:"40px"},{width:h,height:p}=u,f={locale:r.button?.locale??"pt",type:r.button?.type??"plain",color:r.button?.color??"black",borderRadius:l(r.button?.borderRadius),...!!h&&!!p&&{size:{width:h,height:p}},...r.colorScheme&&{colorScheme:r.colorScheme},allowedAuthMethods:["CRYPTOGRAM_3DS"],process:async(t,n)=>{if(a||o)return Promise.resolve();try{o=!0;const i=s(t,e,"GOOGLE_PAY");let c=!1;const l=e=>{c=!0,n.fail(e)};return await(r.onCapture?.(i,l)),void(c||(a=!0))}catch(i){return n.fail({message:i instanceof Error?i.message:c.errors.failedToProcessGooglePay}),Promise.resolve()}finally{a||(o=!1)}}},y=t.ui.googlePay(e,f);return y.on("error",(...e)=>{if(o)return;o=!0;const t={code:"PROVIDER_ERROR",message:("string"==typeof e[0]?e[0]:void 0)??c.errors.googlePayError};r.onError?.(t)}),y.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({mount(e){try{const r=d(e,i);return y.mount(r),Promise.resolve({unmount:()=>{y.unmount()}})}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:c.errors.failedToMountGooglePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},card:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=n(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=n(r);let a={isValid:!1,isComplete:!1,errors:{}},i={card:{number:"",cvc:"",expiry:{month:"",year:""}}};const c=f(o.ui.themes,e,r),s=o.ui.card(c);return e.onReady&&s.on("ready",e.onReady),s.on("change",r=>{var o;a=p(r),o=r.card,i={card:{number:o.number??"",cvc:o.cvc??"",expiry:{month:o.expiry.month??"",year:o.expiry.year??""},name:o.name??void 0,brand:o.brand??void 0,lastFour:o.lastFour??void 0}},e.onChange?.(a)}),e.onComplete&&s.on("complete",r=>{e.onComplete?.(p(r))}),e.onFocus&&s.on("focus",r=>{e.onFocus?.(y(r.field,p(r.data)))}),e.onBlur&&s.on("blur",r=>{e.onBlur?.(y(r.field,p(r.data)))}),Promise.resolve({async mount(e){try{const o=d(e,r);return await Promise.resolve(s.mount(o)),{get values(){return i},get isComplete(){return a.isComplete},get isValid(){return a.isValid},unmount(){s.unmount()}}}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:t.errors.failedToMountCard,o);throw new Error(e.message,{cause:e})}}})});var o;return r(e)},threeDSecure:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=n(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=n(r),a=e.target,i=function(e){const r={};if(e.size&&(r.size=e.size),void 0!==e.colorScheme&&(r.colorScheme=e.colorScheme),e.theme)if("function"==typeof e.theme)r.theme=e.theme;else{const o="string"==typeof e.theme?e.theme:e.theme.preset;o&&(r.theme=o)}return r}(e);let c=null;return Promise.resolve({async mount(n){const s=n.trim();if(!s)throw new Error(t.errors.threeDSecureSessionRequired);!function(e){if(e)try{e.unmount()}catch{}}(c),c=null;try{const t=o.ui.threeDSecure(s,i);if(c=t,function(e,r){r.onReady&&e.on("ready",r.onReady),r.onSuccess&&e.on("success",r.onSuccess),r.onFailure&&e.on("failure",e=>{r.onFailure?.(e)}),r.onError&&e.on("error",e=>{r.onError?.(e)})}(t,e),a){const e=d(a,r);await Promise.resolve(t.mount(e))}else await Promise.resolve(t.mount());return{unmount(){t.unmount(),c===t&&(c=null)}}}catch(l){const e=m("PROVIDER_ERROR",l instanceof Error?l.message:t.errors.failedToMount3DS,l);throw new Error(e.message,{cause:e})}}})});var o;return r(e)}}}createTransactionNamespace(){return{create:async e=>{if(await this.initialize(),!this.evervault||!this.config?.merchantId){const e=n("pt");throw new Error(e.errors.failedToInitialize)}return this.evervault.transactions.create({type:"payment",...e,country:e.country??"BR",currency:e.currency??"BRL",merchantId:this.config.merchantId,priceLabel:this.config.name})}}}};
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,11 @@ export declare interface CardElementOptions {
|
|
|
56
56
|
* @default 'material'
|
|
57
57
|
*/
|
|
58
58
|
theme?: ThemeOption;
|
|
59
|
+
/**
|
|
60
|
+
* Root color-scheme for the card iframe.
|
|
61
|
+
* Use the same value as your page for a seamless transparent background.
|
|
62
|
+
*/
|
|
63
|
+
colorScheme?: ColorScheme;
|
|
59
64
|
/** Locale for error messages. @default 'pt' */
|
|
60
65
|
locale?: Locale;
|
|
61
66
|
/** Whether to show card brand icons */
|
|
@@ -144,6 +149,12 @@ export declare interface CardValues {
|
|
|
144
149
|
};
|
|
145
150
|
}
|
|
146
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Root color-scheme for iframe documents.
|
|
154
|
+
* Use the same value as your page for a seamless transparent background.
|
|
155
|
+
*/
|
|
156
|
+
export declare type ColorScheme = 'light' | 'dark';
|
|
157
|
+
|
|
147
158
|
export declare interface ElementsNamespace {
|
|
148
159
|
applePay: ApplePayElementNamespace;
|
|
149
160
|
googlePay: GooglePayElementNamespace;
|
|
@@ -165,6 +176,11 @@ export declare type GooglePayElementNamespace = (transaction: EvTransaction, opt
|
|
|
165
176
|
|
|
166
177
|
export declare interface GooglePayMountOptions extends WalletHandlers {
|
|
167
178
|
button?: WalletButtonOptions;
|
|
179
|
+
/**
|
|
180
|
+
* Root color-scheme for the Google Pay iframe.
|
|
181
|
+
* Use the same value as your page for a seamless transparent background.
|
|
182
|
+
*/
|
|
183
|
+
colorScheme?: ColorScheme;
|
|
168
184
|
}
|
|
169
185
|
|
|
170
186
|
export declare type Locale = 'pt' | 'en' | 'es';
|
|
@@ -309,6 +325,11 @@ export declare interface ThreeDSecureElementOptions {
|
|
|
309
325
|
width: string;
|
|
310
326
|
height: string;
|
|
311
327
|
};
|
|
328
|
+
/**
|
|
329
|
+
* Root color-scheme for the 3DS iframe.
|
|
330
|
+
* Use the same value as your page for a seamless transparent background.
|
|
331
|
+
*/
|
|
332
|
+
colorScheme?: ColorScheme;
|
|
312
333
|
/**
|
|
313
334
|
* Theme configuration for the 3DS challenge UI.
|
|
314
335
|
* Can be a preset name, config object, or function for responsive styling.
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let e=null;async function r(){if(window.Evervault)return window.Evervault;try{return await async function(){return e||(e=new Promise((r,o)=>{const t=document.createElement("script");if(t.src="https://js.evervault.com/v2",t.onload=()=>r(),t.onerror=()=>{e=null,o()},!document.head)throw new Error("Expected document.head not to be null. Evervault.js requires a <head> element.");document.head.appendChild(t)}),e)}(),window.Evervault}catch{throw new Error("Failed to load Evervault.js")}}Promise.resolve().then(()=>{r()});const o={pt:{name:{label:"Nome no cartão",placeholder:"Nome completo",errors:{invalid:"Nome inválido"}},number:{label:"Número do cartão",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de cartão inválido"}},expiry:{label:"Validade",placeholder:"MM/AA",errors:{invalid:"Data de validade inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}},en:{name:{label:"Name on card",placeholder:"Full name",errors:{invalid:"Invalid name"}},number:{label:"Card number",placeholder:"1234 5678 9012 3456",errors:{invalid:"Invalid card number"}},expiry:{label:"Expiry",placeholder:"MM/YY",errors:{invalid:"Invalid expiry date"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"Invalid CVC"}}},es:{name:{label:"Nombre en la tarjeta",placeholder:"Nombre completo",errors:{invalid:"Nombre inválido"}},number:{label:"Número de tarjeta",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de tarjeta inválido"}},expiry:{label:"Vencimiento",placeholder:"MM/AA",errors:{invalid:"Fecha de vencimiento inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}}},t={pt:{errors:{targetElementNotFound:"Elemento alvo não encontrado",failedToInitialize:"Falha ao inicializar Rinne SDK",failedToProcessApplePay:"Falha ao processar dados do Apple Pay",failedToProcessGooglePay:"Falha ao processar dados do Google Pay",applePayError:"Erro do Apple Pay",googlePayError:"Erro do Google Pay",failedToMountApplePay:"Falha ao montar botão do Apple Pay",failedToMountGooglePay:"Falha ao montar botão do Google Pay",failedToFetchConfig:"Falha ao buscar configuração do comerciante",invalidConfig:"Configuração de comerciante inválida: campos obrigatórios ausentes",configFetchFailed:"Falha ao buscar configuração",unknownError:"Erro desconhecido",failedToMountCard:"Falha ao montar formulário de cartão",cardError:"Erro no formulário de cartão",failedToMount3DS:"Falha ao montar autenticação 3D Secure",threeDSecureError:"Erro na autenticação 3D Secure",threeDSecureFailed:"Autenticação 3D Secure falhou",threeDSecureSessionRequired:"ID da sessão 3D Secure é obrigatório"}},en:{errors:{targetElementNotFound:"Target element not found",failedToInitialize:"Failed to initialize Rinne SDK",failedToProcessApplePay:"Failed to process Apple Pay data",failedToProcessGooglePay:"Failed to process Google Pay data",applePayError:"Apple Pay error occurred",googlePayError:"Google Pay error occurred",failedToMountApplePay:"Failed to mount Apple Pay button",failedToMountGooglePay:"Failed to mount Google Pay button",failedToFetchConfig:"Failed to fetch merchant config",invalidConfig:"Invalid merchant config: missing required fields",configFetchFailed:"Configuration fetch failed",unknownError:"Unknown error",failedToMountCard:"Failed to mount card form",cardError:"Card form error",failedToMount3DS:"Failed to mount 3D Secure authentication",threeDSecureError:"3D Secure authentication error",threeDSecureFailed:"3D Secure authentication failed",threeDSecureSessionRequired:"3D Secure session ID is required"}},es:{errors:{targetElementNotFound:"Elemento objetivo no encontrado",failedToInitialize:"Error al inicializar Rinne SDK",failedToProcessApplePay:"Error al procesar datos de Apple Pay",failedToProcessGooglePay:"Error al procesar datos de Google Pay",applePayError:"Error de Apple Pay",googlePayError:"Error de Google Pay",failedToMountApplePay:"Error al montar botón de Apple Pay",failedToMountGooglePay:"Error al montar botón de Google Pay",failedToFetchConfig:"Error al obtener configuración del comerciante",invalidConfig:"Configuración de comerciante inválida: faltan campos requeridos",configFetchFailed:"Error al obtener configuración",unknownError:"Error desconocido",failedToMountCard:"Error al montar formulario de tarjeta",cardError:"Error en el formulario de tarjeta",failedToMount3DS:"Error al montar autenticación 3D Secure",threeDSecureError:"Error en la autenticación 3D Secure",threeDSecureFailed:"La autenticación 3D Secure falló",threeDSecureSessionRequired:"Se requiere el ID de sesión 3D Secure"}}};function n(e="pt"){return t[e]}const a={sandbox:"https://api-sandbox.rinne.com.br/core/v1",production:"https://api.rinne.com.br/core/v1"};function i(e){return String(e).padStart(2,"0")}function s(e){const r=String(e);return 2===r.length?`20${r}`:r}function c(e,r,o){const t=(e.card.funding??"credit").toLowerCase(),n="APPLE_PAY"===o?function(e){const{networkToken:r,card:o,cryptogram:t,eci:n,paymentDataType:a,deviceManufacturerIdentifier:c}=e;return{network_token:r.number,expiry_month:i(r.expiry.month),expiry_year:s(r.expiry.year),cryptogram:t,eci:n,token_provider:r.tokenServiceProvider,brand:o.brand,device_id:c,authentication_type:"3DSecure"===a?"3DS":void 0,last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"APPLE_PAY",display_name:o.displayName}}(e):function(e){if(!function(e){return"token"in e&&"tokenServiceProvider"in e.token}(e))throw new Error("Google Pay response must contain a network token (3DS authentication)");const{token:r,card:o,cryptogram:t,eci:n}=e;return{network_token:r.number,expiry_month:i(r.expiry.month),expiry_year:s(r.expiry.year),cryptogram:t,eci:n??null,token_provider:r.tokenServiceProvider,brand:o.brand,authentication_type:"3DS",last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"GOOGLE_PAY",display_name:o.displayName}}(e);return{card_data:n,payment_method:"debit"===t?"DEBIT_CARD":"CREDIT_CARD",transaction:r}}function l(e){if(void 0!==e)return 0===e?"0":e}function u(e){return{pt:"pt-BR",en:"en-US",es:"es-ES"}[e]}function d(e,r="pt"){if("string"==typeof e){const o=document.querySelector(e);if(!o){const o=n(r).errors.targetElementNotFound;throw new Error(`${o}: ${e}`)}return o}return e}function m(e,r,o){return{code:e,message:r,details:o}}function p(e){if(!e)return{};const r=e;return{number:r.number,expiry:r.expiry,cvc:r.cvc,name:r.name}}function h(e){return{isValid:e.isValid,isComplete:e.isComplete,errors:p(e.errors)}}function f(e,r,t){const n={};void 0!==r.icons&&(n.icons=r.icons),r.fields&&(n.fields=r.fields);const a=function(e,r){if("function"==typeof r)return r;const{preset:o,customStyles:t,customFonts:n}=function(e){return"string"==typeof e?{preset:e}:{preset:e?.preset??"material",customStyles:e?.styles,customFonts:e?.fonts}}(r),a=e[o];if(a){if(t||n){const e={};return t&&(e.styles=t),n&&(e.fonts=n),a(e)}return a()}}(e,r.theme);return void 0!==a&&(n.theme=a),n.translations=function(e="pt"){return o[e]}(t),n}function y(e,r){return{field:e,state:r}}class v{constructor(e){this.options=e,this.transaction=this.createTransactionNamespace(),this.elements=this.createElementsNamespace()}config=null;evervault=null;initPromise=null;transaction;elements;async initialize(){return this.initPromise||(this.initPromise=(async()=>{try{const e=await async function(e){const r=n("pt"),o=`${e.baseUrl??a[e.environment??"production"]}/merchants/${e.merchantId}/public-settings`;try{const e=await fetch(o);if(!e.ok){const o=String(e.status);throw new Error(`${r.errors.failedToFetchConfig}: ${o} ${e.statusText}`)}const t=await e.json();if(!t.merchant_id||!t.team_id||!t.app_id)throw new Error(r.errors.invalidConfig);return{merchantId:t.merchant_id,teamId:t.team_id,appId:t.app_id,availableMethods:t.available_methods,name:t.name}}catch(t){if(t instanceof Error)throw new Error(`${r.errors.configFetchFailed}: ${t.message}`);throw new Error(`${r.errors.configFetchFailed}: ${r.errors.unknownError}`)}}({merchantId:this.options.merchantId,environment:this.options.environment??"production",baseUrl:this.options.rinneUrl});this.config=e,this.evervault=await async function(e,o,t){return new(await r())(e,o,t)}(this.config.teamId,this.config.appId)}catch(e){throw this.initPromise=null,e}})()),this.initPromise}createElementsNamespace(){return{applePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=n(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,a=!1;const i=r.button?.locale??"pt",s=n(i),p=r.button?.size??{width:"100%",height:"40px"},{width:h,height:f}=p,y={locale:u(r.button?.locale??"pt"),type:(g=r.button?.type??"plain",{book:"book",buy:"buy",checkout:"check-out",donate:"donate",order:"order",pay:"pay",plain:"plain",subscribe:"subscribe"}[g]),style:(v=r.button?.color??"black","white"===v?"white-outline":v),borderRadius:l(r.button?.borderRadius),...!!h&&!!f&&{size:{width:h,height:f}},process:async(t,n)=>{if(a||o)return Promise.resolve();try{o=!0;const i=c(t,e,"APPLE_PAY");let s=!1;const l=e=>{s=!0,n.fail(e)};return await(r.onCapture?.(i,l)),void(s||(a=!0))}catch(i){return n.fail({message:i instanceof Error?i.message:s.errors.failedToProcessApplePay}),Promise.resolve()}finally{a||(o=!1)}}};var v,g;const E=t.ui.applePay(e,y);return E.on("error",(...e)=>{if(o)return;o=!0;const t="string"==typeof e[0]?e[0]:void 0;if("CANCELLED"===t?.toUpperCase())return o=!1,void r.onCancel?.();const n={code:"PROVIDER_ERROR",message:t??s.errors.applePayError};r.onError?.(n)}),E.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({async mount(e){try{const r=d(e,i);return await E.mount(r),{unmount:()=>{E.unmount()}}}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:s.errors.failedToMountApplePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},googlePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=n(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,a=!1;const i=r.button?.locale??"pt",s=n(i),u=r.button?.size??{width:"100%",height:"40px"},{width:p,height:h}=u,f={locale:r.button?.locale??"pt",type:r.button?.type??"plain",color:r.button?.color??"black",borderRadius:l(r.button?.borderRadius),...!!p&&!!h&&{size:{width:p,height:h}},allowedAuthMethods:["CRYPTOGRAM_3DS"],process:async(t,n)=>{if(a||o)return Promise.resolve();try{o=!0;const i=c(t,e,"GOOGLE_PAY");let s=!1;const l=e=>{s=!0,n.fail(e)};return await(r.onCapture?.(i,l)),void(s||(a=!0))}catch(i){return n.fail({message:i instanceof Error?i.message:s.errors.failedToProcessGooglePay}),Promise.resolve()}finally{a||(o=!1)}}},y=t.ui.googlePay(e,f);return y.on("error",(...e)=>{if(o)return;o=!0;const t={code:"PROVIDER_ERROR",message:("string"==typeof e[0]?e[0]:void 0)??s.errors.googlePayError};r.onError?.(t)}),y.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({mount(e){try{const r=d(e,i);return y.mount(r),Promise.resolve({unmount:()=>{y.unmount()}})}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:s.errors.failedToMountGooglePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},card:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=n(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=n(r);let a={isValid:!1,isComplete:!1,errors:{}},i={card:{number:"",cvc:"",expiry:{month:"",year:""}}};const s=f(o.ui.themes,e,r),c=o.ui.card(s);return e.onReady&&c.on("ready",e.onReady),c.on("change",r=>{var o;a=h(r),o=r.card,i={card:{number:o.number??"",cvc:o.cvc??"",expiry:{month:o.expiry.month??"",year:o.expiry.year??""},name:o.name??void 0,brand:o.brand??void 0,lastFour:o.lastFour??void 0}},e.onChange?.(a)}),e.onComplete&&c.on("complete",r=>{e.onComplete?.(h(r))}),e.onFocus&&c.on("focus",r=>{e.onFocus?.(y(r.field,h(r.data)))}),e.onBlur&&c.on("blur",r=>{e.onBlur?.(y(r.field,h(r.data)))}),Promise.resolve({async mount(e){try{const o=d(e,r);return await Promise.resolve(c.mount(o)),{get values(){return i},get isComplete(){return a.isComplete},get isValid(){return a.isValid},unmount(){c.unmount()}}}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:t.errors.failedToMountCard,o);throw new Error(e.message,{cause:e})}}})});var o;return r(e)},threeDSecure:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=n(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=n(r),a=e.target,i=function(e){const r={};if(e.size&&(r.size=e.size),e.theme)if("function"==typeof e.theme)r.theme=e.theme;else{const o="string"==typeof e.theme?e.theme:e.theme.preset;o&&(r.theme=o)}return r}(e);let s=null;return Promise.resolve({async mount(n){const c=n.trim();if(!c)throw new Error(t.errors.threeDSecureSessionRequired);!function(e){if(e)try{e.unmount()}catch{}}(s),s=null;try{const t=o.ui.threeDSecure(c,i);if(s=t,function(e,r){r.onReady&&e.on("ready",r.onReady),r.onSuccess&&e.on("success",r.onSuccess),r.onFailure&&e.on("failure",e=>{r.onFailure?.(e)}),r.onError&&e.on("error",e=>{r.onError?.(e)})}(t,e),a){const e=d(a,r);await Promise.resolve(t.mount(e))}else await Promise.resolve(t.mount());return{unmount(){t.unmount(),s===t&&(s=null)}}}catch(l){const e=m("PROVIDER_ERROR",l instanceof Error?l.message:t.errors.failedToMount3DS,l);throw new Error(e.message,{cause:e})}}})});var o;return r(e)}}}createTransactionNamespace(){return{create:async e=>{if(await this.initialize(),!this.evervault||!this.config?.merchantId){const e=n("pt");throw new Error(e.errors.failedToInitialize)}return this.evervault.transactions.create({type:"payment",...e,country:e.country??"BR",currency:e.currency??"BRL",merchantId:this.config.merchantId,priceLabel:this.config.name})}}}}export{v as Rinne};
|
|
1
|
+
let e=null;async function r(){if(window.Evervault)return window.Evervault;try{return await async function(){return e||(e=new Promise((r,o)=>{const t=document.createElement("script");if(t.src="https://js.evervault.com/v2",t.onload=()=>r(),t.onerror=()=>{e=null,o()},!document.head)throw new Error("Expected document.head not to be null. Evervault.js requires a <head> element.");document.head.appendChild(t)}),e)}(),window.Evervault}catch{throw new Error("Failed to load Evervault.js")}}Promise.resolve().then(()=>{r()});const o={pt:{name:{label:"Nome no cartão",placeholder:"Nome completo",errors:{invalid:"Nome inválido"}},number:{label:"Número do cartão",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de cartão inválido"}},expiry:{label:"Validade",placeholder:"MM/AA",errors:{invalid:"Data de validade inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}},en:{name:{label:"Name on card",placeholder:"Full name",errors:{invalid:"Invalid name"}},number:{label:"Card number",placeholder:"1234 5678 9012 3456",errors:{invalid:"Invalid card number"}},expiry:{label:"Expiry",placeholder:"MM/YY",errors:{invalid:"Invalid expiry date"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"Invalid CVC"}}},es:{name:{label:"Nombre en la tarjeta",placeholder:"Nombre completo",errors:{invalid:"Nombre inválido"}},number:{label:"Número de tarjeta",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de tarjeta inválido"}},expiry:{label:"Vencimiento",placeholder:"MM/AA",errors:{invalid:"Fecha de vencimiento inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}}},t={pt:{errors:{targetElementNotFound:"Elemento alvo não encontrado",failedToInitialize:"Falha ao inicializar Rinne SDK",failedToProcessApplePay:"Falha ao processar dados do Apple Pay",failedToProcessGooglePay:"Falha ao processar dados do Google Pay",applePayError:"Erro do Apple Pay",googlePayError:"Erro do Google Pay",failedToMountApplePay:"Falha ao montar botão do Apple Pay",failedToMountGooglePay:"Falha ao montar botão do Google Pay",failedToFetchConfig:"Falha ao buscar configuração do comerciante",invalidConfig:"Configuração de comerciante inválida: campos obrigatórios ausentes",configFetchFailed:"Falha ao buscar configuração",unknownError:"Erro desconhecido",failedToMountCard:"Falha ao montar formulário de cartão",cardError:"Erro no formulário de cartão",failedToMount3DS:"Falha ao montar autenticação 3D Secure",threeDSecureError:"Erro na autenticação 3D Secure",threeDSecureFailed:"Autenticação 3D Secure falhou",threeDSecureSessionRequired:"ID da sessão 3D Secure é obrigatório"}},en:{errors:{targetElementNotFound:"Target element not found",failedToInitialize:"Failed to initialize Rinne SDK",failedToProcessApplePay:"Failed to process Apple Pay data",failedToProcessGooglePay:"Failed to process Google Pay data",applePayError:"Apple Pay error occurred",googlePayError:"Google Pay error occurred",failedToMountApplePay:"Failed to mount Apple Pay button",failedToMountGooglePay:"Failed to mount Google Pay button",failedToFetchConfig:"Failed to fetch merchant config",invalidConfig:"Invalid merchant config: missing required fields",configFetchFailed:"Configuration fetch failed",unknownError:"Unknown error",failedToMountCard:"Failed to mount card form",cardError:"Card form error",failedToMount3DS:"Failed to mount 3D Secure authentication",threeDSecureError:"3D Secure authentication error",threeDSecureFailed:"3D Secure authentication failed",threeDSecureSessionRequired:"3D Secure session ID is required"}},es:{errors:{targetElementNotFound:"Elemento objetivo no encontrado",failedToInitialize:"Error al inicializar Rinne SDK",failedToProcessApplePay:"Error al procesar datos de Apple Pay",failedToProcessGooglePay:"Error al procesar datos de Google Pay",applePayError:"Error de Apple Pay",googlePayError:"Error de Google Pay",failedToMountApplePay:"Error al montar botón de Apple Pay",failedToMountGooglePay:"Error al montar botón de Google Pay",failedToFetchConfig:"Error al obtener configuración del comerciante",invalidConfig:"Configuración de comerciante inválida: faltan campos requeridos",configFetchFailed:"Error al obtener configuración",unknownError:"Error desconocido",failedToMountCard:"Error al montar formulario de tarjeta",cardError:"Error en el formulario de tarjeta",failedToMount3DS:"Error al montar autenticación 3D Secure",threeDSecureError:"Error en la autenticación 3D Secure",threeDSecureFailed:"La autenticación 3D Secure falló",threeDSecureSessionRequired:"Se requiere el ID de sesión 3D Secure"}}};function n(e="pt"){return t[e]}const a={sandbox:"https://api-sandbox.rinne.com.br/core/v1",production:"https://api.rinne.com.br/core/v1"};function i(e){return String(e).padStart(2,"0")}function c(e){const r=String(e);return 2===r.length?`20${r}`:r}function s(e,r,o){const t=(e.card.funding??"credit").toLowerCase(),n="APPLE_PAY"===o?function(e){const{networkToken:r,card:o,cryptogram:t,eci:n,paymentDataType:a,deviceManufacturerIdentifier:s}=e;return{network_token:r.number,expiry_month:i(r.expiry.month),expiry_year:c(r.expiry.year),cryptogram:t,eci:n,token_provider:r.tokenServiceProvider,brand:o.brand,device_id:s,authentication_type:"3DSecure"===a?"3DS":void 0,last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"APPLE_PAY",display_name:o.displayName}}(e):function(e){if(!function(e){return"token"in e&&"tokenServiceProvider"in e.token}(e))throw new Error("Google Pay response must contain a network token (3DS authentication)");const{token:r,card:o,cryptogram:t,eci:n}=e;return{network_token:r.number,expiry_month:i(r.expiry.month),expiry_year:c(r.expiry.year),cryptogram:t,eci:n??null,token_provider:r.tokenServiceProvider,brand:o.brand,authentication_type:"3DS",last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"GOOGLE_PAY",display_name:o.displayName}}(e);return{card_data:n,payment_method:"debit"===t?"DEBIT_CARD":"CREDIT_CARD",transaction:r}}function l(e){if(void 0!==e)return 0===e?"0":e}function u(e){return{pt:"pt-BR",en:"en-US",es:"es-ES"}[e]}function d(e,r="pt"){if("string"==typeof e){const o=document.querySelector(e);if(!o){const o=n(r).errors.targetElementNotFound;throw new Error(`${o}: ${e}`)}return o}return e}function m(e,r,o){return{code:e,message:r,details:o}}function h(e){if(!e)return{};const r=e;return{number:r.number,expiry:r.expiry,cvc:r.cvc,name:r.name}}function p(e){return{isValid:e.isValid,isComplete:e.isComplete,errors:h(e.errors)}}function f(e,r,t){const n={};void 0!==r.icons&&(n.icons=r.icons),r.fields&&(n.fields=r.fields);const a=function(e,r){if("function"==typeof r)return r;const{preset:o,customStyles:t,customFonts:n}=function(e){return"string"==typeof e?{preset:e}:{preset:e?.preset??"material",customStyles:e?.styles,customFonts:e?.fonts}}(r),a=e[o];if(a){if(t||n){const e={};return t&&(e.styles=t),n&&(e.fonts=n),a(e)}return a()}}(e,r.theme);return void 0!==a&&(n.theme=a),void 0!==r.colorScheme&&(n.colorScheme=r.colorScheme),n.translations=function(e="pt"){return o[e]}(t),n}function y(e,r){return{field:e,state:r}}class v{constructor(e){this.options=e,this.transaction=this.createTransactionNamespace(),this.elements=this.createElementsNamespace()}config=null;evervault=null;initPromise=null;transaction;elements;async initialize(){return this.initPromise||(this.initPromise=(async()=>{try{const e=await async function(e){const r=n("pt"),o=`${e.baseUrl??a[e.environment??"production"]}/merchants/${e.merchantId}/public-settings`;try{const e=await fetch(o);if(!e.ok){const o=String(e.status);throw new Error(`${r.errors.failedToFetchConfig}: ${o} ${e.statusText}`)}const t=await e.json();if(!t.merchant_id||!t.team_id||!t.app_id)throw new Error(r.errors.invalidConfig);return{merchantId:t.merchant_id,teamId:t.team_id,appId:t.app_id,availableMethods:t.available_methods,name:t.name}}catch(t){if(t instanceof Error)throw new Error(`${r.errors.configFetchFailed}: ${t.message}`);throw new Error(`${r.errors.configFetchFailed}: ${r.errors.unknownError}`)}}({merchantId:this.options.merchantId,environment:this.options.environment??"production",baseUrl:this.options.rinneUrl});this.config=e,this.evervault=await async function(e,o,t){return new(await r())(e,o,t)}(this.config.teamId,this.config.appId)}catch(e){throw this.initPromise=null,e}})()),this.initPromise}createElementsNamespace(){return{applePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=n(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,a=!1;const i=r.button?.locale??"pt",c=n(i),h=r.button?.size??{width:"100%",height:"40px"},{width:p,height:f}=h,y={locale:u(r.button?.locale??"pt"),type:(g=r.button?.type??"plain",{book:"book",buy:"buy",checkout:"check-out",donate:"donate",order:"order",pay:"pay",plain:"plain",subscribe:"subscribe"}[g]),style:(v=r.button?.color??"black","white"===v?"white-outline":v),borderRadius:l(r.button?.borderRadius),...!!p&&!!f&&{size:{width:p,height:f}},process:async(t,n)=>{if(a||o)return Promise.resolve();try{o=!0;const i=s(t,e,"APPLE_PAY");let c=!1;const l=e=>{c=!0,n.fail(e)};return await(r.onCapture?.(i,l)),void(c||(a=!0))}catch(i){return n.fail({message:i instanceof Error?i.message:c.errors.failedToProcessApplePay}),Promise.resolve()}finally{a||(o=!1)}}};var v,g;const E=t.ui.applePay(e,y);return E.on("error",(...e)=>{if(o)return;o=!0;const t="string"==typeof e[0]?e[0]:void 0;if("CANCELLED"===t?.toUpperCase())return o=!1,void r.onCancel?.();const n={code:"PROVIDER_ERROR",message:t??c.errors.applePayError};r.onError?.(n)}),E.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({async mount(e){try{const r=d(e,i);return await E.mount(r),{unmount:()=>{E.unmount()}}}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:c.errors.failedToMountApplePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},googlePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=n(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,a=!1;const i=r.button?.locale??"pt",c=n(i),u=r.button?.size??{width:"100%",height:"40px"},{width:h,height:p}=u,f={locale:r.button?.locale??"pt",type:r.button?.type??"plain",color:r.button?.color??"black",borderRadius:l(r.button?.borderRadius),...!!h&&!!p&&{size:{width:h,height:p}},...r.colorScheme&&{colorScheme:r.colorScheme},allowedAuthMethods:["CRYPTOGRAM_3DS"],process:async(t,n)=>{if(a||o)return Promise.resolve();try{o=!0;const i=s(t,e,"GOOGLE_PAY");let c=!1;const l=e=>{c=!0,n.fail(e)};return await(r.onCapture?.(i,l)),void(c||(a=!0))}catch(i){return n.fail({message:i instanceof Error?i.message:c.errors.failedToProcessGooglePay}),Promise.resolve()}finally{a||(o=!1)}}},y=t.ui.googlePay(e,f);return y.on("error",(...e)=>{if(o)return;o=!0;const t={code:"PROVIDER_ERROR",message:("string"==typeof e[0]?e[0]:void 0)??c.errors.googlePayError};r.onError?.(t)}),y.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({mount(e){try{const r=d(e,i);return y.mount(r),Promise.resolve({unmount:()=>{y.unmount()}})}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:c.errors.failedToMountGooglePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},card:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=n(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=n(r);let a={isValid:!1,isComplete:!1,errors:{}},i={card:{number:"",cvc:"",expiry:{month:"",year:""}}};const c=f(o.ui.themes,e,r),s=o.ui.card(c);return e.onReady&&s.on("ready",e.onReady),s.on("change",r=>{var o;a=p(r),o=r.card,i={card:{number:o.number??"",cvc:o.cvc??"",expiry:{month:o.expiry.month??"",year:o.expiry.year??""},name:o.name??void 0,brand:o.brand??void 0,lastFour:o.lastFour??void 0}},e.onChange?.(a)}),e.onComplete&&s.on("complete",r=>{e.onComplete?.(p(r))}),e.onFocus&&s.on("focus",r=>{e.onFocus?.(y(r.field,p(r.data)))}),e.onBlur&&s.on("blur",r=>{e.onBlur?.(y(r.field,p(r.data)))}),Promise.resolve({async mount(e){try{const o=d(e,r);return await Promise.resolve(s.mount(o)),{get values(){return i},get isComplete(){return a.isComplete},get isValid(){return a.isValid},unmount(){s.unmount()}}}catch(o){const e=m("PROVIDER_ERROR",o instanceof Error?o.message:t.errors.failedToMountCard,o);throw new Error(e.message,{cause:e})}}})});var o;return r(e)},threeDSecure:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=n(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=n(r),a=e.target,i=function(e){const r={};if(e.size&&(r.size=e.size),void 0!==e.colorScheme&&(r.colorScheme=e.colorScheme),e.theme)if("function"==typeof e.theme)r.theme=e.theme;else{const o="string"==typeof e.theme?e.theme:e.theme.preset;o&&(r.theme=o)}return r}(e);let c=null;return Promise.resolve({async mount(n){const s=n.trim();if(!s)throw new Error(t.errors.threeDSecureSessionRequired);!function(e){if(e)try{e.unmount()}catch{}}(c),c=null;try{const t=o.ui.threeDSecure(s,i);if(c=t,function(e,r){r.onReady&&e.on("ready",r.onReady),r.onSuccess&&e.on("success",r.onSuccess),r.onFailure&&e.on("failure",e=>{r.onFailure?.(e)}),r.onError&&e.on("error",e=>{r.onError?.(e)})}(t,e),a){const e=d(a,r);await Promise.resolve(t.mount(e))}else await Promise.resolve(t.mount());return{unmount(){t.unmount(),c===t&&(c=null)}}}catch(l){const e=m("PROVIDER_ERROR",l instanceof Error?l.message:t.errors.failedToMount3DS,l);throw new Error(e.message,{cause:e})}}})});var o;return r(e)}}}createTransactionNamespace(){return{create:async e=>{if(await this.initialize(),!this.evervault||!this.config?.merchantId){const e=n("pt");throw new Error(e.errors.failedToInitialize)}return this.evervault.transactions.create({type:"payment",...e,country:e.country??"BR",currency:e.currency??"BRL",merchantId:this.config.merchantId,priceLabel:this.config.name})}}}}export{v as Rinne};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).Rinne={})}(this,function(e){"use strict";let r=null;async function o(){if(window.Evervault)return window.Evervault;try{return await async function(){return r||(r=new Promise((e,o)=>{const t=document.createElement("script");if(t.src="https://js.evervault.com/v2",t.onload=()=>e(),t.onerror=()=>{r=null,o()},!document.head)throw new Error("Expected document.head not to be null. Evervault.js requires a <head> element.");document.head.appendChild(t)}),r)}(),window.Evervault}catch{throw new Error("Failed to load Evervault.js")}}Promise.resolve().then(()=>{o()});const t={pt:{name:{label:"Nome no cartão",placeholder:"Nome completo",errors:{invalid:"Nome inválido"}},number:{label:"Número do cartão",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de cartão inválido"}},expiry:{label:"Validade",placeholder:"MM/AA",errors:{invalid:"Data de validade inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}},en:{name:{label:"Name on card",placeholder:"Full name",errors:{invalid:"Invalid name"}},number:{label:"Card number",placeholder:"1234 5678 9012 3456",errors:{invalid:"Invalid card number"}},expiry:{label:"Expiry",placeholder:"MM/YY",errors:{invalid:"Invalid expiry date"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"Invalid CVC"}}},es:{name:{label:"Nombre en la tarjeta",placeholder:"Nombre completo",errors:{invalid:"Nombre inválido"}},number:{label:"Número de tarjeta",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de tarjeta inválido"}},expiry:{label:"Vencimiento",placeholder:"MM/AA",errors:{invalid:"Fecha de vencimiento inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}}},n={pt:{errors:{targetElementNotFound:"Elemento alvo não encontrado",failedToInitialize:"Falha ao inicializar Rinne SDK",failedToProcessApplePay:"Falha ao processar dados do Apple Pay",failedToProcessGooglePay:"Falha ao processar dados do Google Pay",applePayError:"Erro do Apple Pay",googlePayError:"Erro do Google Pay",failedToMountApplePay:"Falha ao montar botão do Apple Pay",failedToMountGooglePay:"Falha ao montar botão do Google Pay",failedToFetchConfig:"Falha ao buscar configuração do comerciante",invalidConfig:"Configuração de comerciante inválida: campos obrigatórios ausentes",configFetchFailed:"Falha ao buscar configuração",unknownError:"Erro desconhecido",failedToMountCard:"Falha ao montar formulário de cartão",cardError:"Erro no formulário de cartão",failedToMount3DS:"Falha ao montar autenticação 3D Secure",threeDSecureError:"Erro na autenticação 3D Secure",threeDSecureFailed:"Autenticação 3D Secure falhou",threeDSecureSessionRequired:"ID da sessão 3D Secure é obrigatório"}},en:{errors:{targetElementNotFound:"Target element not found",failedToInitialize:"Failed to initialize Rinne SDK",failedToProcessApplePay:"Failed to process Apple Pay data",failedToProcessGooglePay:"Failed to process Google Pay data",applePayError:"Apple Pay error occurred",googlePayError:"Google Pay error occurred",failedToMountApplePay:"Failed to mount Apple Pay button",failedToMountGooglePay:"Failed to mount Google Pay button",failedToFetchConfig:"Failed to fetch merchant config",invalidConfig:"Invalid merchant config: missing required fields",configFetchFailed:"Configuration fetch failed",unknownError:"Unknown error",failedToMountCard:"Failed to mount card form",cardError:"Card form error",failedToMount3DS:"Failed to mount 3D Secure authentication",threeDSecureError:"3D Secure authentication error",threeDSecureFailed:"3D Secure authentication failed",threeDSecureSessionRequired:"3D Secure session ID is required"}},es:{errors:{targetElementNotFound:"Elemento objetivo no encontrado",failedToInitialize:"Error al inicializar Rinne SDK",failedToProcessApplePay:"Error al procesar datos de Apple Pay",failedToProcessGooglePay:"Error al procesar datos de Google Pay",applePayError:"Error de Apple Pay",googlePayError:"Error de Google Pay",failedToMountApplePay:"Error al montar botón de Apple Pay",failedToMountGooglePay:"Error al montar botón de Google Pay",failedToFetchConfig:"Error al obtener configuración del comerciante",invalidConfig:"Configuración de comerciante inválida: faltan campos requeridos",configFetchFailed:"Error al obtener configuración",unknownError:"Error desconocido",failedToMountCard:"Error al montar formulario de tarjeta",cardError:"Error en el formulario de tarjeta",failedToMount3DS:"Error al montar autenticación 3D Secure",threeDSecureError:"Error en la autenticación 3D Secure",threeDSecureFailed:"La autenticación 3D Secure falló",threeDSecureSessionRequired:"Se requiere el ID de sesión 3D Secure"}}};function i(e="pt"){return n[e]}const a={sandbox:"https://api-sandbox.rinne.com.br/core/v1",production:"https://api.rinne.com.br/core/v1"};function s(e){return String(e).padStart(2,"0")}function c(e){const r=String(e);return 2===r.length?`20${r}`:r}function l(e,r,o){const t=(e.card.funding??"credit").toLowerCase(),n="APPLE_PAY"===o?function(e){const{networkToken:r,card:o,cryptogram:t,eci:n,paymentDataType:i,deviceManufacturerIdentifier:a}=e;return{network_token:r.number,expiry_month:s(r.expiry.month),expiry_year:c(r.expiry.year),cryptogram:t,eci:n,token_provider:r.tokenServiceProvider,brand:o.brand,device_id:a,authentication_type:"3DSecure"===i?"3DS":void 0,last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"APPLE_PAY",display_name:o.displayName}}(e):function(e){if(!function(e){return"token"in e&&"tokenServiceProvider"in e.token}(e))throw new Error("Google Pay response must contain a network token (3DS authentication)");const{token:r,card:o,cryptogram:t,eci:n}=e;return{network_token:r.number,expiry_month:s(r.expiry.month),expiry_year:c(r.expiry.year),cryptogram:t,eci:n??null,token_provider:r.tokenServiceProvider,brand:o.brand,authentication_type:"3DS",last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"GOOGLE_PAY",display_name:o.displayName}}(e);return{card_data:n,payment_method:"debit"===t?"DEBIT_CARD":"CREDIT_CARD",transaction:r}}function u(e){if(void 0!==e)return 0===e?"0":e}function d(e){return{pt:"pt-BR",en:"en-US",es:"es-ES"}[e]}function m(e,r="pt"){if("string"==typeof e){const o=document.querySelector(e);if(!o){const o=i(r).errors.targetElementNotFound;throw new Error(`${o}: ${e}`)}return o}return e}function p(e,r,o){return{code:e,message:r,details:o}}function h(e){if(!e)return{};const r=e;return{number:r.number,expiry:r.expiry,cvc:r.cvc,name:r.name}}function f(e){return{isValid:e.isValid,isComplete:e.isComplete,errors:h(e.errors)}}function y(e,r,o){const n={};void 0!==r.icons&&(n.icons=r.icons),r.fields&&(n.fields=r.fields);const i=function(e,r){if("function"==typeof r)return r;const{preset:o,customStyles:t,customFonts:n}=function(e){return"string"==typeof e?{preset:e}:{preset:e?.preset??"material",customStyles:e?.styles,customFonts:e?.fonts}}(r),i=e[o];if(i){if(t||n){const e={};return t&&(e.styles=t),n&&(e.fonts=n),i(e)}return i()}}(e,r.theme);return void 0!==i&&(n.theme=i),n.translations=function(e="pt"){return t[e]}(o),n}function v(e,r){return{field:e,state:r}}e.Rinne=class{constructor(e){this.options=e,this.transaction=this.createTransactionNamespace(),this.elements=this.createElementsNamespace()}config=null;evervault=null;initPromise=null;transaction;elements;async initialize(){return this.initPromise||(this.initPromise=(async()=>{try{const e=await async function(e){const r=i("pt"),o=`${e.baseUrl??a[e.environment??"production"]}/merchants/${e.merchantId}/public-settings`;try{const e=await fetch(o);if(!e.ok){const o=String(e.status);throw new Error(`${r.errors.failedToFetchConfig}: ${o} ${e.statusText}`)}const t=await e.json();if(!t.merchant_id||!t.team_id||!t.app_id)throw new Error(r.errors.invalidConfig);return{merchantId:t.merchant_id,teamId:t.team_id,appId:t.app_id,availableMethods:t.available_methods,name:t.name}}catch(t){if(t instanceof Error)throw new Error(`${r.errors.configFetchFailed}: ${t.message}`);throw new Error(`${r.errors.configFetchFailed}: ${r.errors.unknownError}`)}}({merchantId:this.options.merchantId,environment:this.options.environment??"production",baseUrl:this.options.rinneUrl});this.config=e,this.evervault=await async function(e,r,t){return new(await o())(e,r,t)}(this.config.teamId,this.config.appId)}catch(e){throw this.initPromise=null,e}})()),this.initPromise}createElementsNamespace(){return{applePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=i(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,n=!1;const a=r.button?.locale??"pt",s=i(a),c=r.button?.size??{width:"100%",height:"40px"},{width:h,height:f}=c,y={locale:d(r.button?.locale??"pt"),type:(g=r.button?.type??"plain",{book:"book",buy:"buy",checkout:"check-out",donate:"donate",order:"order",pay:"pay",plain:"plain",subscribe:"subscribe"}[g]),style:(v=r.button?.color??"black","white"===v?"white-outline":v),borderRadius:u(r.button?.borderRadius),...!!h&&!!f&&{size:{width:h,height:f}},process:async(t,i)=>{if(n||o)return Promise.resolve();try{o=!0;const a=l(t,e,"APPLE_PAY");let s=!1;const c=e=>{s=!0,i.fail(e)};return await(r.onCapture?.(a,c)),void(s||(n=!0))}catch(a){return i.fail({message:a instanceof Error?a.message:s.errors.failedToProcessApplePay}),Promise.resolve()}finally{n||(o=!1)}}};var v,g;const E=t.ui.applePay(e,y);return E.on("error",(...e)=>{if(o)return;o=!0;const t="string"==typeof e[0]?e[0]:void 0;if("CANCELLED"===t?.toUpperCase())return o=!1,void r.onCancel?.();const n={code:"PROVIDER_ERROR",message:t??s.errors.applePayError};r.onError?.(n)}),E.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({async mount(e){try{const r=m(e,a);return await E.mount(r),{unmount:()=>{E.unmount()}}}catch(o){const e=p("PROVIDER_ERROR",o instanceof Error?o.message:s.errors.failedToMountApplePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},googlePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=i(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,n=!1;const a=r.button?.locale??"pt",s=i(a),c=r.button?.size??{width:"100%",height:"40px"},{width:d,height:h}=c,f={locale:r.button?.locale??"pt",type:r.button?.type??"plain",color:r.button?.color??"black",borderRadius:u(r.button?.borderRadius),...!!d&&!!h&&{size:{width:d,height:h}},allowedAuthMethods:["CRYPTOGRAM_3DS"],process:async(t,i)=>{if(n||o)return Promise.resolve();try{o=!0;const a=l(t,e,"GOOGLE_PAY");let s=!1;const c=e=>{s=!0,i.fail(e)};return await(r.onCapture?.(a,c)),void(s||(n=!0))}catch(a){return i.fail({message:a instanceof Error?a.message:s.errors.failedToProcessGooglePay}),Promise.resolve()}finally{n||(o=!1)}}},y=t.ui.googlePay(e,f);return y.on("error",(...e)=>{if(o)return;o=!0;const t={code:"PROVIDER_ERROR",message:("string"==typeof e[0]?e[0]:void 0)??s.errors.googlePayError};r.onError?.(t)}),y.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({mount(e){try{const r=m(e,a);return y.mount(r),Promise.resolve({unmount:()=>{y.unmount()}})}catch(o){const e=p("PROVIDER_ERROR",o instanceof Error?o.message:s.errors.failedToMountGooglePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},card:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=i(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=i(r);let n={isValid:!1,isComplete:!1,errors:{}},a={card:{number:"",cvc:"",expiry:{month:"",year:""}}};const s=y(o.ui.themes,e,r),c=o.ui.card(s);return e.onReady&&c.on("ready",e.onReady),c.on("change",r=>{var o;n=f(r),o=r.card,a={card:{number:o.number??"",cvc:o.cvc??"",expiry:{month:o.expiry.month??"",year:o.expiry.year??""},name:o.name??void 0,brand:o.brand??void 0,lastFour:o.lastFour??void 0}},e.onChange?.(n)}),e.onComplete&&c.on("complete",r=>{e.onComplete?.(f(r))}),e.onFocus&&c.on("focus",r=>{e.onFocus?.(v(r.field,f(r.data)))}),e.onBlur&&c.on("blur",r=>{e.onBlur?.(v(r.field,f(r.data)))}),Promise.resolve({async mount(e){try{const o=m(e,r);return await Promise.resolve(c.mount(o)),{get values(){return a},get isComplete(){return n.isComplete},get isValid(){return n.isValid},unmount(){c.unmount()}}}catch(o){const e=p("PROVIDER_ERROR",o instanceof Error?o.message:t.errors.failedToMountCard,o);throw new Error(e.message,{cause:e})}}})});var o;return r(e)},threeDSecure:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=i(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=i(r),n=e.target,a=function(e){const r={};if(e.size&&(r.size=e.size),e.theme)if("function"==typeof e.theme)r.theme=e.theme;else{const o="string"==typeof e.theme?e.theme:e.theme.preset;o&&(r.theme=o)}return r}(e);let s=null;return Promise.resolve({async mount(i){const c=i.trim();if(!c)throw new Error(t.errors.threeDSecureSessionRequired);!function(e){if(e)try{e.unmount()}catch{}}(s),s=null;try{const t=o.ui.threeDSecure(c,a);if(s=t,function(e,r){r.onReady&&e.on("ready",r.onReady),r.onSuccess&&e.on("success",r.onSuccess),r.onFailure&&e.on("failure",e=>{r.onFailure?.(e)}),r.onError&&e.on("error",e=>{r.onError?.(e)})}(t,e),n){const e=m(n,r);await Promise.resolve(t.mount(e))}else await Promise.resolve(t.mount());return{unmount(){t.unmount(),s===t&&(s=null)}}}catch(l){const e=p("PROVIDER_ERROR",l instanceof Error?l.message:t.errors.failedToMount3DS,l);throw new Error(e.message,{cause:e})}}})});var o;return r(e)}}}createTransactionNamespace(){return{create:async e=>{if(await this.initialize(),!this.evervault||!this.config?.merchantId){const e=i("pt");throw new Error(e.errors.failedToInitialize)}return this.evervault.transactions.create({type:"payment",...e,country:e.country??"BR",currency:e.currency??"BRL",merchantId:this.config.merchantId,priceLabel:this.config.name})}}}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}),"undefined"!=typeof window&&window.Rinne&&window.Rinne.Rinne&&(window.Rinne=window.Rinne.Rinne);
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).Rinne={})}(this,function(e){"use strict";let r=null;async function o(){if(window.Evervault)return window.Evervault;try{return await async function(){return r||(r=new Promise((e,o)=>{const t=document.createElement("script");if(t.src="https://js.evervault.com/v2",t.onload=()=>e(),t.onerror=()=>{r=null,o()},!document.head)throw new Error("Expected document.head not to be null. Evervault.js requires a <head> element.");document.head.appendChild(t)}),r)}(),window.Evervault}catch{throw new Error("Failed to load Evervault.js")}}Promise.resolve().then(()=>{o()});const t={pt:{name:{label:"Nome no cartão",placeholder:"Nome completo",errors:{invalid:"Nome inválido"}},number:{label:"Número do cartão",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de cartão inválido"}},expiry:{label:"Validade",placeholder:"MM/AA",errors:{invalid:"Data de validade inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}},en:{name:{label:"Name on card",placeholder:"Full name",errors:{invalid:"Invalid name"}},number:{label:"Card number",placeholder:"1234 5678 9012 3456",errors:{invalid:"Invalid card number"}},expiry:{label:"Expiry",placeholder:"MM/YY",errors:{invalid:"Invalid expiry date"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"Invalid CVC"}}},es:{name:{label:"Nombre en la tarjeta",placeholder:"Nombre completo",errors:{invalid:"Nombre inválido"}},number:{label:"Número de tarjeta",placeholder:"1234 5678 9012 3456",errors:{invalid:"Número de tarjeta inválido"}},expiry:{label:"Vencimiento",placeholder:"MM/AA",errors:{invalid:"Fecha de vencimiento inválida"}},cvc:{label:"CVC",placeholder:"123",errors:{invalid:"CVC inválido"}}}},n={pt:{errors:{targetElementNotFound:"Elemento alvo não encontrado",failedToInitialize:"Falha ao inicializar Rinne SDK",failedToProcessApplePay:"Falha ao processar dados do Apple Pay",failedToProcessGooglePay:"Falha ao processar dados do Google Pay",applePayError:"Erro do Apple Pay",googlePayError:"Erro do Google Pay",failedToMountApplePay:"Falha ao montar botão do Apple Pay",failedToMountGooglePay:"Falha ao montar botão do Google Pay",failedToFetchConfig:"Falha ao buscar configuração do comerciante",invalidConfig:"Configuração de comerciante inválida: campos obrigatórios ausentes",configFetchFailed:"Falha ao buscar configuração",unknownError:"Erro desconhecido",failedToMountCard:"Falha ao montar formulário de cartão",cardError:"Erro no formulário de cartão",failedToMount3DS:"Falha ao montar autenticação 3D Secure",threeDSecureError:"Erro na autenticação 3D Secure",threeDSecureFailed:"Autenticação 3D Secure falhou",threeDSecureSessionRequired:"ID da sessão 3D Secure é obrigatório"}},en:{errors:{targetElementNotFound:"Target element not found",failedToInitialize:"Failed to initialize Rinne SDK",failedToProcessApplePay:"Failed to process Apple Pay data",failedToProcessGooglePay:"Failed to process Google Pay data",applePayError:"Apple Pay error occurred",googlePayError:"Google Pay error occurred",failedToMountApplePay:"Failed to mount Apple Pay button",failedToMountGooglePay:"Failed to mount Google Pay button",failedToFetchConfig:"Failed to fetch merchant config",invalidConfig:"Invalid merchant config: missing required fields",configFetchFailed:"Configuration fetch failed",unknownError:"Unknown error",failedToMountCard:"Failed to mount card form",cardError:"Card form error",failedToMount3DS:"Failed to mount 3D Secure authentication",threeDSecureError:"3D Secure authentication error",threeDSecureFailed:"3D Secure authentication failed",threeDSecureSessionRequired:"3D Secure session ID is required"}},es:{errors:{targetElementNotFound:"Elemento objetivo no encontrado",failedToInitialize:"Error al inicializar Rinne SDK",failedToProcessApplePay:"Error al procesar datos de Apple Pay",failedToProcessGooglePay:"Error al procesar datos de Google Pay",applePayError:"Error de Apple Pay",googlePayError:"Error de Google Pay",failedToMountApplePay:"Error al montar botón de Apple Pay",failedToMountGooglePay:"Error al montar botón de Google Pay",failedToFetchConfig:"Error al obtener configuración del comerciante",invalidConfig:"Configuración de comerciante inválida: faltan campos requeridos",configFetchFailed:"Error al obtener configuración",unknownError:"Error desconocido",failedToMountCard:"Error al montar formulario de tarjeta",cardError:"Error en el formulario de tarjeta",failedToMount3DS:"Error al montar autenticación 3D Secure",threeDSecureError:"Error en la autenticación 3D Secure",threeDSecureFailed:"La autenticación 3D Secure falló",threeDSecureSessionRequired:"Se requiere el ID de sesión 3D Secure"}}};function i(e="pt"){return n[e]}const a={sandbox:"https://api-sandbox.rinne.com.br/core/v1",production:"https://api.rinne.com.br/core/v1"};function c(e){return String(e).padStart(2,"0")}function s(e){const r=String(e);return 2===r.length?`20${r}`:r}function l(e,r,o){const t=(e.card.funding??"credit").toLowerCase(),n="APPLE_PAY"===o?function(e){const{networkToken:r,card:o,cryptogram:t,eci:n,paymentDataType:i,deviceManufacturerIdentifier:a}=e;return{network_token:r.number,expiry_month:c(r.expiry.month),expiry_year:s(r.expiry.year),cryptogram:t,eci:n,token_provider:r.tokenServiceProvider,brand:o.brand,device_id:a,authentication_type:"3DSecure"===i?"3DS":void 0,last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"APPLE_PAY",display_name:o.displayName}}(e):function(e){if(!function(e){return"token"in e&&"tokenServiceProvider"in e.token}(e))throw new Error("Google Pay response must contain a network token (3DS authentication)");const{token:r,card:o,cryptogram:t,eci:n}=e;return{network_token:r.number,expiry_month:c(r.expiry.month),expiry_year:s(r.expiry.year),cryptogram:t,eci:n??null,token_provider:r.tokenServiceProvider,brand:o.brand,authentication_type:"3DS",last_digits:o.lastFour,issuer:"issuer"in o?o.issuer:void 0,segment:"segment"in o?o.segment:void 0,country:"country"in o?o.country:void 0,wallet_type:"GOOGLE_PAY",display_name:o.displayName}}(e);return{card_data:n,payment_method:"debit"===t?"DEBIT_CARD":"CREDIT_CARD",transaction:r}}function u(e){if(void 0!==e)return 0===e?"0":e}function d(e){return{pt:"pt-BR",en:"en-US",es:"es-ES"}[e]}function m(e,r="pt"){if("string"==typeof e){const o=document.querySelector(e);if(!o){const o=i(r).errors.targetElementNotFound;throw new Error(`${o}: ${e}`)}return o}return e}function h(e,r,o){return{code:e,message:r,details:o}}function p(e){if(!e)return{};const r=e;return{number:r.number,expiry:r.expiry,cvc:r.cvc,name:r.name}}function f(e){return{isValid:e.isValid,isComplete:e.isComplete,errors:p(e.errors)}}function y(e,r,o){const n={};void 0!==r.icons&&(n.icons=r.icons),r.fields&&(n.fields=r.fields);const i=function(e,r){if("function"==typeof r)return r;const{preset:o,customStyles:t,customFonts:n}=function(e){return"string"==typeof e?{preset:e}:{preset:e?.preset??"material",customStyles:e?.styles,customFonts:e?.fonts}}(r),i=e[o];if(i){if(t||n){const e={};return t&&(e.styles=t),n&&(e.fonts=n),i(e)}return i()}}(e,r.theme);return void 0!==i&&(n.theme=i),void 0!==r.colorScheme&&(n.colorScheme=r.colorScheme),n.translations=function(e="pt"){return t[e]}(o),n}function v(e,r){return{field:e,state:r}}e.Rinne=class{constructor(e){this.options=e,this.transaction=this.createTransactionNamespace(),this.elements=this.createElementsNamespace()}config=null;evervault=null;initPromise=null;transaction;elements;async initialize(){return this.initPromise||(this.initPromise=(async()=>{try{const e=await async function(e){const r=i("pt"),o=`${e.baseUrl??a[e.environment??"production"]}/merchants/${e.merchantId}/public-settings`;try{const e=await fetch(o);if(!e.ok){const o=String(e.status);throw new Error(`${r.errors.failedToFetchConfig}: ${o} ${e.statusText}`)}const t=await e.json();if(!t.merchant_id||!t.team_id||!t.app_id)throw new Error(r.errors.invalidConfig);return{merchantId:t.merchant_id,teamId:t.team_id,appId:t.app_id,availableMethods:t.available_methods,name:t.name}}catch(t){if(t instanceof Error)throw new Error(`${r.errors.configFetchFailed}: ${t.message}`);throw new Error(`${r.errors.configFetchFailed}: ${r.errors.unknownError}`)}}({merchantId:this.options.merchantId,environment:this.options.environment??"production",baseUrl:this.options.rinneUrl});this.config=e,this.evervault=await async function(e,r,t){return new(await o())(e,r,t)}(this.config.teamId,this.config.appId)}catch(e){throw this.initPromise=null,e}})()),this.initPromise}createElementsNamespace(){return{applePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=i(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,n=!1;const a=r.button?.locale??"pt",c=i(a),s=r.button?.size??{width:"100%",height:"40px"},{width:p,height:f}=s,y={locale:d(r.button?.locale??"pt"),type:(g=r.button?.type??"plain",{book:"book",buy:"buy",checkout:"check-out",donate:"donate",order:"order",pay:"pay",plain:"plain",subscribe:"subscribe"}[g]),style:(v=r.button?.color??"black","white"===v?"white-outline":v),borderRadius:u(r.button?.borderRadius),...!!p&&!!f&&{size:{width:p,height:f}},process:async(t,i)=>{if(n||o)return Promise.resolve();try{o=!0;const a=l(t,e,"APPLE_PAY");let c=!1;const s=e=>{c=!0,i.fail(e)};return await(r.onCapture?.(a,s)),void(c||(n=!0))}catch(a){return i.fail({message:a instanceof Error?a.message:c.errors.failedToProcessApplePay}),Promise.resolve()}finally{n||(o=!1)}}};var v,g;const E=t.ui.applePay(e,y);return E.on("error",(...e)=>{if(o)return;o=!0;const t="string"==typeof e[0]?e[0]:void 0;if("CANCELLED"===t?.toUpperCase())return o=!1,void r.onCancel?.();const n={code:"PROVIDER_ERROR",message:t??c.errors.applePayError};r.onError?.(n)}),E.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({async mount(e){try{const r=m(e,a);return await E.mount(r),{unmount:()=>{E.unmount()}}}catch(o){const e=h("PROVIDER_ERROR",o instanceof Error?o.message:c.errors.failedToMountApplePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},googlePay:async(e,r)=>{if(await this.initialize(),!this.evervault||!this.config){const e=i(r.button?.locale??"pt");throw new Error(e.errors.failedToInitialize)}const o=(t=this.evervault,this.config,(e,r)=>{let o=!1,n=!1;const a=r.button?.locale??"pt",c=i(a),s=r.button?.size??{width:"100%",height:"40px"},{width:d,height:p}=s,f={locale:r.button?.locale??"pt",type:r.button?.type??"plain",color:r.button?.color??"black",borderRadius:u(r.button?.borderRadius),...!!d&&!!p&&{size:{width:d,height:p}},...r.colorScheme&&{colorScheme:r.colorScheme},allowedAuthMethods:["CRYPTOGRAM_3DS"],process:async(t,i)=>{if(n||o)return Promise.resolve();try{o=!0;const a=l(t,e,"GOOGLE_PAY");let c=!1;const s=e=>{c=!0,i.fail(e)};return await(r.onCapture?.(a,s)),void(c||(n=!0))}catch(a){return i.fail({message:a instanceof Error?a.message:c.errors.failedToProcessGooglePay}),Promise.resolve()}finally{n||(o=!1)}}},y=t.ui.googlePay(e,f);return y.on("error",(...e)=>{if(o)return;o=!0;const t={code:"PROVIDER_ERROR",message:("string"==typeof e[0]?e[0]:void 0)??c.errors.googlePayError};r.onError?.(t)}),y.on("cancel",()=>{o=!1,r.onCancel?.()}),Promise.resolve({mount(e){try{const r=m(e,a);return y.mount(r),Promise.resolve({unmount:()=>{y.unmount()}})}catch(o){const e=h("PROVIDER_ERROR",o instanceof Error?o.message:c.errors.failedToMountGooglePay,o);throw r.onError&&r.onError(e),o}}})});var t;return o(e,r)},card:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=i(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=i(r);let n={isValid:!1,isComplete:!1,errors:{}},a={card:{number:"",cvc:"",expiry:{month:"",year:""}}};const c=y(o.ui.themes,e,r),s=o.ui.card(c);return e.onReady&&s.on("ready",e.onReady),s.on("change",r=>{var o;n=f(r),o=r.card,a={card:{number:o.number??"",cvc:o.cvc??"",expiry:{month:o.expiry.month??"",year:o.expiry.year??""},name:o.name??void 0,brand:o.brand??void 0,lastFour:o.lastFour??void 0}},e.onChange?.(n)}),e.onComplete&&s.on("complete",r=>{e.onComplete?.(f(r))}),e.onFocus&&s.on("focus",r=>{e.onFocus?.(v(r.field,f(r.data)))}),e.onBlur&&s.on("blur",r=>{e.onBlur?.(v(r.field,f(r.data)))}),Promise.resolve({async mount(e){try{const o=m(e,r);return await Promise.resolve(s.mount(o)),{get values(){return a},get isComplete(){return n.isComplete},get isValid(){return n.isValid},unmount(){s.unmount()}}}catch(o){const e=h("PROVIDER_ERROR",o instanceof Error?o.message:t.errors.failedToMountCard,o);throw new Error(e.message,{cause:e})}}})});var o;return r(e)},threeDSecure:async(e={})=>{if(await this.initialize(),!this.evervault||!this.config){const r=i(e.locale??"pt");throw new Error(r.errors.failedToInitialize)}const r=(o=this.evervault,(e={})=>{const r=e.locale??"pt",t=i(r),n=e.target,a=function(e){const r={};if(e.size&&(r.size=e.size),void 0!==e.colorScheme&&(r.colorScheme=e.colorScheme),e.theme)if("function"==typeof e.theme)r.theme=e.theme;else{const o="string"==typeof e.theme?e.theme:e.theme.preset;o&&(r.theme=o)}return r}(e);let c=null;return Promise.resolve({async mount(i){const s=i.trim();if(!s)throw new Error(t.errors.threeDSecureSessionRequired);!function(e){if(e)try{e.unmount()}catch{}}(c),c=null;try{const t=o.ui.threeDSecure(s,a);if(c=t,function(e,r){r.onReady&&e.on("ready",r.onReady),r.onSuccess&&e.on("success",r.onSuccess),r.onFailure&&e.on("failure",e=>{r.onFailure?.(e)}),r.onError&&e.on("error",e=>{r.onError?.(e)})}(t,e),n){const e=m(n,r);await Promise.resolve(t.mount(e))}else await Promise.resolve(t.mount());return{unmount(){t.unmount(),c===t&&(c=null)}}}catch(l){const e=h("PROVIDER_ERROR",l instanceof Error?l.message:t.errors.failedToMount3DS,l);throw new Error(e.message,{cause:e})}}})});var o;return r(e)}}}createTransactionNamespace(){return{create:async e=>{if(await this.initialize(),!this.evervault||!this.config?.merchantId){const e=i("pt");throw new Error(e.errors.failedToInitialize)}return this.evervault.transactions.create({type:"payment",...e,country:e.country??"BR",currency:e.currency??"BRL",merchantId:this.config.merchantId,priceLabel:this.config.name})}}}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}),"undefined"!=typeof window&&window.Rinne&&window.Rinne.Rinne&&(window.Rinne=window.Rinne.Rinne);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rinnebr/js",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.19",
|
|
4
4
|
"description": "Modern payment elements library for Apple Pay, Google Pay, and other payment methods",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "yarn@4.9.1",
|
|
@@ -75,6 +75,6 @@
|
|
|
75
75
|
"vitest": "^4.0.8"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@evervault/js": "^2.
|
|
78
|
+
"@evervault/js": "^2.9.1"
|
|
79
79
|
}
|
|
80
80
|
}
|