Tap Payment API Integration in PHP involves several steps, including setting up your Tap Payments account, creating a payment form, and handling the API requests. In this article, we will explore how to integrate Tap Payment’s API into a PHP web application. Tap Payment is a leading payment gateway in the MENA region that allows businesses to accept online payments securely. It supports various payment methods, including credit and debit cards, Knet, and more, making it an ideal choice for businesses looking to expand their reach in the Middle East.

The Tap Payment API enables developers to integrate this payment gateway into their applications, whether it’s an e-commerce website, mobile app, or any digital platform that requires online payments. We will provide step-by-step instructions and include source code examples to help you get started.

  • Step 1: Install Required Packages

    The first step in integrating Tap Payment into your PHP application is to install the necessary packages. You’ll need to install the official Tap Payment PHP SDK, which simplifies the integration process.
    Open your command line terminal and navigate to your project directory. Then, run the following command to install the Tap Payment SDK via Composer:

    Copy to Clipboard

    This command will download and install the Tap Payment PHP SDK in your project.

  • Step 2: Obtain API Credentials

    To use the Tap Payment API, you need to obtain your API credentials from the Tap Payment dashboard. These credentials include your API Key and Secret Key.

    If you don’t have a Tap Payments account yet, please visit the official Tap Payments website at https://www.tap.company/. Sign up for an account with Tap Payments. Please log in to your Tap Dashboard with your login information. Then, go to the “goSell” section, select “API Credentials,” and click “Generate Key” to access the secret keys for your preferred mode.

    Make sure to keep your API credentials secure, as they are sensitive and should not be shared publicly

  • Step 3: Set Up Your PHP Application

    Create a new PHP file in your project, e.g., index.php, and include the Tap Payment SDK at the beginning of the file

    Copy to Clipboard
  • Step 4: Initialize the Tap Payment SDK

    To initialize the Tap Payment SDK, you need to provide your API credentials. Add the following code to your PHP file, replacing 'YOUR_API_KEY' and 'YOUR_SECRET_KEY' with your actual Tap Payment API credentials:

    Copy to Clipboard

    This initializes the SDK with your API credentials, allowing you to make requests to the Tap Payment API.

  • Step 5: Create a Payment Request

    Before processing a payment, you need to create a payment request. The request should include the amount to be charged, currency, and any additional information about the payment.

    Copy to Clipboard

    You can customize the payment request based on your requirements, such as including product details or other relevant information.

  • Step 6: Create a Payment Charge

    Now that you have your payment request prepared, you can create a payment charge using the createCharge method of the Tap Payment SDK. Here’s how to do it:

    Copy to Clipboard

    This code attempts to create a payment charge and handles both successful payments and payment errors. If the payment is successful, it will display the payment ID and status. If there’s an error, it will show the error message.

  • Step 7: Handle Webhooks (Optional)

    Tap Payment provides webhooks to notify your application about payment events, such as successful payments, refunds, and chargebacks. While handling webhooks is optional, it’s a good practice to ensure that your application stays updated with the latest payment status.

    To handle webhooks, you need to set up a route or endpoint in your PHP application to receive Tap Payment webhook notifications. You can use a framework like Laravel or create a simple PHP script to handle incoming webhook requests.

    Copy to Clipboard

    In the webhook endpoint, you should validate the authenticity of the incoming webhook using the secret key you received from Tap Payment. This validation helps ensure that the webhook request is legitimate.

    Here’s an example of how to set up a webhook endpoint to handle Tap Payment notifications:

  • Step 8: Test Your Integration

    Testing is a critical part of the integration process to ensure that your application interacts with the Tap Payment API as expected. Tap Payment provides a sandbox environment for testing, allowing you to make test payments without actual money.

    To test your integration, you can use the Tap Payment test card details provided in the Tap Payment documentation. These test cards allow you to simulate different payment scenarios, such as successful payments, declined payments, and 3D Secure verifications.

    Payment MethodCard Number3D Secure EnrolledExpiry DateCSC/CVV
    MasterCard5123450000000008YesYesYes
    MasterCard5111111111111118NoYesYes
    Visa4508750015741019YesYesYes
    Visa4012000033330026NoYesYes
    American Express345678901234564YesYesYes
    American Express371449635398431NoYesYes
  • Step 9: Go Live

    Once you’ve thoroughly tested your Tap Payment API integration in PHP in the sandbox environment and everything works as expected, you can switch to the production environment to accept real payments from your customers.