1.0.16 • Published 4 days ago

@motopays/pay-form v1.0.16

Weekly downloads
-
License
-
Repository
-
Last release
4 days ago

@motopays/pay-form

Installation

npm i @motopays/pay-form
#or
yarn add @motopays/pay-form

Usage

<body>
  <moto-web-pay id="payment"></moto-web-pay>
</body>
import "@motopays/pay-form/lib/index.js";
import "@motopays/pay-form/lib/styles/styles.css";

const payment$ = document.querySelector("#payment");

payment$.payment = {
  userAuthToken?: string;
  userId: string;
  
  paymentId: string;
  amount: number;
  amountType?: AmountType; //one of strings: GrossWithoutGst, Net, Gross
  tax?: number;
  orderType?: OrderType; //one of numbers: Regular, FreeTrial
  currency: string;
  merchantId: string;
  initiator?: PaymentInitiatorType; //one of strings: Customer, Merchant

  webhookUrl?: string;
  returnUrl?: string;

  description: string;
  email?: string;
  details?: ISimple<any>; //any object
  phoneNumber?: string;
  ipAddress?: string;

  billingAddress?: {
    addressLine: string;
    city: string;
    state: string;
    country: string;
    zip: string;
  }
}

payment$.settings = {
  isPhoneNumberFieldVisible: boolean;
  isCloseButtonVisible: boolean;

  urls: {
    //For example, "https://billingprofiles.dating.com
    billingProfiles: string;
    processing: string;
  };

  //Now it supports these strings: "american-express" | "discover" | "jcb" | "maestro" | "mastercard" | "unionpay" | "visa"
  availableCardBrands: string[] or CreditCardTypeCardBrandId[];

  chargeTerms: {
    visible: boolean;
    text?: string;
    checkboxes?: { 
      text: string; 
      link: { 
        text: string; 
        href: string; 
      }
    } [];
  };

  merchantInfo: {
    visible: boolean;
    text?: string;
    links?: { 
      text: string; 
      href: string; 
    } [];
  };
}

payment$.addEventListener("close", (event) => {
  console.log("clicked to close icon: ", e); // Custom event
});

payment$.addEventListener("paid", (event) => {
  console.log("event after pay: ", event.detail); // Payment result event
});

Usage with TypeScript

declare module "@motopays/pay-form/pay";

Payment interface

FieldTypeDescription
userAuthTokenstringEnd-user authorization token to access Motopays services. This field is necessary for ApplePay availability
userId *requiredstringExternal end-user Id generated on the merchant side (not Motopays)
paymentId *requiredstringId of a payment
amount *requirednumberPayment amount
amountTypeAmountType or stringType of amount can be only one of the following values: {GrossWithoutGst, Net, Gross}
taxnumberPayment tax
orderTypeOrderType or stringType of order can be only one of the following values: {Regular, FreeTrial}
currency *requiredstringPayment currency in ISO_4217 format. Currently accepted: {gbp, eur, usd}
merchantId *requiredstringMerchant's identificator, issued by Motopays.
initiatorPaymentInitiatorType or stringIdentifies who of 2 types initiated the payment. Currently accepted: {Merchant, Customer}
webhookUrlstringURL where the Motopays will send hooks about the payment status changes
returnUrlstringThe URL to which the user will be redirected after completing some types of payment, such as PayPal
descriptionstringShort order description for the customer
emailstringEnd-customer e-mail. That parameter can be used to find a best button appearance for the particular customer.
detailsISimpleAdditional information about payment
phoneNumberstringEnd-customer phone number (can be changed if a customer fill the number by themself)
ipAddressstringEnd-customer ip address
billingAddressBillingAddressThe address linked to a customer bank account
billingAddress.addressLinestringStreet, building appartment and etc in one line
billingAddress.citystringCity of a customer bank account
billingAddress.statestringState of a customer bank account
billingAddress.countrystringCountry of a customer bank account (ISO 3166-1 alpha-2 country code). Example: US
billingAddress.zipstringZip of a customer bank account

Settings interface

FieldTypeDescription
urls *requiredIServicesUrlsThe necessary services urls
urls.processing *requiredstringThe processing service URL
urls.billingprofiles *requiredstringThe billing profiles service URL
isPhoneNumberFieldVisiblebooleanWhether to show the phone input field when creating a map
isCloseButtonVisiblebooleanWhether to show a window close button in the top right corner of the screen
merchantInfoIMerchantInfoSettingsThe information displays in merchant info section
merchantInfo.visiblebooleanWhether to show the merchant information
merchantInfo.textstringThe information about a merchant
merchantInfo.linksILink[]The array of merchant links. For example, Policy and Terms
chargeTermsIChargeTermsSettingsThe charge terms section
chargeTerms.visiblebooleanWhether to show the charge terms
chargeTerms.checkboxesITermCheckbox[]The checkboxes that, without being selected, the user will not be able to make a payment. All these checkboxes have to be selected by user to be able to make a payment
chargeTerms.textstringThe text of charge terms. For example, description of terms and policy
chargeTerms.locationstring or ChargeTermsLocationThe location of ChargeTerms element. Currently accepted: { BeforePay, AfterPay }
availableCardBrandsstring[] or CreditCardTypeCardBrandId[]The сard brands for which icons will be displayed on the form as card payment methods. Currently accepted: {american-express, discover, jcb, maestro, mastercard, unionpay, visa}
requiredFieldsBehaviorIRequiredFieldsBehaviorConfiguration of the display of required fields for the user to manage the user's focus on them
requiredFieldsBehavior.showStarsbooleanShow the stars on labels of required fields
requiredFieldsBehavior.buttonStateUntilCorrectstringIf 'disabled', the payment buttons remain disabled until the user fills in all the required fields. If 'enabled', then when one of the buttons is pressed (the buttons are enabled), the required fields will be marked as invalid (red color) for the user. If 'hidden-enabled', then when one of the buttons is pressed (the buttons are enabled but have styles as disabled), the required fields will be marked as invalid (red color) for the user. Current accepted: { enabled, disabled, hidden-enabled }
requiredFieldsBehavior.markAsInvalidUntilCorrectbooleanIf true, then all unfilled or incorrectly filled required fields will initially appear as invalid (red color) to the user until they are filled and correct. If the value is false, the required fields will only be shown as invalid in the event that the user presses the payment button when the buttons are enabled
userPreferencesIUserPreferencesSettingsThe user preferences section
userPreferences.visiblebooleanWhether to show the user preferences
userPreferences.textstringThe text of user preferences. For example, description of autorefill plan
userPreferences.checkboxesIUserPreferenceCheckbox[]The text of user preferences. For example, description of autorefill plan

