Skip to main content

PHP

Learn how to work with Dojo's PHP SDK for the Dojo Payments API.

Packagist

The Dojo.PHP is the official Dojo PHP library, supporting the Dojo API. To start using the Dojo PHP SDK:

Installing the SDK

To install the Dojo PHP library, you'll need Composer. If you don't have it installed, make sure to set it up first. Here's how to install the Dojo PHP SDK:

  1. Get the SDK package from Packagist.
  2. Install the package using Composer with the following command:
composer require dojo/dojo-php

Building the source code

To build the Dojo PHP SDK, ensure you have PHP 7.4 or higher installed. Alternatively, use the VSCode devcontainer for a more streamlined development experience.

Do the following:

  1. Run:
composer install
  1. From the root of the repository, execute the script:
/build/generate-openapi.sh
  1. Copy all files from /generated/src into /src

Using the PHP SDK to create a payment intent

Create a client for the payment intent, using your API key:

use Dojo_PHP\ApiFactory;
$apiKey = "YOUR_API_KEY";
$client = ApiFactory::createPaymentIntentApi($apiKey);

In this step, you create a new payment intent request object. This request object will hold the details of the payment intent that you want to create.

$req = new CreatePaymentIntentRequest();

Set a reference for the payment intent (e.g., an order number or unique identifier):

$req->setReference("test");

Create a Money object to specify the amount and currency

$money = new Money();

Set the amount to 100 in the specified currency, in minor units.

$money->setValue(100); 

Set the currency code (for example, GBP for British Pounds).

$money->setCurrencyCode("GBP"); 

Set the amount in the request: The $money item in this example should also be written in minor units.

$req->setAmount($money);

Use the client to create the payment intent by making a request to the payment gateway. The paymentIntentsCreatePaymentIntent method is called with the provided API version and the payment intent request object:

$paymentIntent = $client->paymentIntentsCreatePaymentIntent(\Dojo_PHP\API_VERSION, $req);

The $paymentIntent now contains the information about the created payment intent.

For any requests, bugs, or comments, please open an issue or submit a pull request.