đSteps to Support Basic Payment Forms with your Custom Payment Gateway
Pre-Requisites
đģBuilding a Custom Payment GatewayđĄAbout Basic Payment FormsBasic Payment Form Support
The payment flow will look for code in your set Custom Payment Gateway Partial Path. The file it's looking for is {{Custom Payment Gateway Partial Path}}/basic_payment.liquid
(e.g. modules/my_ecommerce/payment_gateways/money_take/basic_payment
)
Your code will be included inside the Form - where in the Form Layout you see the tag
<div data-gb-custom-block data-tag="-" data-0='ecommerce/basic_payment' data-1=', amount: ' data-2='500' data-3='500' data-4=', currency: '></div>
To access information about your custom Payment Gateway such as the API Keys, you can output {{payment_gateway}}
into the layout.
When building you layout consider the following process that needs to be take place.
Step 1) Set up Client Side Code on Page Load
Initially set up any Client-side HTML or JavaScript which the Payment Gateway requires to be rendered on Page Load. E.g. elements for securely entering card details.
Step 2) Define a Payment Function to run after Form Validation
Define a JavaScript function which will set up and carry out the payment transaction. Depending on the complexity of your Payment Gateway, this may include multiple steps.
You should assign this function to window.s_e_payment = my_payment_function
. The Siteglide Form will call this function when validation is complete and it is ready to begin the payment.
The function definition should return a JavaScript Promise - this will allow the Siteglide Form Submit function to wait for the payment to finish, before it continues submitting the Form.
Your function definition can use the parameter form
- this contains the DOM element for the Form which has been submitted. This will be used in the JS selectors in the next step to make sure we target the DOM in the correct Form where more than one Form is present on the Page.
All of the following information is available in the HTML DOM and therefore is also accessible via JavaScript.
The parameter form
from the previous step is used for specificity.
See the next step r.e. checking the amount on the Server Side.
Field | JavaScript Selector | Purpose/Notes |
Amount |
| The amount of money the customer intends to pay. For Basic Payment Forms, this value is editable on the Client Side. If you need the original Minimum Amount defined against the Form, run a server -side check. |
Currency |
| The currency the customer intends to use. If you need the original currency set up against the Form, use a server-side check. |
Form Configuration ID |
| This Form Configuration ID can be sent to your own Liquid XHR endpoint and used in a GraphQL query to confirm the details of this Form. |
Step 3) Check the Minimum Value is Met
Siteglide Basic Payment Forms have a "Minimum Value" defined in the Form Structure. This can be used in two ways:
As the actual value of products or services
When the User is choosing their own price e.g. a donation Form, the minimum price the Client will accept in order to not make a loss on the donation when the Payment Gateway's fees are paid.
All of our native Payment Gateways include a server-side check to make sure the amount is met- so most likely you'll wish to do the same.
In order to do this- your Payment Gateway should make a request to a Liquid Page you create. The Form Configuration ID and Amount should be sent over in your data payload or query parameters.
The Endpoint Page should run an admin_form_configurations
query:
In the results of this query, you'll be able to verify the true minimum amount and currency. You can compare these to the s_e_amount value calculated on the Front-end. Depending on the result_name you choose - the values from this example query of note are:
On this endpoint, you'll have secure access to these values, so it might make sense to use this same endpoint to:
send an API call to your Payment Gateway to set up a Payment Intent (or complete Payment Transaction).
run a GraphQL mutation to create a "module_14/payment" model in the database, (with a status of "Intent Created" or "Payment Complete" as appropriate) (see below)
Step 4) Create a Record of the Payment in Siteglide
In order for the Client to see a record of the Payment in the Siteglide Admin, you must:
Create a database object with the model_schema_name of module_14/payment.
Via the JavaScript in your Payment function, store the ID of this newly created Payment Model in the hidden HTML field #s_e_order_id. This way it will be submitted with the Form and a relationship will be established between the Payment and the Case- allowing their information to be linked in the Admin.
Depending on the complexity of your Payment Gateway, you may wish to:
Create the Payment Model at the same time a Payment Intent is created with the status Intent Created. After capturing funds in a later step, you may wish to update the same model by referring to it by its ID, this time giving it the status Payment Complete.
Create the Payment Model at the end of the Payment process- to confirm its success. This would immediately be given the status Payment Complete.
The key fields you will need to set on the Payment Model are shown in the following table:
Field Name | Field ID | Purpose / Notes |
---|---|---|
Payment ID | module_field_14/payment_1 | The Payment Gateway's ID for this Payment Intent |
Gateway ID | module_field_14/payment_2 | Optional - The ID of the Payment Gateway in Siteglide that handled this payment. |
Gateway Type | module_field_14/payment_4 | Optional - The type of the Payment Gateway in Siteglide that handled this payment. |
Status | module_field_14/payment_5 | The status of this Payment: Intent Created, Payment Complete or a custom Status of your choice. |
Charge ID (Stripe), Capture ID (PayPal) or use for a similar purpose in another Payment Gateway. | module_field_14/payment_6 | Optional |
Currency | module_field_14/payment_7 | The actual currency used. |
Amount | module_field_14/payment_8 | The actual amount to be paid. |
Step 5) Resolve any Errors
To halt both your Payment Function and Form Submission and throw errors to the User, you'll need to resolve your Payment Function's promise with an object containing an errors property - an array of objects, each with a message String property.
Note, your Promise should not include a reject, as this will not be used.
Step 6) Resolve your Payment
Once your my_payment_function payment function is complete and the funds have been captured, you will want to let the Siteglide Form Submit Function finish submitting the Form. To do this, resolve the Promise (without an errors object):
Last updated