Accept Payments
To facilitate payment acceptance, you can initiate a transaction through our API, our client JavaScript library, Popup JS, or our SDKs. Each transaction will generate a unique link that enables users to finalize the payment process seamlessly.
Popup
Lahza Popup offers a user-friendly and hassle-free payment flow designed for web applications. Integrating it into your platform is a breeze and can be accomplished in just five simple steps, making it the most straightforward method to begin accepting payments.
Collect customer information
To initialize the transaction, you need to pass information such as email, mobile, amount, transaction reference, etc. The key
, email
,mobile
and amount
parameters are the only required parameters. The table below lists the parameters that you can pass when initializing a transaction.
key
Yes
Your public key from Lahza. Use test key for test mode and live key for live mode
No
Email address of customer
mobile
No
Mobile number of customer
firstName
No
First name of the customer
lastName
No
Last name of the customer
amount
Yes
Amount (in the lowest currency value - agora, cents) you are debiting customer.
ref
No
Unique case sensitive transaction reference. Only -,., =and alphanumeric characters allowed. If you do not pass this parameter, Lahza will generate a unique reference for you.
currency
No
Currency charge should be performed in. Allowed values are: ILS
, JOD
or USD
It defaults to your integration currency.
channels
No
An array of payment channels to control what channels you want to make available to the user to make a payment with. Available channels include; ['card', 'bank', 'ussd', 'qr', 'mobile_money', 'bank_transfer']
metadata
No
Object containing any extra information you want recorded with the transaction. Fields within the custom_field
object will show up on merchant receipt and within the transaction information on the Lahza Dashboard. You can learn more on the Metadata page.
label
No
String that replaces customer email as shown on the checkout form
onSuccess
No
Function that runs when payment is successful. This should ideally be a script that uses the verify endpoint on the Lahza API to check the status of the transaction.
onCancel
No
Javascript function that is called if the customer closes the payment window instead of making a payment.
In this sample, notice how:
The Lahza inline javascript is included using a
script
tag. This is how you import Lahza into your code.The amount here can be hardcoded if you want to charge a specific amount.
The
Pay
button has been tied to anonClick
function calledpay
. This is the action that causes the Lahza popup to load.
If you don't collect customer email addresses, you can generate email addresses using the available information (e.g., phone numbers) along with your website URL.
Handle the callback method.
The callback method is fired when the transaction is successful. This is where you include any action you want to perform when the transaction is successful.
The recommended next step here is to verify the transaction to confirm the status.
To verify a transaction, you need to set up a server route or page where you pass the transaction reference. From your server, you can call the Lahza verify endpoint to check the status of the transaction. The response from the verification is then returned to your frontend for further processing.
There are 2 ways you can call your server from the callback function
Make an AJAX request to the endpoint on your server that handles the transaction verification
Redirect to the server URL by setting a
window.location
to the URL where the verification endpoint is set on your server.
For security reasons, it is essential to never directly call the Lahza API from your frontend. This prevents exposing your secret key on the client-side. Instead, all requests to the Lahza API should be initiated from your server. Your frontend can then receive the response from your server, ensuring the confidentiality of your secret key. This practice helps maintain the integrity of your payment system and safeguards sensitive information.
Verify the Transaction
After payment is made, the next step is to verify the transaction. Here's how to verify transactions with Lahza.
Handle Webhook
When a payment is successful, Lahza sends a charge.success
webhook event to your webhook URL. You can learn more here.
Redirect
Here, you call the Initialize TransactionAPI from your server to generate a checkout link, then redirect your users to the link so they can pay. After payment is made, the users are returned to your website at the callback_url
Please ensure that your server is capable of establishing a TLSv1.2 connection with Lahza's servers. The majority of modern software supports this capability. If you encounter any SSL errors, it is recommended to contact your service provider for guidance and assistance in resolving the issue.
Initialize transaction
To initiate a transaction, follow these steps:
When a customer clicks the payment action button, send a POST request to our API to initialize the transaction. Include parameters such as email, amount, and any other required fields in the request to the Initialize Transaction API endpoint.
Upon a successful API call, we will provide you with an authorization URL. Redirect the customer to this URL to allow them to input their payment information and complete the transaction.
Important notes:
Ensure that the amount field is converted to the lowest currency unit. Multiply the value by 100 to obtain the correct amount. For example, if you want to charge ULS50 or $50 or JOD50, multiply 50 by 100 and pass 5000 in the amount field.
You should utilize a unique transaction identifier from your own system as the reference.
If you wish to customize the callback URL for the transaction, set the callback_url in the transaction_data array. If not specified, we will use the callback URL set on your dashboard. Specifying the callback URL in the code allows you to be flexible with the redirect URL if necessary.
If you do not set a callback URL on either the dashboard or in the code, users will not be redirected back to your site after completing the payment.
For test transactions, you can set test callback URLs, while for live transactions, use live callback URLs. This distinction allows you to differentiate between test and live environments effectively.
Verify Transaction
If the transaction is successful, Lahza will redirect the user back to a callback_url
you set. We'll append the transaction reference in the URL. In the example above, the user will be redirected to http://your_website.com/callback.php?reference=YOUR_REFERENCE
.
So you retrieve the reference from the URL parameter and use that to call the verify endpoint to confirm the status of the transaction. Learn more about verifying transactions.
It's very important that you call the Verify endpoint to confirm the status of the transactions before delivering value. Just because the callback_url
was visited doesn't prove that transaction was successful.
Handle Webhook
When a payment is successful, Lahza sends a charge.success
webhook event to webhook URL that you provide. Learn more about using webhooks.
Mobile SDKs
You can integrate Lahza directly into your Android or iOS app using our mobile SDK. For mobile frameworks like Ionic or React Native, please find the libraries here.
Last updated