@payrails/web-sdk 1.1.6
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/index.js +1 -0
- package/package.json +14 -0
- package/payrails-styles.css +349 -0
- package/payrails.d.ts +434 -0
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const DEFAULT_ELEMENT_CONFIG={table:"cards",labelStyles:{},errorTextStyles:{}};var ElementType;exports.ElementType=void 0,(ElementType=exports.ElementType||(exports.ElementType={})).CARD_NUMBER="CARD_NUMBER",ElementType.CARDHOLDER_NAME="CARDHOLDER_NAME",ElementType.CVV="CVV",ElementType.EXPIRATION_MONTH="EXPIRATION_MONTH",ElementType.EXPIRATION_YEAR="EXPIRATION_YEAR";class PayrailsElement{constructor(elementType,{id:id="",className:className=""}={}){this.subElements=[];const el=document.createElement(elementType);id&&(this.id=id,el.setAttribute("id",id)),className&&el.setAttribute("class",className),this.element=el}get parentElement(){return this.element.parentElement}mount(location){const parent=document.querySelector(location);if(!parent)throw new Error(`Element with selector "${location}" not found in in the DOM`);parent.appendChild(this.element),this.subElements.forEach((el=>{if(!this.id)throw new Error("Sub elements can not be rendered, please set id for the element");el.mount(`#${this.id}`)}))}unmount(){var _a;this.subElements.forEach((i=>i.unmount())),null===(_a=this.parentElement)||void 0===_a||_a.removeChild(this.element)}}const{CARD_NUMBER:CARD_NUMBER,CVV:CVV,CARDHOLDER_NAME:CARDHOLDER_NAME,EXPIRATION_MONTH:EXPIRATION_MONTH,EXPIRATION_YEAR:EXPIRATION_YEAR}=exports.ElementType,INPUT_STYLES={base:{border:"none",padding:"10px 16px",color:"#1d1d1d",backgroundColor:"#fff"},invalid:{backgroundColor:"#f9e1e1",borderColor:"#f25226",border:"1px solid"}},FORM_FIELDS=[{type:CARDHOLDER_NAME,placeholder:"Card holder",styles:Object.assign(Object.assign({},INPUT_STYLES),{base:Object.assign(Object.assign({},INPUT_STYLES.base),{border:"1px solid #eae8ee",padding:"10px 16px",borderTopLeftRadius:"4px",borderTopRightRadius:"4px"})})},{type:CARD_NUMBER,placeholder:"1234 1234 1234 1234",styles:Object.assign(Object.assign({},INPUT_STYLES),{base:Object.assign(Object.assign({},INPUT_STYLES.base),{border:"1px solid #eae8ee",padding:"10px 16px",borderTopLeftRadius:"4px",borderTopRightRadius:"4px",textIndent:"0"}),cardIcon:{position:"absolute",right:"8px",height:"24px",bottom:"calc(50% - 12px)"}})},{type:EXPIRATION_MONTH,placeholder:"MM",styles:Object.assign(Object.assign({},INPUT_STYLES),{base:Object.assign(Object.assign({},INPUT_STYLES.base),{borderBottom:"1px solid #eae8ee",borderLeft:"1px solid #eae8ee",borderRight:"1px solid #eae8ee",borderBottomLeftRadius:"4px"})})},{type:EXPIRATION_YEAR,placeholder:"YY",format:"YY",styles:Object.assign(Object.assign({},INPUT_STYLES),{base:Object.assign(Object.assign({},INPUT_STYLES.base),{borderBottom:"1px solid #eae8ee",borderRight:"1px solid #eae8ee"})})},{type:CVV,placeholder:"CVC",styles:Object.assign(Object.assign({},INPUT_STYLES),{base:Object.assign(Object.assign({},INPUT_STYLES.base),{borderBottom:"1px solid #eae8ee",borderRight:"1px solid #eae8ee",borderBottomRightRadius:"4px"})})}];class CardForm extends PayrailsElement{constructor(collectContainer,options){var _a,_b,_c,_d,_e,_f;super("div",{id:"payrails-card-form"}),this.collectContainer=collectContainer,this.options=options,this.storeCardCheckbox=null,this.formFields=[],FORM_FIELDS.forEach((({type:type,styles:styles,format:format,placeholder:placeholder,label:label})=>{var _a,_b,_c,_d,_e;if(!(null===(_a=this.options)||void 0===_a?void 0:_a.showCardHolderName)&&type===exports.ElementType.CARDHOLDER_NAME)return;const inputStyles=this.prepareStyles(styles,type),el=new CardField(this.collectContainer,{type:type,label:label,placeholder:(null===(_c=null===(_b=null==options?void 0:options.translations)||void 0===_b?void 0:_b.placeholders)||void 0===_c?void 0:_c[type])||placeholder,inputStyles:inputStyles,format:format,events:{onFocus:null===(_e=null===(_d=this.options)||void 0===_d?void 0:_d.events)||void 0===_e?void 0:_e.onFocus,onChange:this.onChange.bind(this)}});this.formFields.push(el)})),this.subElements.push(this.collectContainer),(null===(_a=this.options)||void 0===_a?void 0:_a.showStoreInstrumentCheckbox)&&(this.storeCardCheckbox=new StoreCardCheckbox({label:null===(_d=null===(_c=null===(_b=this.options)||void 0===_b?void 0:_b.translations)||void 0===_c?void 0:_c.labels)||void 0===_d?void 0:_d.saveCreditCard,styles:null===(_f=null===(_e=this.options)||void 0===_e?void 0:_e.styles)||void 0===_f?void 0:_f.storeCardCheckbox}),this.subElements.push(this.storeCardCheckbox))}show(){this.element.style.display="flex"}hide(){this.element.style.display="none"}prepareStyles(styles,type){var _a;let inputStyles=JSON.parse(JSON.stringify(styles));return(null===(_a=this.options)||void 0===_a?void 0:_a.showCardHolderName)&&type===exports.ElementType.CARD_NUMBER&&(this.element.setAttribute("class","with-card-holder"),inputStyles=Object.assign(Object.assign({},styles),{base:Object.assign(Object.assign({},INPUT_STYLES.base),{border:"1px solid #eae8ee",borderTop:"none",padding:"10px 16px"})})),["base","complete","empty","focus","invalid","cardIcon","copyIcon"].forEach((key=>{var _a,_b,_c,_d,_e,_f,_g;inputStyles[key]=Object.assign(Object.assign(Object.assign({},inputStyles[key]),null===(_d=null===(_c=null===(_b=null===(_a=this.options)||void 0===_a?void 0:_a.styles)||void 0===_b?void 0:_b.inputFields)||void 0===_c?void 0:_c.all)||void 0===_d?void 0:_d[key]),null===(_g=null===(_f=null===(_e=this.options)||void 0===_e?void 0:_e.styles)||void 0===_f?void 0:_f.inputFields)||void 0===_g?void 0:_g[type])})),inputStyles}get isValid(){return this.formFields.reduce(((prev,curr)=>prev&&curr.isValid),!0)}onChange(){var _a,_b,_c,_d;(null===(_b=null===(_a=this.options)||void 0===_a?void 0:_a.events)||void 0===_b?void 0:_b.onChange)&&(null===(_d=null===(_c=this.options)||void 0===_c?void 0:_c.events)||void 0===_d||_d.onChange({isValid:this.isValid}))}async collectValues(){var _a,_b;return{tokenizedCardData:await this.collectContainer.collect(),storeInstrument:(null===(_a=this.storeCardCheckbox)||void 0===_a?void 0:_a.isChecked)||(null===(_b=this.options)||void 0===_b?void 0:_b.alwaysStoreInstrument)}}}class StoreCardCheckbox extends PayrailsElement{constructor(options){super("span",{id:"payrails-store-card"});const id="payrails-store-card-checkbox",label=(null==options?void 0:options.label)||"Save credit card for future payments";this.element.innerHTML=`<label for="${id}"}"><input type="checkbox" id="${id}" name="${id}" >${label}</label>`,Object.keys((null==options?void 0:options.styles)||{}).forEach((key=>{var _a;this.element.style[key]=null===(_a=null==options?void 0:options.styles)||void 0===_a?void 0:_a[key]})),this.element.addEventListener("change",(e=>{e.stopPropagation(),e.stopImmediatePropagation()}))}get isChecked(){var _a;return null===(_a=this.element.querySelector("input"))||void 0===_a?void 0:_a.checked}}class CardField{constructor(collectContainer,options){this.isValid=!1;const{type:type,label:label,placeholder:placeholder,inputStyles:inputStyles,events:events,format:format}=options,vaultElement=collectContainer.createCollectElement({type:type,label:label,placeholder:placeholder,format:format,inputStyles:inputStyles});(null==events?void 0:events.onFocus)&&vaultElement.on("FOCUS",events.onFocus),vaultElement.on("CHANGE",(e=>{const{isEmpty:isEmpty,isValid:isValid}=e;this.isValid=!isEmpty&&isValid,(null==events?void 0:events.onChange)&&events.onChange(this)}))}}class CardList extends PayrailsElement{constructor(workflowExecution,options){super("div",{id:"payrails-card-list"}),this.workflowExecution=workflowExecution,this.listItems=[],this.workflowExecution.savedCreditCards.forEach((cardData=>{const listItem=new ListItem((()=>{(null==options?void 0:options.onCardChange)&&options.onCardChange(cardData)}),cardData);this.listItems.push(listItem),this.subElements.push(listItem)}))}reset(){this.element.querySelectorAll("input").forEach((e=>e.checked=!1))}}class ListItem extends PayrailsElement{constructor(onClick,cardData){super("div",{className:"payrails-card-list-item",id:`payrails-card-list-item-${cardData.id}`});const{id:id}=cardData,labelText=this.createCardLabel(cardData),label=document.createElement("label");label.setAttribute("for",id),label.addEventListener("click",onClick);const input=document.createElement("input");input.setAttribute("type","radio"),input.setAttribute("name","payment-option"),input.setAttribute("id",id),input.setAttribute("value",id),label.appendChild(input);const text=document.createElement("span");text.innerText=labelText,label.appendChild(text),this.element.appendChild(label)}createCardLabel({data:{suffix:suffix}}){return`****${suffix}`}}let getRandomValues;const rnds8=new Uint8Array(16);function rng(){if(!getRandomValues&&(getRandomValues="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!getRandomValues))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return getRandomValues(rnds8)}const byteToHex=[];for(let i=0;i<256;++i)byteToHex.push((i+256).toString(16).slice(1));var RequestMethod,native={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function v4(options,buf,offset){if(native.randomUUID&&!buf&&!options)return native.randomUUID();const rnds=(options=options||{}).random||(options.rng||rng)();if(rnds[6]=15&rnds[6]|64,rnds[8]=63&rnds[8]|128,buf){offset=offset||0;for(let i=0;i<16;++i)buf[offset+i]=rnds[i];return buf}return function(arr,offset=0){return(byteToHex[arr[offset+0]]+byteToHex[arr[offset+1]]+byteToHex[arr[offset+2]]+byteToHex[arr[offset+3]]+"-"+byteToHex[arr[offset+4]]+byteToHex[arr[offset+5]]+"-"+byteToHex[arr[offset+6]]+byteToHex[arr[offset+7]]+"-"+byteToHex[arr[offset+8]]+byteToHex[arr[offset+9]]+"-"+byteToHex[arr[offset+10]]+byteToHex[arr[offset+11]]+byteToHex[arr[offset+12]]+byteToHex[arr[offset+13]]+byteToHex[arr[offset+14]]+byteToHex[arr[offset+15]]).toLowerCase()}(rnds)}!function(RequestMethod){RequestMethod.GET="GET",RequestMethod.POST="POST"}(RequestMethod||(RequestMethod={}));const payrailsFetch=async({url:url,method:method=RequestMethod.GET,token:token,body:body})=>{const reqInit={method:method,headers:Object.assign(Object.assign({},getIdempotencyHeader()),getAuthorizationHeader(token))};method===RequestMethod.POST&&(reqInit.body=JSON.stringify(body||{}));const req=await fetch(url,reqInit),res=await req.json();if([401,403].includes(req.status))throw new AuthorizationError(url,method);if(!req.ok)throw new UnsuccessfulError(url,method,res);return{ok:req.ok,req:Object.assign({url:url},reqInit),res:res}};class AuthorizationError extends Error{constructor(url,method){super(`[${method}] ${url} unauthorized`)}}class UnsuccessfulError extends Error{constructor(url,method,res){super(`[${method}] ${url} unsuccessful`),this.res=res}}const getAuthorizationHeader=token=>({authorization:`Bearer ${token}`}),getIdempotencyHeader=()=>({"x-idempotency-key":v4()});class PaymentExecutor{constructor(sdkConfig,execution){this.sdkConfig=sdkConfig,this.execution=execution}async pay(paymentComposition){const executionUrl=(await this.authorize(paymentComposition)).res.links.execution;return await this.pollForAuthorizationResult(executionUrl)}async authorize(paymentComposition){if(!this.execution.authorizeLink||!this.sdkConfig.amount)throw new Error("SDK was not initialized with workflow execution");return payrailsFetch({url:this.execution.authorizeLink,method:RequestMethod.POST,token:this.sdkConfig.token,body:{amount:this.sdkConfig.amount,paymentComposition:paymentComposition,returnInfo:{success:"https://www.bootstrap.payrails.io/success"}}})}async pollForAuthorizationResult(url){const execRes=(await this.getExecution(url)).res,statuses=execRes.status,finalStatuses=["authorizePending","authorizeSuccessful","authorizeFailed"],authorizeRequestedStatus=statuses.find((({code:code})=>"authorizeRequested"===code));if(!authorizeRequestedStatus)return await new Promise((resolve=>setTimeout(resolve,300))),this.pollForAuthorizationResult(url);let finalState=statuses.find((({code:code,time:time})=>finalStatuses.includes(code)&&new Date(time)>new Date(authorizeRequestedStatus.time)));if(!finalState){const{res:res}=await this.getExecution(url,void 0,authorizeRequestedStatus.time);return finalState=res.status.find((({code:code,time:time})=>finalStatuses.includes(code)&&new Date(time)>new Date(authorizeRequestedStatus.time))),{finalState:finalState,response:res}}return{finalState:finalState,response:execRes}}async getExecution(url,currentStatuses,statusTime){const pollParams=new URLSearchParams;currentStatuses&¤tStatuses.length>0&&pollParams.append("waitWhile[status]",`[${currentStatuses.map((i=>`"${i}"`)).join(",")}]`),statusTime&&pollParams.append("waitWhile[lastStatusTime]",statusTime);const pollUrl=`${url}${pollParams.toString()?"?":""}${pollParams.toString()}`;return payrailsFetch({url:pollUrl,token:this.sdkConfig.token})}}var PAYMENT_METHOD_CODES,PAYMENT_INSTRUMENT_STATUS;!function(PAYMENT_METHOD_CODES){PAYMENT_METHOD_CODES.CARD="card",PAYMENT_METHOD_CODES.GOOGLE_PAY="googlePay"}(PAYMENT_METHOD_CODES||(PAYMENT_METHOD_CODES={})),function(PAYMENT_INSTRUMENT_STATUS){PAYMENT_INSTRUMENT_STATUS.ENABLED="enabled",PAYMENT_INSTRUMENT_STATUS.CREATED="created"}(PAYMENT_INSTRUMENT_STATUS||(PAYMENT_INSTRUMENT_STATUS={}));class WorkflowExecution{constructor(executionResponse){this.executionResponse=executionResponse}get lookup(){return this.executionResponse.initialResults.find((({body:{name:name}})=>"lookup"===name))}get holderReference(){return this.executionResponse.holderReference}get savedCreditCards(){const cardPayment=this.availablePaymentMethods.find((({paymentMethodCode:paymentMethodCode})=>paymentMethodCode===PAYMENT_METHOD_CODES.CARD));return(null==cardPayment?void 0:cardPayment.paymentInstruments)||[]}get googlePayConfig(){const googlePay=this.availablePaymentMethods.find((({paymentMethodCode:paymentMethodCode})=>paymentMethodCode===PAYMENT_METHOD_CODES.GOOGLE_PAY));if(!googlePay)throw new Error("trying to initialize google pay without config");return googlePay?[googlePay.config]:[]}get url(){return this.response.links.self}get response(){return this.executionResponse}get meta(){return this.executionResponse.meta}get availablePaymentMethods(){var _a;return(null===(_a=this.lookup)||void 0===_a?void 0:_a.body.data.paymentCompositionOptions)||[]}get authorizeLink(){var _a;return null===(_a=this.lookup)||void 0===_a?void 0:_a.body.links.authorize.href}update(response){this.executionResponse=response}}class CardPaymentButton extends PayrailsElement{constructor(sdkConfig,execution,options){var _a;super("button",{id:"payrails-card-payment-button"}),this.sdkConfig=sdkConfig,this.execution=execution,this.options=options,this.selectedCard=null,this.storeInstrument=!1,this.element.innerText=(null===(_a=null==options?void 0:options.translations)||void 0===_a?void 0:_a.label)||"Pay",this.element.addEventListener("click",this.onPay.bind(this)),this.element.addEventListener("mouseenter",(()=>{var _a;this.element.classList.add("hover"),this.setStyles((null===(_a=this.options.styles)||void 0===_a?void 0:_a.hover)||{})})),this.element.addEventListener("mouseleave",(()=>{var _a;this.element.classList.remove("hover"),this.removeStyles((null===(_a=this.options.styles)||void 0===_a?void 0:_a.hover)||{})})),this.paymentExecutor=new PaymentExecutor(this.sdkConfig,this.execution)}setDisabled(isDisabled){var _a,_b,_c;this.element.disabled=isDisabled,isDisabled?(this.element.classList.add("disabled"),(null===(_a=this.options.styles)||void 0===_a?void 0:_a.disabled)&&this.setStyles(this.options.styles.disabled)):(this.element.classList.remove("disabled"),this.removeStyles((null===(_b=this.options.styles)||void 0===_b?void 0:_b.disabled)||{}),(null===(_c=this.options.styles)||void 0===_c?void 0:_c.base)&&this.setStyles(this.options.styles.base))}setStyles(styles){var _a;const stylesToApply=Object.assign(Object.assign({},null===(_a=this.options.styles)||void 0===_a?void 0:_a.base),styles);Object.keys(stylesToApply).forEach((key=>{this.element.style[key]=stylesToApply[key]}))}removeStyles(styles){var _a;const baseKeys=Object.keys((null===(_a=this.options.styles)||void 0===_a?void 0:_a.base)||{});Object.keys(styles).forEach((key=>{var _a,_b;baseKeys.includes(key)?this.element.style[key]=null===(_b=null===(_a=this.options.styles)||void 0===_a?void 0:_a.base)||void 0===_b?void 0:_b[key]:this.element.style[key]=""}))}setLabel(label){this.element.innerText=label}setCardForm(cardForm){this.cardForm=cardForm}triggerLoading(isLoading){var _a,_b,_c,_d;const elementWidth=this.element.offsetWidth;this.element.style.minWidth=`${elementWidth}px`,isLoading?(this.element.innerHTML='<div class="dot-flashing"></div>',this.element.classList.add("loading"),(null===(_a=this.options.styles)||void 0===_a?void 0:_a.loading)&&this.setStyles(this.options.styles.loading)):(this.element.innerText=(null===(_c=null===(_b=this.options)||void 0===_b?void 0:_b.translations)||void 0===_c?void 0:_c.label)||"Pay",this.element.classList.remove("loading"),this.removeStyles((null===(_d=this.options.styles)||void 0===_d?void 0:_d.loading)||{}))}onAuthorizationFailed(){var _a,_b;this.setDisabled(!1),this.triggerLoading(!1),(null===(_a=this.options.events)||void 0===_a?void 0:_a.onAuthorizeFailed)&&(null===(_b=this.options.events)||void 0===_b||_b.onAuthorizeFailed())}async onPay(){var _a,_b,_c,_d;if(this.setDisabled(!0),this.triggerLoading(!0),null===(_a=this.options.events)||void 0===_a?void 0:_a.onPaymentButtonClicked){if(!1===await(null===(_b=this.options.events)||void 0===_b?void 0:_b.onPaymentButtonClicked()))return void this.onAuthorizationFailed()}try{let instrumentId=null===(_c=this.selectedCard)||void 0===_c?void 0:_c.id;if(!instrumentId){instrumentId=(await this.tokenizeCard()).res.id}const paymentComposition=[{paymentMethodCode:PAYMENT_METHOD_CODES.CARD,integrationType:"api",amount:this.sdkConfig.amount,paymentInstrumentId:instrumentId,storeInstrument:this.storeInstrument}],authorizationResult=await this.paymentExecutor.pay(paymentComposition);this.handleAuthorizationResult(authorizationResult)}catch(error){error instanceof AuthorizationError&&(null===(_d=this.options.events)||void 0===_d?void 0:_d.onPaymentSessionExpired)&&this.options.events.onPaymentSessionExpired(),this.onAuthorizationFailed()}}handleAuthorizationResult(result){var _a,_b,_c;switch(null===(_a=null==result?void 0:result.finalState)||void 0===_a?void 0:_a.code){case"authorizeSuccessful":this.triggerLoading(!1),(null===(_b=this.options.events)||void 0===_b?void 0:_b.onAuthorizeSuccess)&&this.options.events.onAuthorizeSuccess();break;case"authorizePending":"3ds"===(null===(_c=null==result?void 0:result.response)||void 0===_c?void 0:_c.actionRequired)&&this.handle3ds(result);break;default:this.onAuthorizationFailed()}}handle3ds(authorizationResult){var _a,_b;const link=null===(_a=null==authorizationResult?void 0:authorizationResult.response)||void 0===_a?void 0:_a.links["3ds"];if(link){const availableSizes=[[250,400],[390,400],[500,600],[600,400]],screenWidth=screen.width,iframeSize=availableSizes.reduce(((prev,curr)=>screenWidth>curr[0]?curr:prev),[250,400]),iframe=document.createElement("iframe");iframe.setAttribute("id","payrails-3ds-frame"),iframe.setAttribute("src",link),iframe.setAttribute("width",iframeSize[0].toString()),iframe.setAttribute("height",iframeSize[1].toString());const popup=document.createElement("div");popup.setAttribute("id","payrails-3ds-challenge"),popup.appendChild(iframe);const popupBackground=document.createElement("div");popupBackground.addEventListener("click",(async()=>{popupBackground.remove()})),popupBackground.setAttribute("id","payrails-3ds-popup-background"),popupBackground.appendChild(popup);const handleMessages=async ev=>{var _a,_b,_c;if(ev.data&&'{"type":"3DS-challenge-completed"}'===ev.data){window.removeEventListener("message",handleMessages),popupBackground.remove();if(!(await this.paymentExecutor.getExecution(this.execution.url)).res.status.find((({code:code})=>"authorizeSuccessful"===code))&&(null===(_a=this.options.events)||void 0===_a?void 0:_a.onAuthorizeFailed))return void this.onAuthorizationFailed();if(null===(_b=this.options.events)||void 0===_b?void 0:_b.onAuthorizeSuccess)return void(null===(_c=this.options.events)||void 0===_c||_c.onAuthorizeSuccess())}};null===(_b=document.querySelector("body"))||void 0===_b||_b.appendChild(popupBackground),window.addEventListener("message",handleMessages),popup.style.width=`${iframeSize[0]+4}px`,popup.style.height=`${iframeSize[1]+4}px`}}async tokenizeCard(){if(!this.cardForm)throw new Error("Trying to tokenize non-existent card form");const{tokenizedCardData:tokenizedCardData,storeInstrument:storeInstrument}=await this.cardForm.collectValues();this.storeInstrument=Boolean(storeInstrument);const{instrumentId:instrumentId,card_number:card_number,cardholder_name:cardholder_name,expiry_month:expiry_month,expiry_year:expiry_year}=tokenizedCardData;return(({url:url,token:token,instrumentId:instrumentId,holderReference:holderReference,providerId:providerId,providerConfigId:providerConfigId,meta:meta,storeInstrument:storeInstrument=!1})=>payrailsFetch({url:url,token:token,method:RequestMethod.POST,body:{holderReference:holderReference,storeInstrument:storeInstrument,paymentMethod:"card",token:{providerId:providerId,providerConfigId:providerConfigId,reference:instrumentId,type:"vault",meta:meta}}}))({url:this.sdkConfig.vaultConfiguration.links.saveInstrument.href,token:this.sdkConfig.token,instrumentId:instrumentId,holderReference:this.execution.holderReference,providerId:this.sdkConfig.vaultConfiguration.providerId,providerConfigId:this.sdkConfig.vaultConfiguration.providerConfigId,meta:{skyflow_id:instrumentId,card_number:card_number,cardholder_name:cardholder_name,expiry_month:expiry_month,expiry_year:expiry_year},storeInstrument:this.storeInstrument})}}class AuthFailMsg extends PayrailsElement{constructor(label="Authorization failed, please try again."){super("div",{id:"authorization-failed-message"}),this.element.innerText=label,this.element.innerHTML=`\n <div>\n <svg class="checkmark-cross" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">\n <circle class="checkmark-cross_circle" cx="26" cy="26" r="25" fill="none"/>\n <path class="checkmark-cross_check" fill="none" d="M14.1 14.1l23.8 23.8 m0,-23.8 l-23.8,23.8"/>\n </svg>\n </div>\n <div>${label}</div>`,this.element.addEventListener("click",(e=>{e.stopImmediatePropagation(),e.stopPropagation(),this.unmount()}))}}class AuthSuccessMsg extends PayrailsElement{constructor(options){var _a;super("div",{id:"payrails-authorization-success-msg"}),this.element.innerHTML=`\n <div class="checkmark-wrapper">\n <svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">\n <circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>\n <path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>\n </svg>\n </div>\n <div id="payrails-authorization-success">${(null===(_a=null==options?void 0:options.translations)||void 0===_a?void 0:_a.label)||"Payment successful"}</div`}}class DropinElement extends PayrailsElement{constructor(id,label,events){super("div",{id:id,className:"payrails-dropin-item"}),this.events=events,this.isActive=!1;const checkboxId=`payrails-dropin-item-${id}`,labelEl=document.createElement("label");labelEl.setAttribute("for",checkboxId);const input=document.createElement("input");input.setAttribute("type","radio"),input.setAttribute("name","payment-option"),input.setAttribute("id",checkboxId),input.setAttribute("value",checkboxId),this.input=input,labelEl.appendChild(input),this.label=labelEl;const text=document.createElement("span");labelEl.appendChild(text),text.innerText=label,this.element.appendChild(labelEl)}get identifier(){return`payrails-dropin-item-${this.id}`}deactivate(){var _a,_b;this.isActive&&(this.isActive=!1,this.label.style.marginBottom="0",null===(_a=this.component)||void 0===_a||_a.unmount(),(null===(_b=this.events)||void 0===_b?void 0:_b.onDeactivate)&&this.events.onDeactivate())}activate(){var _a,_b;this.isActive||(null===(_a=this.component)||void 0===_a||_a.mount(`#${this.id}`),this.label.style.marginBottom="8px",this.isActive=!0,(null===(_b=this.events)||void 0===_b?void 0:_b.onActivate)&&this.events.onActivate())}}class CreditCardDropin extends DropinElement{constructor(cardForm,paymentButton){super("payrails-credit-card-wrapper","Card"),this.cardForm=cardForm,this.paymentButton=paymentButton,this.cardFormShown=!1,this.component=new CreditCardFormWrapper(cardForm,paymentButton)}activate(){var _a,_b;this.cardFormShown||(this.cardFormShown=!0,null===(_a=this.component)||void 0===_a||_a.mount(`#${this.id}`)),this.isActive||(this.paymentButton.selectedCard=null,this.paymentButton.mount(`#${this.id}`),this.paymentButton.setDisabled(!this.cardForm.isValid),this.paymentButton.mount("#payrails-card-form"),this.input.checked=!0,this.cardForm.show(),this.isActive=!0,(null===(_b=this.events)||void 0===_b?void 0:_b.onActivate)&&this.events.onActivate())}deactivate(){var _a;this.isActive&&(this.paymentButton.unmount(),this.cardForm.hide(),this.isActive=!1,(null===(_a=this.events)||void 0===_a?void 0:_a.onDeactivate)&&this.events.onDeactivate())}}class CreditCardFormWrapper extends PayrailsElement{constructor(cardForm,paymentButton){super("div",{id:"payrails-form-container"}),this.subElements.push(cardForm,paymentButton)}}const GPAY_BASE_REQUEST={apiVersion:2,apiVersionMinor:0};class GooglePayButton extends PayrailsElement{constructor(sdkConfig,execution,options){super("div",{id:"payrails-google-pay-button"}),this.sdkConfig=sdkConfig,this.execution=execution,this.options=options,this.client=null,this.googleButton=null,this.loadScript=null,this.paymentExecutor=new PaymentExecutor(sdkConfig,execution)}async sdkLoaded(){var _a,_b,_c,_d,_e,_f,_g,_h;this.client=new google.payments.api.PaymentsClient({environment:this.options.environment||"TEST"});try{const isReadyToPayRequest=Object.assign({},GPAY_BASE_REQUEST);if(isReadyToPayRequest.allowedPaymentMethods=this.execution.googlePayConfig,!this.client)throw new Error("Google pay client can not be initialized");const{result:result}=await this.client.isReadyToPay(isReadyToPayRequest);if(!result)return;const buttonColor=(null===(_b=null===(_a=this.options)||void 0===_a?void 0:_a.styles)||void 0===_b?void 0:_b.buttonColor)||"black",buttonType=(null===(_d=null===(_c=this.options)||void 0===_c?void 0:_c.styles)||void 0===_d?void 0:_d.buttonType)||"long",buttonSizeMode=(null===(_f=null===(_e=this.options)||void 0===_e?void 0:_e.styles)||void 0===_f?void 0:_f.buttonSizeMode)||"fill",buttonLocale=(null===(_h=null===(_g=this.options)||void 0===_g?void 0:_g.styles)||void 0===_h?void 0:_h.buttonLocale)||void 0;this.googleButton=this.client.createButton({buttonColor:buttonColor,buttonType:buttonType,buttonSizeMode:buttonSizeMode,buttonLocale:buttonLocale,onClick:async()=>{var _a,_b,_c;if(null===(_b=null===(_a=this.options)||void 0===_a?void 0:_a.events)||void 0===_b?void 0:_b.onPaymentButtonClicked){if(!await(null===(_c=this.options)||void 0===_c?void 0:_c.events.onPaymentButtonClicked()))return}this.onPaymentButtonClicked()},allowedPaymentMethods:this.execution.googlePayConfig}),this.element.appendChild(this.googleButton)}catch(e){throw console.error("Google pay can not be initialized",e),new Error(e.message)}}async onLoadPaymentData(data){var _a,_b,_c,_d;const paymentComposition=[{paymentMethodCode:"googlePay",integrationType:"api",paymentInstrumentData:{paymentToken:data.paymentMethodData.tokenizationData.token},amount:this.sdkConfig.amount}],result=await this.paymentExecutor.pay(paymentComposition);(null===(_b=null===(_a=this.options)||void 0===_a?void 0:_a.events)||void 0===_b?void 0:_b.onAuthorizeSuccess)&&(null===(_d=null===(_c=this.options)||void 0===_c?void 0:_c.events)||void 0===_d||_d.onAuthorizeSuccess(result))}async onPaymentButtonClicked(){var _a,_b,_c,_d,_e;const paymentDataRequest=Object.assign({},GPAY_BASE_REQUEST);if(paymentDataRequest.allowedPaymentMethods=this.execution.googlePayConfig,paymentDataRequest.transactionInfo={totalPriceStatus:"FINAL",totalPrice:null===(_a=this.sdkConfig.amount)||void 0===_a?void 0:_a.value,currencyCode:null===(_b=this.sdkConfig.amount)||void 0===_b?void 0:_b.currency,countryCode:null===(_e=null===(_d=null===(_c=this.execution.meta)||void 0===_c?void 0:_c.customer)||void 0===_d?void 0:_d.country)||void 0===_e?void 0:_e.code},!this.client)throw new Error("Google pay client is not initialized");this.client.loadPaymentData(paymentDataRequest).then((paymentData=>{this.onLoadPaymentData(paymentData)})).catch((err=>{var _a,_b,_c;(null===(_b=null===(_a=this.options)||void 0===_a?void 0:_a.events)||void 0===_b?void 0:_b.onAuthorizeFailed)&&(null===(_c=this.options)||void 0===_c||_c.events.onAuthorizeFailed(err))}))}mount(location){super.mount(location),this.loadScript?this.googleButton&&this.element.appendChild(this.googleButton):(this.loadScript=new LoadScript(this.sdkLoaded.bind(this)),this.loadScript.mount("body"))}unmount(){var _a;this.googleButton&&(null===(_a=this.googleButton.parentElement)||void 0===_a||_a.removeChild(this.googleButton)),super.unmount()}}class LoadScript extends PayrailsElement{constructor(onIsLoaded){super("script"),this.loaded=!1,this.loaded||(this.element.setAttribute("async","async"),this.element.setAttribute("src","https://pay.google.com/gp/p/js/pay.js"),this.element.setAttribute("onload","onPayrailsGpayLoaded()"),window.onPayrailsGpayLoaded=()=>{this.loaded||(this.loaded=!0,onIsLoaded())})}}class GooglePayDropin extends DropinElement{constructor(sdkConfig,workflowExecution,options){var _a;super("google-pay-dropin",(null===(_a=options.translations)||void 0===_a?void 0:_a.label)||"Google Pay"),this.component=new GooglePayButton(sdkConfig,workflowExecution,options)}}class SavedCard extends DropinElement{constructor(cardData,paymentButton,onActivate){super(`card-${cardData.id}`,`****${cardData.data.suffix}`,{onActivate:()=>{onActivate(cardData),this.component.setDisabled(!1)}}),this.component=paymentButton}}class Dropin extends PayrailsElement{constructor(collectContainer,dropinConfig,execution,sdkConfig){var _a,_b;super("fieldset",{id:"payrails-dropin-component"}),this.collectContainer=collectContainer,this.dropinConfig=dropinConfig,this.execution=execution,this.sdkConfig=sdkConfig;const savedCardsDisabled=!1===(null===(_b=null===(_a=this.dropinConfig.paymentMethodsConfiguration)||void 0===_a?void 0:_a.cards)||void 0===_b?void 0:_b.showExistingCards),availablePayments=new Map;this.execution.availablePaymentMethods.forEach((({paymentMethodCode:paymentMethodCode})=>{if(paymentMethodCode===PAYMENT_METHOD_CODES.CARD)savedCardsDisabled||this.execution.savedCreditCards.forEach((cardData=>{var _a;this.cardPaymentButton=this.createCardPaymentButton(null===(_a=this.dropinConfig.translations)||void 0===_a?void 0:_a.cardPaymentButton);const savedCard=new SavedCard(cardData,this.cardPaymentButton,(cardData=>{this.cardPaymentButton&&(this.cardPaymentButton.selectedCard=cardData)}));availablePayments.set(savedCard.identifier,savedCard)}))})),this.execution.availablePaymentMethods.forEach((({paymentMethodCode:paymentMethodCode})=>{var _a,_b;switch(paymentMethodCode){case PAYMENT_METHOD_CODES.CARD:this.creditCard=new CreditCardDropin(this.createCardForm(),this.createCardPaymentButton(null===(_a=this.dropinConfig.translations)||void 0===_a?void 0:_a.cardPaymentButton)),availablePayments.set(this.creditCard.identifier,this.creditCard);break;case PAYMENT_METHOD_CODES.GOOGLE_PAY:this.googlePay=new GooglePayDropin(this.sdkConfig,this.execution,{events:{onAuthorizeSuccess:result=>{var _a;if(result)if("authorizeSuccessful"===(null===(_a=null==result?void 0:result.finalState)||void 0===_a?void 0:_a.code))this.onAuthorizeSuccess();else this.onAuthorizeFailed()},onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onPaymentButtonClicked:this.dropinConfig.events.onPaymentButtonClicked},styles:null===(_b=this.dropinConfig.styles)||void 0===_b?void 0:_b.googlePayButton}),availablePayments.set(this.googlePay.identifier,this.googlePay)}})),this.element.addEventListener("change",(e=>{var _a,_b;const elementKey=(null===(_a=null==e?void 0:e.target)||void 0===_a?void 0:_a.value)||"";availablePayments.forEach((val=>{val.deactivate()})),null===(_b=availablePayments.get(elementKey))||void 0===_b||_b.activate()})),this.subElements.push(...Array.from(availablePayments.values()))}createCardForm(){var _a,_b;if(!this.cardForm){const cardConfig=null===(_a=this.dropinConfig.paymentMethodsConfiguration)||void 0===_a?void 0:_a.cards,showStoreInstrumentCheckbox=Boolean(null==cardConfig?void 0:cardConfig.showStoreInstrumentCheckbox),showCardHolderName=Boolean(null==cardConfig?void 0:cardConfig.showCardHolderName),alwaysStoreInstrument=Boolean(null==cardConfig?void 0:cardConfig.alwaysStoreInstrument);this.cardForm=new CardForm(this.collectContainer,{showStoreInstrumentCheckbox:showStoreInstrumentCheckbox,showCardHolderName:showCardHolderName,alwaysStoreInstrument:alwaysStoreInstrument,translations:null===(_b=this.dropinConfig.translations)||void 0===_b?void 0:_b.cardForm,events:{onFocus:()=>{var _a;null===(_a=this.creditCard)||void 0===_a||_a.activate()},onChange:({isValid:isValid})=>{var _a;null===(_a=this.cardPaymentButton)||void 0===_a||_a.setDisabled(!isValid)}}})}return this.cardPaymentButton&&this.cardPaymentButton.setCardForm(this.cardForm),this.cardForm}createCardPaymentButton(translations){return this.cardPaymentButton||(this.cardPaymentButton=new CardPaymentButton(this.sdkConfig,this.execution,{translations:translations,events:{onAuthorizeSuccess:this.onAuthorizeSuccess.bind(this),onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onPaymentButtonClicked:this.dropinConfig.events.onPaymentButtonClicked}})),this.cardForm&&this.cardPaymentButton.setCardForm(this.cardForm),this.cardPaymentButton}onAuthorizeSuccess(){var _a,_b,_c,_d;this.subElements.forEach((i=>i.unmount())),new AuthSuccessMsg({translations:{label:null===(_c=null===(_b=null===(_a=this.dropinConfig)||void 0===_a?void 0:_a.translations)||void 0===_b?void 0:_b.paymentResult)||void 0===_c?void 0:_c.success}}).mount(`#${this.id}`),(null===(_d=this.dropinConfig.events)||void 0===_d?void 0:_d.onAuthorizeSuccess)&&this.dropinConfig.events.onAuthorizeSuccess()}onAuthorizeFailed(){var _a,_b,_c;new AuthFailMsg(null===(_b=null===(_a=this.dropinConfig.translations)||void 0===_a?void 0:_a.paymentResult)||void 0===_b?void 0:_b.fail).mount(`#${this.id}`),this.dropinConfig.events.onAuthorizeFailed&&(null===(_c=this.dropinConfig.events)||void 0===_c||_c.onAuthorizeFailed())}}var Skyflow$1=require("skyflow-js").default;class CollectContainer{constructor(__client,options){this.__container=__client.container(Skyflow$1.ContainerType.COMPOSABLE,options)}get elementToFieldMap(){return new Map([[exports.ElementType.CARD_NUMBER,"card_number"],[exports.ElementType.CARDHOLDER_NAME,"cardholder_name"],[exports.ElementType.CVV,"security_code"],[exports.ElementType.EXPIRATION_MONTH,"expiry_month"],[exports.ElementType.EXPIRATION_YEAR,"expiry_year"]])}createCollectElement(options){return this.__container.create(Object.assign(Object.assign(Object.assign({},DEFAULT_ELEMENT_CONFIG),{column:this.elementToFieldMap.get(options.type)}),options),{format:options.format})}mount(selector){const id="payrails-container-wrapper";this.element=document.createElement("span"),this.element.setAttribute("id",id);const parentEl=document.querySelector(selector);if(!parentEl)throw new Error(`Element with selector ${selector} does not exist`);parentEl.appendChild(this.element),window.setTimeout((()=>{this.__container.mount(`#${id}`)}),50)}unmount(){this.element&&this.element.remove()}async collect(){const{records:records}=await this.__container.collect(),{skyflow_id:skyflow_id,card_number:card_number,cardholder_name:cardholder_name,expiry_month:expiry_month,expiry_year:expiry_year}=records[0].fields;return{instrumentId:skyflow_id,card_number:card_number,cardholder_name:cardholder_name,expiry_month:expiry_month,expiry_year:expiry_year}}}var Skyflow=require("skyflow-js").default;class Payrails{static init(initResponse,options){const deserializedData=JSON.parse(atob(initResponse.data)),{vaultConfiguration:{vaultId:vaultId,vaultUrl:vaultUrl,token:token},execution:execution}=deserializedData,vaultClient=Skyflow.init({vaultID:vaultId,vaultURL:vaultUrl,getBearerToken:()=>Promise.resolve(token)});return new Payrails(deserializedData,vaultClient,new WorkflowExecution(execution),options)}update(execution,amount){this.execution.update(execution),this.sdkConfiguration.amount=amount}collectContainer(containerOptions){if(!containerOptions.layout)throw new Error("Layout configuration is required");return this.__container=new CollectContainer(this.vaultClient,containerOptions),this.__container}googlePayButton(options){var _a;if(!this.execution)throw new Error("SDK was not initialized with workflow execution");return new GooglePayButton(this.sdkConfiguration,this.execution,Object.assign({environment:null===(_a=this.options)||void 0===_a?void 0:_a.environment},options))}cardList(options){return this.__cardList||(this.__cardList=new CardList(this.execution,{onCardChange:selectedCard=>{this.__cardPaymentButton&&(this.__cardPaymentButton.selectedCard=selectedCard,this.__cardPaymentButton.setDisabled(!1)),null==options||options.onCardChange(selectedCard)}})),this.__cardList}cardForm(options){var _a,_b;if(!this.__cardForm){const layout=this.getContainerLayout(null==options?void 0:options.showCardHolderName);this.__container=this.collectContainer(Object.assign(Object.assign({layout:layout,errorTextStyles:{base:{display:"none"}}},null===(_a=null==options?void 0:options.styles)||void 0===_a?void 0:_a.errorTextStyles),{styles:{base:null===(_b=null==options?void 0:options.styles)||void 0===_b?void 0:_b.base}})),this.__cardForm=new CardForm(this.__container,Object.assign(Object.assign({},options),{events:Object.assign(Object.assign({},null==options?void 0:options.events),{onChange:e=>{var _a;this.__cardPaymentButton&&(this.__cardPaymentButton.selectedCard=null,this.__cardForm&&this.__cardPaymentButton.setDisabled(!this.__cardForm.isValid)),(null===(_a=null==options?void 0:options.events)||void 0===_a?void 0:_a.onChange)&&options.events.onChange(e)},onFocus:()=>{var _a;this.__cardList&&this.__cardList.reset(),this.__cardPaymentButton&&(this.__cardPaymentButton.selectedCard=null,this.__cardForm&&this.__cardPaymentButton.setDisabled(!this.__cardForm.isValid)),(null===(_a=null==options?void 0:options.events)||void 0===_a?void 0:_a.onFocus)&&options.events.onFocus()}})}))}return this.__cardPaymentButton&&this.__cardPaymentButton.setCardForm(this.__cardForm),this.__cardForm}constructor(sdkConfiguration,vaultClient,execution,options){var _a;this.sdkConfiguration=sdkConfiguration,this.vaultClient=vaultClient,this.execution=execution,this.options=options,(null===(_a=null==options?void 0:options.events)||void 0===_a?void 0:_a.onClientInitialized)&&options.events.onClientInitialized(this.execution)}dropin(options){var _a,_b;const layout=this.getContainerLayout(null===(_b=null===(_a=options.paymentMethodsConfiguration)||void 0===_a?void 0:_a.cards)||void 0===_b?void 0:_b.showCardHolderName);return this.__container=this.collectContainer({layout:layout,errorTextStyles:{base:{display:"none"}}}),new Dropin(this.__container,options,this.execution,this.sdkConfiguration)}getContainerLayout(showCardHolderName){return showCardHolderName?[1,1,3]:[1,3]}paymentButton(options){return this.__cardPaymentButton||(this.__cardPaymentButton=new CardPaymentButton(this.sdkConfiguration,this.execution,options)),this.__cardPaymentButton.setDisabled(!0),this.__cardForm&&this.__cardPaymentButton.setCardForm(this.__cardForm),this.__cardPaymentButton}}exports.Payrails=Payrails;
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@payrails/web-sdk",
|
|
3
|
+
"version": "1.1.6",
|
|
4
|
+
"description": "SDK providing tokenization options on the client for merchants",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "payrails.d.ts",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"scripts": {},
|
|
9
|
+
"author": "Petr Prchal <petr@payrails.com>",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"skyflow-js": "1.25.0"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
#payrails-card-form {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-wrap: wrap;
|
|
4
|
+
flex-direction: row;
|
|
5
|
+
justify-content: space-between;
|
|
6
|
+
align-items: center;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
#payrails-store-card label {
|
|
10
|
+
font-size: 14px;
|
|
11
|
+
margin-left: 4px;
|
|
12
|
+
display: flex;
|
|
13
|
+
margin-bottom: 4px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
#payrails-store-card-checkbox {
|
|
17
|
+
margin-right: 4px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#payrails-card-list * {
|
|
21
|
+
line-height: 1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#payrails-card-list {
|
|
25
|
+
width: 100%;
|
|
26
|
+
border: none;
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: 0;
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
gap: 8px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.payrails-card-list-item {
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
align-items: flex-start;
|
|
38
|
+
padding: 16px;
|
|
39
|
+
gap: 16px;
|
|
40
|
+
|
|
41
|
+
width: 100%;
|
|
42
|
+
|
|
43
|
+
background: #ffffff;
|
|
44
|
+
|
|
45
|
+
border: 1px solid #eaebec;
|
|
46
|
+
border-radius: 8px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.payrails-card-list-item input[type='radio'] {
|
|
50
|
+
width: auto;
|
|
51
|
+
margin-right: 8px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.payrails-saved-cards-header {
|
|
55
|
+
font-weight: bolder;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#payrails-card-payment-button {
|
|
59
|
+
display: flex;
|
|
60
|
+
flex-direction: row;
|
|
61
|
+
justify-content: center;
|
|
62
|
+
align-items: center;
|
|
63
|
+
padding: 8px 16px;
|
|
64
|
+
gap: 8px;
|
|
65
|
+
|
|
66
|
+
width: 100%;
|
|
67
|
+
height: 40px;
|
|
68
|
+
|
|
69
|
+
background: #015bbb;
|
|
70
|
+
border-radius: 4px;
|
|
71
|
+
box-shadow: none;
|
|
72
|
+
|
|
73
|
+
font-size: 14px;
|
|
74
|
+
color: #fff;
|
|
75
|
+
margin: 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#payrails-card-payment-button:disabled {
|
|
79
|
+
background-color: #fff;
|
|
80
|
+
border: 1px solid #eae8ee;
|
|
81
|
+
color: #eae8ee;
|
|
82
|
+
cursor: not-allowed;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* The Modal (background) */
|
|
86
|
+
#payrails-3ds-popup-background {
|
|
87
|
+
position: fixed;
|
|
88
|
+
z-index: 10000;
|
|
89
|
+
left: 0;
|
|
90
|
+
top: 0;
|
|
91
|
+
width: 100%;
|
|
92
|
+
height: 100%;
|
|
93
|
+
overflow: auto;
|
|
94
|
+
background-color: rgb(0, 0, 0);
|
|
95
|
+
background-color: rgba(0, 0, 0, 0.4);
|
|
96
|
+
display: flex;
|
|
97
|
+
align-content: center;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* Modal Content/Box */
|
|
101
|
+
#payrails-3ds-challenge {
|
|
102
|
+
background-color: #fefefe;
|
|
103
|
+
margin: 15% auto;
|
|
104
|
+
padding: 0;
|
|
105
|
+
overflow: hidden;
|
|
106
|
+
border: 1px solid #888;
|
|
107
|
+
border-radius: 4px;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#payrails-3ds-frame {
|
|
111
|
+
border: 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#payrails-card-payment-button .dot-flashing {
|
|
115
|
+
position: relative;
|
|
116
|
+
width: 10px;
|
|
117
|
+
height: 10px;
|
|
118
|
+
border-radius: 5px;
|
|
119
|
+
background-color: #015bbb;
|
|
120
|
+
color: #015bbb;
|
|
121
|
+
animation: dot-flashing 1s infinite linear alternate;
|
|
122
|
+
animation-delay: 0.5s;
|
|
123
|
+
}
|
|
124
|
+
#payrails-card-payment-button .dot-flashing::before,
|
|
125
|
+
#payrails-card-payment-button .dot-flashing::after {
|
|
126
|
+
content: '';
|
|
127
|
+
display: inline-block;
|
|
128
|
+
position: absolute;
|
|
129
|
+
top: 0;
|
|
130
|
+
}
|
|
131
|
+
#payrails-card-payment-button .dot-flashing::before {
|
|
132
|
+
left: -15px;
|
|
133
|
+
width: 10px;
|
|
134
|
+
height: 10px;
|
|
135
|
+
border-radius: 5px;
|
|
136
|
+
background-color: #015bbb;
|
|
137
|
+
color: #015bbb;
|
|
138
|
+
animation: dot-flashing 1s infinite alternate;
|
|
139
|
+
animation-delay: 0s;
|
|
140
|
+
}
|
|
141
|
+
#payrails-card-payment-button .dot-flashing::after {
|
|
142
|
+
left: 15px;
|
|
143
|
+
width: 10px;
|
|
144
|
+
height: 10px;
|
|
145
|
+
border-radius: 5px;
|
|
146
|
+
background-color: #015bbb;
|
|
147
|
+
color: #015bbb;
|
|
148
|
+
animation: dot-flashing 1s infinite alternate;
|
|
149
|
+
animation-delay: 1s;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@keyframes dot-flashing {
|
|
153
|
+
0% {
|
|
154
|
+
background-color: #015bbb;
|
|
155
|
+
}
|
|
156
|
+
50%,
|
|
157
|
+
100% {
|
|
158
|
+
background-color: rgba(152, 128, 255, 0.2);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#payrails-dropin-component {
|
|
163
|
+
background: #ffffff;
|
|
164
|
+
box-shadow: 0px 0px 1px rgba(66, 71, 76, 0.32),
|
|
165
|
+
0px 4px 8px rgba(66, 71, 76, 0.06), 0px 8px 48px #eeeeee;
|
|
166
|
+
border-radius: 16px;
|
|
167
|
+
border: 1px solid #eae8ee;
|
|
168
|
+
width: 100%;
|
|
169
|
+
|
|
170
|
+
display: flex;
|
|
171
|
+
flex-direction: column;
|
|
172
|
+
align-items: flex-start;
|
|
173
|
+
padding: 24px;
|
|
174
|
+
gap: 24px;
|
|
175
|
+
position: relative;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.payrails-dropin-item input[type='radio'] {
|
|
179
|
+
width: auto;
|
|
180
|
+
margin-right: 8px;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.payrails-dropin-item {
|
|
184
|
+
border: 1px solid #eae8ee;
|
|
185
|
+
border-radius: 4px;
|
|
186
|
+
padding: 16px;
|
|
187
|
+
width: 100%;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#payrails-dropin-component * {
|
|
191
|
+
min-width: none !important;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
#payrails-dropin-component .gpay-button {
|
|
195
|
+
background-color: #000;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#payrails-dropin-component label {
|
|
199
|
+
line-height: 1;
|
|
200
|
+
min-width: 100px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
#payrails-credit-card-wrapper button {
|
|
204
|
+
margin-top: 8px;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
#payrails-authorization-success {
|
|
208
|
+
width: 100%;
|
|
209
|
+
text-align: center;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
#authorization-failed-message {
|
|
213
|
+
text-align: center;
|
|
214
|
+
position: absolute;
|
|
215
|
+
left: 8px;
|
|
216
|
+
right: 8px;
|
|
217
|
+
top: 8px;
|
|
218
|
+
bottom: 8px;
|
|
219
|
+
margin: auto;
|
|
220
|
+
border-radius: 16px;
|
|
221
|
+
border: 1px solid #eae8ee;
|
|
222
|
+
background-color: #fff;
|
|
223
|
+
opacity: 0.95;
|
|
224
|
+
display: flex;
|
|
225
|
+
flex-direction: column;
|
|
226
|
+
align-items: center;
|
|
227
|
+
justify-content: center;
|
|
228
|
+
gap: 8px;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
#authorization-failed-message .checkmark-cross {
|
|
232
|
+
width: 56px;
|
|
233
|
+
height: 56px;
|
|
234
|
+
border-radius: 50%;
|
|
235
|
+
display: block;
|
|
236
|
+
stroke-width: 2;
|
|
237
|
+
stroke: #fff;
|
|
238
|
+
stroke-miterlimit: 10;
|
|
239
|
+
box-shadow: inset 0px 0px 0px #ff5a66;
|
|
240
|
+
animation: strokeFill 0.4s ease-in-out 0.4s forwards,
|
|
241
|
+
strokeScale 0.3s ease-in-out 0.9s both;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
#authorization-failed-message .checkmark-cross_circle {
|
|
245
|
+
stroke-dasharray: 166;
|
|
246
|
+
stroke-dashoffset: 166;
|
|
247
|
+
stroke-width: 2;
|
|
248
|
+
stroke-miterlimit: 10;
|
|
249
|
+
stroke: #ff5a66;
|
|
250
|
+
fill: none;
|
|
251
|
+
animation: strokeStroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#authorization-failed-message .checkmark-cross_check {
|
|
255
|
+
transform-origin: 50% 50%;
|
|
256
|
+
stroke-dasharray: 48;
|
|
257
|
+
stroke-dashoffset: 48;
|
|
258
|
+
animation: strokeCross 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
@keyframes strokeCross {
|
|
262
|
+
100% {
|
|
263
|
+
stroke-dashoffset: 0;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
@keyframes strokeScale {
|
|
267
|
+
0%,
|
|
268
|
+
100% {
|
|
269
|
+
transform: none;
|
|
270
|
+
}
|
|
271
|
+
50% {
|
|
272
|
+
transform: scale3d(1.1, 1.1, 1);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
@keyframes strokeFill {
|
|
276
|
+
100% {
|
|
277
|
+
box-shadow: inset 0px 0px 0px 30px #ff5a66;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
#payrails-authorization-success-msg {
|
|
282
|
+
width: 100%;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
#payrails-authorization-success-msg .checkmark-wrapper {
|
|
286
|
+
display: flex;
|
|
287
|
+
justify-content: center;
|
|
288
|
+
align-items: center;
|
|
289
|
+
width: 100%;
|
|
290
|
+
height: 75px;
|
|
291
|
+
}
|
|
292
|
+
#payrails-authorization-success-msg .checkmark__circle {
|
|
293
|
+
stroke-dasharray: 166;
|
|
294
|
+
stroke-dashoffset: 166;
|
|
295
|
+
stroke-width: 2;
|
|
296
|
+
stroke-miterlimit: 10;
|
|
297
|
+
stroke: #7ac142;
|
|
298
|
+
fill: none;
|
|
299
|
+
animation: strokeCheck 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
|
|
300
|
+
}
|
|
301
|
+
#payrails-authorization-success-msg .checkmark {
|
|
302
|
+
width: 56px;
|
|
303
|
+
height: 56px;
|
|
304
|
+
border-radius: 50%;
|
|
305
|
+
display: block;
|
|
306
|
+
stroke-width: 2;
|
|
307
|
+
stroke: #fff;
|
|
308
|
+
stroke-miterlimit: 10;
|
|
309
|
+
margin: 10% auto;
|
|
310
|
+
box-shadow: inset 0px 0px 0px #7ac142;
|
|
311
|
+
animation: fillCheck 0.4s ease-in-out 0.4s forwards,
|
|
312
|
+
scaleCheck 0.3s ease-in-out 0.9s both;
|
|
313
|
+
}
|
|
314
|
+
#payrails-authorization-success-msg .checkmark__check {
|
|
315
|
+
transform-origin: 50% 50%;
|
|
316
|
+
stroke-dasharray: 48;
|
|
317
|
+
stroke-dashoffset: 48;
|
|
318
|
+
animation: strokeCheck 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
@keyframes strokeCheck {
|
|
322
|
+
100% {
|
|
323
|
+
stroke-dashoffset: 0;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
@keyframes scaleCheck {
|
|
327
|
+
0%,
|
|
328
|
+
100% {
|
|
329
|
+
transform: none;
|
|
330
|
+
}
|
|
331
|
+
50% {
|
|
332
|
+
transform: scale3d(1.1, 1.1, 1);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
@keyframes fillCheck {
|
|
336
|
+
100% {
|
|
337
|
+
box-shadow: inset 0px 0px 0px 30px #7ac142;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
#payrails-container-wrapper {
|
|
342
|
+
width: 100%;
|
|
343
|
+
height: 90px;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
.with-card-holder #payrails-container-wrapper {
|
|
347
|
+
width: 100%;
|
|
348
|
+
height: 120px;
|
|
349
|
+
}
|
package/payrails.d.ts
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/// <reference types="googlepay" />
|
|
2
|
+
import * as skyflow_js_types_core_external_collect_compose_collect_element from 'skyflow-js/types/core/external/collect/compose-collect-element';
|
|
3
|
+
import Skyflow from 'skyflow-js';
|
|
4
|
+
|
|
5
|
+
declare enum ElementType {
|
|
6
|
+
CARD_NUMBER = "CARD_NUMBER",
|
|
7
|
+
CARDHOLDER_NAME = "CARDHOLDER_NAME",
|
|
8
|
+
CVV = "CVV",
|
|
9
|
+
EXPIRATION_MONTH = "EXPIRATION_MONTH",
|
|
10
|
+
EXPIRATION_YEAR = "EXPIRATION_YEAR"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Mountable {
|
|
14
|
+
mount(selector: string | PayrailsElement): void;
|
|
15
|
+
unmount(): void;
|
|
16
|
+
}
|
|
17
|
+
interface ElementOptions {
|
|
18
|
+
id?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
styles?: Partial<CSSStyleDeclaration>;
|
|
21
|
+
}
|
|
22
|
+
declare class PayrailsElement implements Mountable {
|
|
23
|
+
protected element: HTMLElement;
|
|
24
|
+
protected subElements: Array<Mountable>;
|
|
25
|
+
readonly id: string | undefined;
|
|
26
|
+
constructor(elementType: string, { id, className }?: ElementOptions);
|
|
27
|
+
get parentElement(): HTMLElement | null;
|
|
28
|
+
mount(location: string): void;
|
|
29
|
+
unmount(): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface CollectElementOptions {
|
|
33
|
+
type: ElementType;
|
|
34
|
+
label?: string;
|
|
35
|
+
placeholder?: string;
|
|
36
|
+
altText?: string;
|
|
37
|
+
format?: string;
|
|
38
|
+
inputStyles?: object;
|
|
39
|
+
labelStyles?: object;
|
|
40
|
+
errorTextStyles?: object;
|
|
41
|
+
}
|
|
42
|
+
interface CollectContainerOptions {
|
|
43
|
+
layout: number[];
|
|
44
|
+
styles?: {
|
|
45
|
+
base?: Partial<CSSStyleDeclaration>;
|
|
46
|
+
};
|
|
47
|
+
errorTextStyles?: {
|
|
48
|
+
base?: Partial<CSSStyleDeclaration>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
declare class CollectContainer implements Mountable {
|
|
52
|
+
private readonly __container;
|
|
53
|
+
private element;
|
|
54
|
+
constructor(__client: Skyflow, options: CollectContainerOptions);
|
|
55
|
+
private get elementToFieldMap();
|
|
56
|
+
createCollectElement(options: CollectElementOptions): skyflow_js_types_core_external_collect_compose_collect_element.default;
|
|
57
|
+
mount(selector: string): void;
|
|
58
|
+
unmount(): void;
|
|
59
|
+
collect(): Promise<{
|
|
60
|
+
instrumentId: string;
|
|
61
|
+
card_number: string | undefined;
|
|
62
|
+
cardholder_name: string | undefined;
|
|
63
|
+
expiry_month: string | undefined;
|
|
64
|
+
expiry_year: string | undefined;
|
|
65
|
+
}>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface OnChange {
|
|
69
|
+
isValid: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface CardFormOptions {
|
|
72
|
+
showCardHolderName?: boolean;
|
|
73
|
+
showStoreInstrumentCheckbox?: boolean;
|
|
74
|
+
alwaysStoreInstrument?: boolean;
|
|
75
|
+
translations?: {
|
|
76
|
+
placeholders?: {
|
|
77
|
+
[key in ElementType]?: string;
|
|
78
|
+
};
|
|
79
|
+
labels?: {
|
|
80
|
+
saveCreditCard: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
events?: {
|
|
84
|
+
onFocus?: () => void;
|
|
85
|
+
onChange?: (e: OnChange) => void;
|
|
86
|
+
};
|
|
87
|
+
styles?: {
|
|
88
|
+
base?: Partial<CSSStyleDeclaration>;
|
|
89
|
+
storeCardCheckbox?: Partial<CSSStyleDeclaration>;
|
|
90
|
+
errorTextStyles?: {
|
|
91
|
+
base: Partial<CSSStyleDeclaration>;
|
|
92
|
+
};
|
|
93
|
+
inputFields?: {
|
|
94
|
+
[key in ElementType | 'all']?: CardFieldStyles;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
declare class CardForm extends PayrailsElement {
|
|
99
|
+
private readonly collectContainer;
|
|
100
|
+
private readonly options?;
|
|
101
|
+
private readonly storeCardCheckbox;
|
|
102
|
+
private readonly formFields;
|
|
103
|
+
constructor(collectContainer: CollectContainer, options?: CardFormOptions | undefined);
|
|
104
|
+
show(): void;
|
|
105
|
+
hide(): void;
|
|
106
|
+
private prepareStyles;
|
|
107
|
+
get isValid(): boolean;
|
|
108
|
+
onChange(): void;
|
|
109
|
+
collectValues(): Promise<{
|
|
110
|
+
tokenizedCardData: {
|
|
111
|
+
instrumentId: string;
|
|
112
|
+
card_number: string | undefined;
|
|
113
|
+
cardholder_name: string | undefined;
|
|
114
|
+
expiry_month: string | undefined;
|
|
115
|
+
expiry_year: string | undefined;
|
|
116
|
+
};
|
|
117
|
+
storeInstrument: boolean | undefined;
|
|
118
|
+
}>;
|
|
119
|
+
}
|
|
120
|
+
interface CardFieldStyles {
|
|
121
|
+
base?: Partial<CSSStyleDeclaration>;
|
|
122
|
+
complete?: Partial<CSSStyleDeclaration>;
|
|
123
|
+
empty?: Partial<CSSStyleDeclaration>;
|
|
124
|
+
focus?: Partial<CSSStyleDeclaration>;
|
|
125
|
+
invalid?: Partial<CSSStyleDeclaration>;
|
|
126
|
+
cardIcon?: Partial<CSSStyleDeclaration>;
|
|
127
|
+
copyIcon?: Partial<CSSStyleDeclaration>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
declare enum PAYMENT_METHOD_CODES {
|
|
131
|
+
'CARD' = "card",
|
|
132
|
+
'GOOGLE_PAY' = "googlePay"
|
|
133
|
+
}
|
|
134
|
+
declare enum PAYMENT_INSTRUMENT_STATUS {
|
|
135
|
+
'ENABLED' = "enabled",
|
|
136
|
+
'CREATED' = "created"
|
|
137
|
+
}
|
|
138
|
+
declare class WorkflowExecution {
|
|
139
|
+
private executionResponse;
|
|
140
|
+
constructor(executionResponse: ExecutionResponse);
|
|
141
|
+
get lookup(): {
|
|
142
|
+
httpCode: number;
|
|
143
|
+
body: {
|
|
144
|
+
data: {
|
|
145
|
+
paymentCompositionOptions: (GooglePayCompositionOption | CardCompositionOption)[];
|
|
146
|
+
};
|
|
147
|
+
links: {
|
|
148
|
+
authorize: {
|
|
149
|
+
href: string;
|
|
150
|
+
method: "POST";
|
|
151
|
+
};
|
|
152
|
+
execution: string;
|
|
153
|
+
};
|
|
154
|
+
name: "lookup";
|
|
155
|
+
};
|
|
156
|
+
} | undefined;
|
|
157
|
+
get holderReference(): string;
|
|
158
|
+
get savedCreditCards(): SavedCreditCard[];
|
|
159
|
+
get googlePayConfig(): {
|
|
160
|
+
parameters: {
|
|
161
|
+
allowedAuthMethods: string[];
|
|
162
|
+
allowedCardNetworks: string[];
|
|
163
|
+
};
|
|
164
|
+
tokenizationSpecification: {
|
|
165
|
+
parameters: {
|
|
166
|
+
gateway: string;
|
|
167
|
+
gatewayMerchantId: string;
|
|
168
|
+
};
|
|
169
|
+
type: string;
|
|
170
|
+
};
|
|
171
|
+
type: string;
|
|
172
|
+
}[];
|
|
173
|
+
get url(): string;
|
|
174
|
+
get response(): ExecutionResponse;
|
|
175
|
+
get meta(): {
|
|
176
|
+
customer?: {
|
|
177
|
+
country?: {
|
|
178
|
+
code: string;
|
|
179
|
+
} | undefined;
|
|
180
|
+
} | undefined;
|
|
181
|
+
};
|
|
182
|
+
get availablePaymentMethods(): (GooglePayCompositionOption | CardCompositionOption)[];
|
|
183
|
+
get authorizeLink(): string | undefined;
|
|
184
|
+
update(response: ExecutionResponse): void;
|
|
185
|
+
}
|
|
186
|
+
interface ExecutionResponse {
|
|
187
|
+
id: string;
|
|
188
|
+
merchantReference: string;
|
|
189
|
+
holderReference: string;
|
|
190
|
+
actionRequired?: string;
|
|
191
|
+
meta: {
|
|
192
|
+
customer?: {
|
|
193
|
+
country?: {
|
|
194
|
+
code: string;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
status: Array<{
|
|
199
|
+
code: string;
|
|
200
|
+
time: string;
|
|
201
|
+
}>;
|
|
202
|
+
initialResults: Array<{
|
|
203
|
+
httpCode: number;
|
|
204
|
+
body: {
|
|
205
|
+
data: {
|
|
206
|
+
paymentCompositionOptions: Array<GooglePayCompositionOption | CardCompositionOption>;
|
|
207
|
+
};
|
|
208
|
+
links: {
|
|
209
|
+
authorize: {
|
|
210
|
+
href: string;
|
|
211
|
+
method: 'POST';
|
|
212
|
+
};
|
|
213
|
+
execution: string;
|
|
214
|
+
};
|
|
215
|
+
name: 'lookup';
|
|
216
|
+
};
|
|
217
|
+
}>;
|
|
218
|
+
links: {
|
|
219
|
+
'3ds'?: string;
|
|
220
|
+
self: string;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
interface PaymentCompositionOption {
|
|
224
|
+
paymentMethodCode?: PAYMENT_METHOD_CODES;
|
|
225
|
+
description: string;
|
|
226
|
+
integrationType: string;
|
|
227
|
+
}
|
|
228
|
+
interface CardCompositionOption extends PaymentCompositionOption {
|
|
229
|
+
paymentInstruments?: Array<SavedCreditCard>;
|
|
230
|
+
}
|
|
231
|
+
interface GooglePayCompositionOption extends PaymentCompositionOption {
|
|
232
|
+
config: {
|
|
233
|
+
parameters: {
|
|
234
|
+
allowedAuthMethods: string[];
|
|
235
|
+
allowedCardNetworks: string[];
|
|
236
|
+
};
|
|
237
|
+
tokenizationSpecification: {
|
|
238
|
+
parameters: {
|
|
239
|
+
gateway: string;
|
|
240
|
+
gatewayMerchantId: string;
|
|
241
|
+
};
|
|
242
|
+
type: string;
|
|
243
|
+
};
|
|
244
|
+
type: string;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
interface SavedCreditCard {
|
|
248
|
+
id: string;
|
|
249
|
+
status: PAYMENT_INSTRUMENT_STATUS;
|
|
250
|
+
data: {
|
|
251
|
+
bin: string;
|
|
252
|
+
suffix: string;
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
interface CardListOptions {
|
|
257
|
+
onCardChange: (selectedCard: SavedCreditCard) => void;
|
|
258
|
+
}
|
|
259
|
+
declare class CardList extends PayrailsElement {
|
|
260
|
+
private readonly workflowExecution;
|
|
261
|
+
private listItems;
|
|
262
|
+
constructor(workflowExecution: WorkflowExecution, options?: CardListOptions);
|
|
263
|
+
reset(): void;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
interface CardPaymentButtonOptions {
|
|
267
|
+
events?: PaymentEvents;
|
|
268
|
+
translations?: {
|
|
269
|
+
label: string;
|
|
270
|
+
};
|
|
271
|
+
styles?: {
|
|
272
|
+
base?: Partial<CSSStyleDeclaration>;
|
|
273
|
+
disabled?: Partial<CSSStyleDeclaration>;
|
|
274
|
+
loading?: Partial<CSSStyleDeclaration>;
|
|
275
|
+
hover?: Partial<CSSStyleDeclaration>;
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
declare class CardPaymentButton extends PayrailsElement {
|
|
279
|
+
private readonly sdkConfig;
|
|
280
|
+
private readonly execution;
|
|
281
|
+
private readonly options;
|
|
282
|
+
selectedCard: SavedCreditCard | null;
|
|
283
|
+
private paymentExecutor;
|
|
284
|
+
private storeInstrument;
|
|
285
|
+
private cardForm;
|
|
286
|
+
constructor(sdkConfig: SdkConfiguration, execution: WorkflowExecution, options: CardPaymentButtonOptions);
|
|
287
|
+
setDisabled(isDisabled: boolean): void;
|
|
288
|
+
private setStyles;
|
|
289
|
+
private removeStyles;
|
|
290
|
+
setLabel(label: string): void;
|
|
291
|
+
setCardForm(cardForm: CardForm): void;
|
|
292
|
+
triggerLoading(isLoading: boolean): void;
|
|
293
|
+
private onAuthorizationFailed;
|
|
294
|
+
private onPay;
|
|
295
|
+
private handleAuthorizationResult;
|
|
296
|
+
private handle3ds;
|
|
297
|
+
private tokenizeCard;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
interface GooglePayButtonOptions {
|
|
301
|
+
environment?: 'TEST' | 'PRODUCTION';
|
|
302
|
+
events?: PaymentEvents;
|
|
303
|
+
styles?: {
|
|
304
|
+
buttonColor?: google.payments.api.ButtonColor;
|
|
305
|
+
buttonType?: google.payments.api.ButtonType;
|
|
306
|
+
buttonSizeMode?: google.payments.api.ButtonSizeMode;
|
|
307
|
+
buttonLocale?: string;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
declare class GooglePayButton extends PayrailsElement {
|
|
311
|
+
private sdkConfig;
|
|
312
|
+
private execution;
|
|
313
|
+
private options;
|
|
314
|
+
private client;
|
|
315
|
+
private googleButton;
|
|
316
|
+
private paymentExecutor;
|
|
317
|
+
private loadScript;
|
|
318
|
+
constructor(sdkConfig: SdkConfiguration, execution: WorkflowExecution, options: GooglePayButtonOptions);
|
|
319
|
+
private sdkLoaded;
|
|
320
|
+
private onLoadPaymentData;
|
|
321
|
+
private onPaymentButtonClicked;
|
|
322
|
+
mount(location: string): void;
|
|
323
|
+
unmount(): void;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
interface GooglePayDropinOptions extends GooglePayButtonOptions {
|
|
327
|
+
translations?: {
|
|
328
|
+
label?: string;
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
declare class Dropin extends PayrailsElement {
|
|
333
|
+
private collectContainer;
|
|
334
|
+
private readonly dropinConfig;
|
|
335
|
+
private readonly execution;
|
|
336
|
+
private readonly sdkConfig;
|
|
337
|
+
private cardPaymentButton;
|
|
338
|
+
private creditCard;
|
|
339
|
+
private googlePay;
|
|
340
|
+
private cardForm;
|
|
341
|
+
constructor(collectContainer: CollectContainer, dropinConfig: DropinConfiguration, execution: WorkflowExecution, sdkConfig: SdkConfiguration);
|
|
342
|
+
private createCardForm;
|
|
343
|
+
private createCardPaymentButton;
|
|
344
|
+
private onAuthorizeSuccess;
|
|
345
|
+
private onAuthorizeFailed;
|
|
346
|
+
}
|
|
347
|
+
interface DropinConfiguration {
|
|
348
|
+
paymentMethodsConfiguration?: {
|
|
349
|
+
cards?: {
|
|
350
|
+
showCardHolderName?: boolean;
|
|
351
|
+
showStoreInstrumentCheckbox?: boolean;
|
|
352
|
+
showStoredInstruments?: boolean;
|
|
353
|
+
showExistingCards?: boolean;
|
|
354
|
+
alwaysStoreInstrument?: boolean;
|
|
355
|
+
};
|
|
356
|
+
};
|
|
357
|
+
returnInfo?: {
|
|
358
|
+
success: string;
|
|
359
|
+
error: string;
|
|
360
|
+
};
|
|
361
|
+
events: PaymentEvents;
|
|
362
|
+
translations?: {
|
|
363
|
+
googlePayButton?: GooglePayDropinOptions['translations'];
|
|
364
|
+
cardPaymentButton?: CardPaymentButtonOptions['translations'];
|
|
365
|
+
cardForm?: CardFormOptions['translations'];
|
|
366
|
+
paymentResult?: {
|
|
367
|
+
success?: string;
|
|
368
|
+
fail?: string;
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
styles?: {
|
|
372
|
+
googlePayButton?: GooglePayButtonOptions['styles'];
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
interface PayrailsClientOptions {
|
|
377
|
+
environment?: 'TEST' | 'PRODUCTION';
|
|
378
|
+
events?: {
|
|
379
|
+
onClientInitialized: (execution: WorkflowExecution) => void;
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
declare class Payrails {
|
|
383
|
+
private sdkConfiguration;
|
|
384
|
+
private vaultClient;
|
|
385
|
+
private execution;
|
|
386
|
+
private options?;
|
|
387
|
+
private __container;
|
|
388
|
+
private __cardForm;
|
|
389
|
+
private __cardList;
|
|
390
|
+
private __cardPaymentButton;
|
|
391
|
+
static init(initResponse: InitOptions, options?: PayrailsClientOptions): Payrails;
|
|
392
|
+
update(execution: ExecutionResponse, amount: PayrailsAmount): void;
|
|
393
|
+
collectContainer(containerOptions: CollectContainerOptions): CollectContainer;
|
|
394
|
+
googlePayButton(options: GooglePayButtonOptions): GooglePayButton;
|
|
395
|
+
cardList(options?: CardListOptions): CardList;
|
|
396
|
+
cardForm(options?: CardFormOptions): CardForm;
|
|
397
|
+
private constructor();
|
|
398
|
+
dropin(options: DropinConfiguration): Dropin;
|
|
399
|
+
private getContainerLayout;
|
|
400
|
+
paymentButton(options: CardPaymentButtonOptions): CardPaymentButton;
|
|
401
|
+
}
|
|
402
|
+
interface InitOptions {
|
|
403
|
+
version: string;
|
|
404
|
+
data: string;
|
|
405
|
+
}
|
|
406
|
+
interface PaymentEvents {
|
|
407
|
+
onAuthorizeSuccess?: (e?: any) => void;
|
|
408
|
+
onAuthorizeFailed?: (e?: any) => void;
|
|
409
|
+
onPaymentButtonClicked?: () => Promise<boolean>;
|
|
410
|
+
onPaymentSessionExpired?: () => void;
|
|
411
|
+
}
|
|
412
|
+
interface SdkConfiguration {
|
|
413
|
+
token: string;
|
|
414
|
+
amount?: PayrailsAmount;
|
|
415
|
+
vaultConfiguration: {
|
|
416
|
+
token: string;
|
|
417
|
+
vaultId: string;
|
|
418
|
+
vaultUrl: string;
|
|
419
|
+
providerId: string;
|
|
420
|
+
providerConfigId: string;
|
|
421
|
+
links: {
|
|
422
|
+
saveInstrument: {
|
|
423
|
+
href: string;
|
|
424
|
+
};
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
execution: ExecutionResponse;
|
|
428
|
+
}
|
|
429
|
+
interface PayrailsAmount {
|
|
430
|
+
value: string;
|
|
431
|
+
currency: string;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export { ElementType, Payrails };
|