Payments

Form Configuration

34min

Overview

Here is a list of acceptable configuration values/options for the form.

Element (required)

The element must be a valid CSS selector for the target element for the form to be mounted. Or can be an instance of a DOM element Element. Here is an example:

JS


Language (optional)

This option can be used to set the display language for the form. If left empty, language will be inferred from <html> element then fallback to en if it can't be inferred. Here is an example:

JS


Translations (optional)

This option is used to add more translations to the form. Here is an example:

JS


Publishable API Key (required)

The publishable API key is required in order to communicate with Moyasar's API and complete the payment request. Here is an example:

JS


Payment Methods (optional)

This is used to enable and disable payment methods on the form. By default, all the methods are enabled, which are:

  • Credit Card (creditcard)
  • Apple Pay (applepay)
  • stc pay (stcpay)
JS


Amount (required)

This sets the amount for the user to pay. The amount must be in a minor unit of selected currency, e.g. if we want to get a payment of $10 then we must represent the amount in cents 1000.

JS


Currency (required)

This sets which currency is used for the amount to be paid.

JS


The currency must be in ISO 3166-1 alpha-3 country code format.

Description (required)

This option is used to set a description to be sent along with other payment information to Moyasar's API.

JS


The description can be any string you want.

Callback URL (required)

This URL is used by Moyasar to redirect the user back after the payment is either successful, or the user has completed the 3D Secure stage.

JS


Metadata (optional)

Adds searchable key/value pairs to the payments.

JS


Supported Networks (optional)

This optional configuration option is used to set accepted card networks in the form.

The default value is all networks except amex.

Supported Networks:

  • Mada (mada)
  • Visa (visa)
  • Mastercard (mastercard)
  • American Express (amex)
JS


Fixed Width (optional)

This option is used to limit the form width to only 360px and it is enabled by default.

To disable this just set it to false.

JS


On Initiating (optional)

This callback is used to handle the event when a user starts a payment method and before any information is sent to Moyasar's API. You can use this to perform any last-second validations or to prepare something.

When you handle this event, you can return a false to stop the payment process, or a dictionary that is either empty or contains a description or callback_url values to update the form configurations if you need to.

If you need to do a long-running process, you can return a Promise that returns either of the mentioned values before.

Here is an example to stop the form from submitting:

JS


Using a Promise:

JS


Make the form proceed:

JS


Using a Promise:

JS


On Completed (optional)

This event is fired when a payment is created by Moyasar's API. You can intercept the payment to save it or do any other processing.

This option can either take a URL and the payment object will be posted to.The endpoint must return 201 for the form to proceed, or the form will be aborted.

You can also provide a callback that returns a void or a Promise if you need a long-running task.

JS


Using a Promise:

JS


On Failure (optional)

This event is used to handle payment failure, you will get a stringif there is an error.

JS


On Redirect (optional)

When the form finishes its work and is about to redirect the user, you can intercept this action and handle redirection manually. Here is an example:

JS


Tokenize (Save) Credit Card (optional)

This option allows you to tokenize credit card information after successfully completing the transaction.

JS


Manual Payments (optional)

This option allows you to only authorize payments without capturing them. To capture the payment, you need to make an API call to the capture endpoint later on. Please review the API section for more details.

JS


Statement Descriptor

Allows the merchant to add a statement descriptor for the payment that will show in the card statement.

JS


Apple Pay Configurations (Required)

Only required if apple pay is enabled.

This is an object that contains Apple Pay specific configurations. Here is an example:

JS


Version (optional)

This is used to specify the Apple Pay JS version. The default is 6. Here is an example:

JS


Country (required)

Apple Pay merchant country.

JS


Merchant Capabilities (optional)

Merchant capabilities to activate this Apple Pay session. Default is:

JS


Label (required)

Label to be displayed in the payment modal.

JS


Merchant Validation URL (required)

This URL is used to initiate the Apple Pay session. A POST request will be made to the specified endpoint with a JSON object containing the URL.

Here is the JSONsnippet:

JSON


The endpoint must return a response with the header Content-Type: application/json and the session object obtained from Apple.

Here is the configuration example:

JS


In order to perform merchant validation, you need to register for an apple developer account and sign up for the Apple Developer program.

Now you must use the provided URL to perform the merchant validation.

Supported Countries (Optional)

An array of countries that cards are allowed from.

Default: ['SA']. Only Saudi Arabia is enabled by default to prevent fraudulent transactions, you may enable more countries at your own risk.

JS


Advanced Integration

If the form does not satisfy your needs, you can always build your own integration solution, and try our manual integration.

Updated 01 Feb 2024
Did this page help you?