ILink interface:

interface ILink {
    text: string;
    href: string;
}

ITermCheckbox interface:

interface ITermCheckbox {
    text: string;
    link?: ILink;
}

IUserPreferenceCheckbox interface:

interface IUserPreferenceCheckbox {
    name: string;
    text: string;
    link?: ILink;
    defaultValue?: boolean;
}

Example of merchantInfo:

merchantInfo: {
  "visible": true,
  "text": "The vendor prides itself on designing and implementing state-of-the-art payment infrastructures that cater to a wide range of commercial activities. Specializing in the creation of robust payment processing platforms, the merchant provides tailored solutions that support the dynamic needs of the global market",
  "links": [
    {
      "text": "Terms",
      "href": "https://www.google.com/"
    },
    {
      "text": "Policy",
      "href": "https://www.google.com/"
    }
  ]
}

Example of chargeTerms:

chargeTerms: {
  "visible": true,
  "text": "By checking this box, I am affirming my full and complete understanding of, as well as my agreement to, all the terms and conditions that were previously presented to me, acknowledging that they form a binding contractual agreement.",
  "checkboxes": [
    {
      "text": "I hereby agree to the conditions previously outlined.",
      "link": {
        "text": "Link to the application",
        "href": "https://www.google.com/"
      }
    },
    {
      "text": "I validate the foregoing stipulations.",
      "link": {
        "text": "Google",
        "href": "https://www.google.com/"
      }
    }
  ]
},

Example of userPreferences:

"userPreferences": {
  "visible": true,
  "text": "By checking this box, I am affirming my full and complete understanding of, as well as my agreement to, all the terms and conditions that were previously presented to me, acknowledging that they form a binding contractual agreement.",
  "checkboxes": [
    {
      "name": "autoFill",
      "text": "Do you want to auto refill? Check this.",
      "link": {
        "text": "Refill policy",
        "href": "https://www.google.com/"
      }
    },
    {
      "name": "isGood",
      "defaultValue": true,
      "text": "Do you want to mark this as good? Check this.",
      "link": {
        "text": "Link to the application",
        "href": "https://www.google.com/"
      }
    }
  ]
}

Output events

EventTypeDescription
closevoidtriggered by clicking on the closing icon
paidPayment Resulttriggered after receiving a payment response

Payment Result Structure

IPaymentResponse {
    action?: {
        name: string;
        data: IThreeDsData | IRedirectData | any;
    }
    ip: string;
    merchant: string;
    order: {
        invoiceId: string;
        details: string;
    }
    payment: {
        paymentId: string;
        state: PaymentState; //on of strings: completed, rejected, needAction
        rebillAnchor: string;
        info: {
            completeProcessingTime?: Date;
            currency: string;
            paymentType: string;
            paymentSystem: string;
            paymentRequisites?: string;
            price: number
        }
        rejectionDetails?: {
            hardDecline: boolean;
            message?: string;
            problemSolvingTips: string[];
            rejectionCode: number;
        }
    }
    taxInfo: {
        abbreviation: string;
        price: number;
        priceNet: number;
        tax: number;
    }
    user: {
        id: string;
    }
    signature: string;
}

IThreeDsData {
  paReq: string;
  acsurl: string;
  termUrl: string;
  md: string;
}

IRedirectData {
    location: string;
}

Webpack 5 Issues

During the integration process, you might face multiple issues with webpack 5. This issue is caused due to the fact that some packages have certain dependencies, which are not present within the browser environment by webpack 5. Hence, you require certain node polyfills to be added to your project, while overriding the configurations to enable their usage. When that is done, your project should run without any issues.

1.0.16

4 days ago

1.0.16-rc.2

9 days ago

1.0.16-rc.1

9 days ago

1.0.16-rc.0

22 days ago

1.0.15

22 days ago

1.0.15-rc.1

24 days ago

1.0.15-rc.0

24 days ago

1.0.14-rc.3

26 days ago

1.0.14

26 days ago

1.0.14-rc.2

28 days ago

1.0.14-rc.1

30 days ago

1.0.14-rc.0

30 days ago

1.0.13

2 months ago

1.0.12

2 months ago

1.0.12-rc.0

2 months ago

1.0.11

2 months ago

1.0.11-rc.1

2 months ago

1.0.11-rc.0

2 months ago

1.0.10

3 months ago

1.0.10-rc.4

3 months ago

1.0.10-rc.3

3 months ago

1.0.10-rc.2

3 months ago

1.0.10-rc.1

4 months ago

1.0.10-rc

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.8-beta.0

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago