🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!

Gravity Forms Moyasar Premium Add-on Setup Guide

Updated 9 min read Gravity Forms Integrations A–Z
On this page
  1. What you need
  2. Install and activate
  3. Connect your Moyasar account
  4. Webhooks
  5. Add a feed to your form
  6. How a payment works
  7. Refunds
  8. Subscriptions
  9. Test and live mode
  10. For developers
  11. Troubleshooting
  12. Privacy

The Gravity Forms Moyasar Premium Add-on takes payments in Saudi Arabia with your forms through Moyasar. When a visitor submits the form, the add-on creates a Moyasar invoice for the exact total Gravity Forms worked out on the server and sends the visitor to the hosted Moyasar invoice page. The visitor pays there with mada, a card, Apple Pay, STC Pay or another method of your Moyasar account, so card details never reach your website. Before an entry changes, the add-on reads the invoice and the payment back from Moyasar and checks the invoice, your reference, the amount, the currency and the status.

Saudi Arabia and riyals

Moyasar is a payment gateway for businesses in Saudi Arabia, and this add-on charges in Saudi riyals (SAR) by default, sending amounts in halalas. Set the Gravity Forms currency to Saudi Riyal (the add-on adds it to the Gravity Forms list when it is missing). Your customers pay on the Moyasar invoice page with the methods your Moyasar account offers there, such as mada, Visa, Mastercard, Apple Pay and STC Pay. If Moyasar has enabled multi-currency on your account, AED, QAR, USD, BHD and KWD work too (card payments only).

This guide covers the setup, the feed, payments, webhooks, refunds and going live. The add-on costs one site $49 a year, five sites $69 a year, unlimited sites $199 a year.

What you need

  • WordPress 6.5 or newer, PHP 7.4 or newer (with the openssl extension) and Gravity Forms 2.9 or newer.
  • A Moyasar account. Test mode is available right away; live payments start when Moyasar has activated your account.
  • The secret key of each mode (sk_test_ and sk_live_), from Settings → API Keys in the Moyasar dashboard.
  • The Gravity Forms currency set to Saudi Riyal.
  • Your site public and on HTTPS, so Moyasar can reach the webhook address.
  • A form with at least one product field or a total.

The add-on talks to the Moyasar API (api.moyasar.com/v1) to create invoices, read invoices and payments back, refund payments and register the webhook. No Moyasar script is loaded on your pages: the customer is redirected to the invoice page. Apart from that, the add-on checks gravityextra.com for your licence and plugin updates.

Install and activate

  1. Upload the zip in Plugins → Add New → Upload Plugin and activate it.
  2. Open Forms → Settings → Moyasar, enter your GravityExtra licence key and press Activate License.
  3. The Moyasar sections appear once the licence is active. Payments, webhooks and refunds work only with an active licence.

Connect your Moyasar account

Moyasar settings: test or live mode, the secret key of each mode, the payment window, the Saudi riyal currency line and the account-ready line with a masked sk_test_ key
Settings: choose test or live mode and paste the secret key from Settings, API Keys in the Moyasar dashboard. Keys are stored encrypted.
  1. Leave Mode on Test for now.
  2. In the Moyasar dashboard, open Settings → API Keys and copy the test secret key (it starts with sk_test_) into the Test secret key field.
  3. Optional: set a payment window in hours (1 to 720). It decides how long the invoice page can be paid. Empty means 72 hours.
  4. Save. The Account line turns green with a masked key. The key is stored encrypted and never shown again.
  5. The Currency line confirms that your forms use SAR.
Setting Used for
Secret key (per mode) Creating each invoice, reading invoices and payments back, refunds and registering the webhook, on your server only
Payment window How long the invoice page can be paid (the invoice expires after that)
Webhook secret token (per mode) Checking that every webhook comes from your Moyasar webhook

Webhooks

Moyasar reports payments to a webhook address. The quickest way is the button Register the test webhook in Moyasar in the Webhooks section: the add-on registers the address with your secret key, for the events payment_paid, payment_failed, payment_refunded, payment_voided and payment_captured, with a new random secret token that it saves encrypted. Do the same for live mode later. The same address serves both modes.

You can also add the webhook yourself in the Moyasar dashboard under Settings → Webhooks: paste the address, choose HTTP method POST, type a secret token of 16 characters or more, pick the events and paste the same token into the add-on. Every webhook Moyasar sends carries that token, and the add-on compares it in constant time; webhooks without the right token are refused.

Every webhook is checked, then verified with Moyasar

Even a webhook with the right token is only a hint: the add-on reads the invoice and the payment back from Moyasar with your secret key and compares the invoice, your reference, the amount in halalas, the currency and the status before the entry changes. A webhook of the other mode, or for an invoice that is not the current one of the entry, is never applied. The invoice also has its own notification address, signed per entry, and it works the same way.

Add a feed to your form

The Moyasar feed: products and services with the form total, the invoice description with merge tags and the option to send notifications only after payment
The feed: choose the amount and write the invoice description the customer sees on the Moyasar page.
  1. Open the form, then Settings → Moyasar → Add New.
  2. Choose Products and Services and usually the Form Total.
  3. Set the invoice description. It is shown on the Moyasar invoice page next to the amount. Merge tags work, for example Booking #{entry_id}.
  4. Keep Send form notifications only after the customer has paid ticked, so your booking emails go out for paid entries only.

No customer details are mapped: the invoice needs only the amount and the description, so the add-on sends Moyasar no names or email addresses.

A calligraphy workshop booking form with name, email, workshop places and starter kits with quantities, the total in Saudi riyals and the Continue to payment button
The form your customer fills in. Card details are entered on the Moyasar invoice page, not here.

How a payment works

  1. The visitor submits the form. Gravity Forms works out the total on the server, and the add-on creates a Moyasar invoice for that amount in halalas, with your reference in the metadata, the return address, a signed notification address and the payment window.
  2. The visitor goes straight to the Moyasar invoice page to choose a method and pay.
  3. Moyasar sends a webhook. The add-on checks the secret token, reads the invoice and the payment, and marks the entry Paid only when Moyasar reports the invoice paid and the invoice, reference, amount and currency match.
  4. Moyasar sends the visitor back to your form page. The return page also reads the invoice; if there is no result yet, it waits and checks again by itself, then shows your confirmation.
  5. A payment is never completed twice, however many webhooks or returns arrive.
What Moyasar reports Entry
Invoice paid Paid, with the invoice, the payment and the method (for example “Card mada •••• 1010”) in the notes
Invoice initiated, a payment in progress (3-D Secure, STC Pay code) Pending; it updates when Moyasar reports the result
Invoice initiated, no payment yet, or only a failed attempt Stays Processing: the invoice page still takes payments, and a failed attempt is noted
Invoice expired, canceled or failed Failed: nothing was charged, and the customer gets a link to try again with a new invoice
Payment refunded (in full or in part) Refunded or Partially Refunded, each refund booked once
Payment voided Voided

When a card is declined on the invoice page, the invoice stays open and the customer can try another card or method right there; the failed attempt is noted on the entry. When the invoice expires or is canceled, your form page says that nothing was charged and offers Try the payment again. The add-on then creates a new Moyasar invoice for the same amount. A webhook about the earlier invoice is not applied to the entry.

Refunds

An entry paid with mada through Moyasar and partly refunded: the Moyasar box with the status, invoice, payment, card, Moyasar status, amount, refunded amount and the refund form
The entry after payment: status, Moyasar invoice and payment, the method, and refunds from the entry screen.

Open a paid entry. The Moyasar box shows the status, the invoice, the payment, the method, the Moyasar status and the amounts. Type an amount in riyals and press Refund. The add-on first reads the payment (it must be paid or captured and belong to the invoice of the entry), then sends the refund, reads the payment again and books the new refunded amount: the entry becomes Partially Refunded or Refunded. Refund all of it at once or part of it in several steps, up to the amount paid. Each refund request can be sent only once.

Refunds and voids you make in the Moyasar dashboard arrive as webhooks and are booked on the entry after the add-on has read and checked the payment. Moyasar can void a paid payment within about two hours, which releases it without a refund; after that, use a refund. For accounts using aggregation, Moyasar needs enough balance to cover a refund.

Subscriptions

Subscriptions are not offered. Moyasar charges saved cards with tokens that are created from a card form on your own page (Moyasar’s JavaScript form), and this add-on keeps payments on the hosted invoice page. Each form submission is one payment.

Test and live mode

  • In test mode, entries are marked as test payments and no money moves. Pay with the test cards in the Moyasar documentation.
  • For live payments, paste the live secret key, register the live webhook, choose Live and save.
  • Make one small real payment and refund it from the entry.
  • Entries remember the mode they were paid in; webhooks and refunds use the key of that mode, and a webhook of the other mode never changes an entry.

For developers

The invoice request can be adjusted with gravityextra_moyasar_invoice_body (for example extra metadata), and the webhook address with gravityextra_moyasar_webhook_url. The amount and the currency always come from the entry, and the reference, the amount and the currency are checked again when the invoice is read back.

// Add the customer's email to the Moyasar invoice metadata for one form (ID 7).
add_filter( 'gravityextra_moyasar_invoice_body', function ( $body, $feed, $form, $entry ) {
    if ( 7 !== (int) rgar( $form, 'id' ) ) {
        return $body;
    }
    $meta = array_merge( (array) rgar( $body, 'metadata' ), array( 'customer_email' => (string) rgar( $entry, '2' ) ) );
    return array_merge( $body, array( 'metadata' => $meta ) );
}, 10, 4 );

Troubleshooting

What you see What to do
“This is a publishable key (pk_)” Paste the secret key (it starts with sk_test_ or sk_live_) from Settings → API Keys in the Moyasar dashboard. The publishable key is for card forms on your own page and is not used.
“This key belongs to the other mode” Each field takes the key of its mode: sk_test_ in the test field, sk_live_ in the live field.
“Online payment is not available in EUR” Moyasar charges Saudi riyals (and a few Gulf currencies with multi-currency). Choose Saudi Riyal in Forms → Settings.
“The smallest amount that can be paid online is SAR 1.00” Moyasar invoices start at 100 halalas. Check the prices and quantities of the form.
Webhooks of a mode are refused Save the secret token of that mode, or press the button that registers the webhook and saves a new token for you. The token in the add-on and in the Moyasar webhook must be the same.
The customer returns but the entry stays Processing The customer has not paid yet. The return page checks again by itself, and the entry updates when the webhook arrives. Check that the webhook is registered for the mode you use.
“Insufficient balance” when refunding For accounts using aggregation, Moyasar needs enough balance to cover the refund. Try again later or refund from the Moyasar dashboard.

If an entry stays Processing although the customer paid, open it and press Check the payment with Moyasar in the Moyasar box: the add-on reads the invoice and updates the entry.

Privacy

The add-on sends Moyasar the amount, the currency, the invoice description, the entry and form numbers and your reference. Card details are entered on the Moyasar page and never reach your site. The secret keys and webhook tokens are stored encrypted with keys from your site’s WordPress salts. Uninstalling the add-on removes its settings, including the keys.

Still need help?

Our support team answers tickets every day, usually within a few hours.

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr