API client for ThePay - payment gate API

Overview

PHP SDK for ThePay.cz

This is the official highly compatible public package of The Pay SDK which interacts with The Pay's REST API. To get started see examples below.

Requirements

  • PHP 5.3+
  • curl extension
  • json extension

Installation

To install the SDK we recommend to use Composer:

composer require thepay/api-client

Preconditions

Make sure that you have all required credentials and that you've set up the API access in administration:

  • merchant ID
  • project ID
  • password for API access
  • enabled your IP address in project settings (you have to add IP address or IP address range of your server)

To test the integration you can create simplified "ready-to-go" DEMO account in our DEMO environment.

You can find all the necessary credentials in "Implementation" section under your merchant profile:

Usage

You will work with only two classes when using this SDK.

  • TheConfig - for setting up the library
  • TheClient - for main functionality (calling the API, rendering helpers)

Configuration

All constructor parameters are described in php doc

$config = new ThePay\ApiClient\TheConfig(
    $merchantId,
    $projectId,
    $apiPassword,
    $apiUrl,
    $gateUrl
);

$config->setLanguage($language);

Usual workflow

There are three steps when creating a payment:

  • creating a link through which the customer will realize the payment
  • hadling the return of customer to your website
  • handling server to server notification, which are sent by us everytime the payment state is changed

All of these steps will need to be implemented by yourself, but fear not, we have prepared examples that you can take on your journey through our SDK.

1. Payment creation

The payment (link) can be created via two methods:

  • REST API
  • Redirection

No matter what method you choose, you have two more options, based on preselection of payment method:

  • Payment method preselected in e-shop
  • Payment method NOT preselected - the customer will select payment method at ThePay gate

Even if you (or your customer) preselect the payment method, it can still be changed after redirection, unless specifically forbidden.

REST API

You can create payment (link) via REST API and redirect user to that link. The payment itself is created through an API call. This is the preferred way for custom forms and if you want to redirect user after the whole cart process is finished.

The payment method can be preselected on your side and simply added as payment parameter to the API. Otherwise, the customer will be presented with payment method selection on visiting ThePay gate through generated link.

The payment link is returned to you in a response, upon calling the API endpoint for payment creation.

Redirection of customer

The second (simpler) method is to redirect customer to payment gate with payment parameters. The payment itself will be created as soon as customer is redirected. This SDK will generate payment buttons which will do all the work.

The payment method can be preselected in your e-shop and simply added as payment parameter to the correct method. Otherwise, the customer will be presented with payment method selection on visiting ThePay gate through generated link.

The payment link is generated by the SDK, upon using the method for generating the payment button/s. The payment on our side is created at the moment the customer visits the link.

Payment amount is unchangeable

In case your order amount changes, a new payment needs to be created.

Payment flow and changes

You should always create only one payment (with its unique UID) for each order in your e-shop. You should never create new payments, except when changing the payment amount.

TL;DR - summary

These are the usual ways for payment creation:

  • API - creating the payment through API call (selection of payment method either in e-shop or ThePay gate)
  • Redirection with selection of payment method in ThePay gateway
  • Redirection with selection of payment method in the e-shop

Always create only one payment for your order for all payment creation options, unless you need to change the payment amount. In that case, consider it a whole new payment.

For more examples see create-payment.md

use ThePay\ApiClient\TheConfig;
use ThePay\ApiClient\TheClient;
use ThePay\ApiClient\Model\CreatePaymentParams;

$merchantId = '86a3eed0-95a4-11ea-ac9f-371f3488e0fa';
$projectId = 3;
$apiPassword = 'secret';
$apiUrl = 'https://demo.api.thepay.cz/'; // production: 'https://api.thepay.cz/'
$gateUrl = 'https://demo.gate.thepay.cz/'; // production: 'https://gate.thepay.cz/'

$config = new TheConfig($merchantId, $projectId, $apiPassword, $apiUrl, $gateUrl);
$thePay = new TheClient($config);

// Render payment methods for payment (100,- Kč)
$paymentParams = new CreatePaymentParams(10000, 'CZK', 'uid124');

// display button, user will choose payment method at the payment gate
echo $thePay->getPaymentButton($paymentParams);

// or buttons with available payment methods, payment method will be preselected
// echo $thePay->getPaymentButtons($paymentParams);

// or just get payment link and redirect customer whenever you want
// $payment = $thePay->createPayment($createPayment);
// $redirectLink = $payment->getPayUrl();

2. Customer return

The customer is returned from ThePay gate to the return url address.

Return url is set in administration and customer gets redirected there with two query parameters added - payment_uid and project_id (needed if you have one endpoint for multiple projects).

The state of payment must be checked at the time of customer return, since the payment may not always be in the paid state at this time. For example the customer simply returns to the e-shop without paying.

General example of handling the customer return

getPayment($uid); // check if the payment is paid if ($payment->wasPaid()) { // Check if the order isn't labeled as paid yet. If not, do so. // ... }">
use ThePay\ApiClient\TheConfig;
use ThePay\ApiClient\TheClient;
use ThePay\ApiClient\Model\CreatePaymentParams;

$uid = $_GET["payment_uid"];
$projectId = $_GET["project_id"];

$merchantId = '86a3eed0-95a4-11ea-ac9f-371f3488e0fa';
$apiPassword = 'secret';
$apiUrl = 'https://demo.api.thepay.cz/'; // production: 'https://api.thepay.cz/'
$gateUrl = 'https://demo.gate.thepay.cz/'; // production: 'https://gate.thepay.cz/'

$config = new TheConfig($merchantId, $projectId, $apiPassword, $apiUrl, $gateUrl);
$thePay = new TheClient($config);

$payment = $thePay->getPayment($uid);

// check if the payment is paid
if ($payment->wasPaid()) {
    // Check if the order isn't labeled as paid yet. If not, do so.
    // ...
}

3. Server to server notification

It's basically the same as second step (customer return), it's triggered everytime the payment has changed, for example when the state of payment has been changed.

wasPaid()) { // Check if the order isn't labeled as paid yet. If not, do so. // ... }">
use ThePay\ApiClient\TheConfig;
use ThePay\ApiClient\TheClient;
use ThePay\ApiClient\Model\CreatePaymentParams;

$uid = $_GET["payment_uid"];
$projectId = $_GET["project_id"];

$merchantId = '86a3eed0-95a4-11ea-ac9f-371f3488e0fa';
$apiPassword = 'secret';
$apiUrl = 'https://demo.api.thepay.cz/'; // production: 'https://api.thepay.cz/'
$gateUrl = 'https://demo.gate.thepay.cz/'; // production: 'https://gate.thepay.cz/'

$config = new TheConfig($merchantId, $projectId, $apiPassword, $apiUrl, $gateUrl);
$thePay = new TheClient($config);

// check if the payment is paid
if ($payment->wasPaid()) {
    // Check if the order isn't labeled as paid yet. If not, do so.
    // ...
}

More and detailed usage examples

You can find more usage examples at folder /doc.

Money calculations

For safe money calculations we recommend to use moneyphp/money package. Please, do not use float to save information about prices because of its inaccuracy.

composer require moneyphp/money

Support & Contributions

If you find any bug, please submit the issue in Github directly or contact us on email: [email protected]

Feel free to contribute via Github issues and pull requests. We will response as soon as possible. Please have on mind the backwards compatibility and do not change requirements without previous admin agreement.

Comments
  • github issue templates added

    github issue templates added

    http://redmine.havelholding.cz/issues/1951 https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms

    enhancement 
    opened by Triplkrypl 3
  • Neexistující ValueObject apple_pay a google_pay

    Neexistující ValueObject apple_pay a google_pay

    Description

    Do formuláře doplňujeme povolené metody pomocí TheClient->getActivePaymentMethods()->all().
    Tam jsou apple_pay a google_pay dostupné.
    
    Při vytvoření platby ale skončí chybou InvalidArgumentException:
    "apple_pay in not valid value" a "google_pay in not valid value"
    
    TheClient->createPayment($params, 'apple_pay');
    "L269: $paymentMethod = $methodCode === null ? null : new PaymentMethodCode($methodCode);"
    
    V https://github.com/ThePay/api-client/blob/v1.x/src/ValueObject/PaymentMethodCode.php chybí dvě hodnoty apple_pay a google_pay.
    

    Environment

    Production

    PHP version

    7.0

    SDK version

    1.3.3, 1.5.1

    Merchant/project

    No response

    bug good first issue PHP SDK 
    opened by RadH-CZ 1
  • Hotfix/2281 return type change

    Hotfix/2281 return type change

    ReturnTypeWillChange added for better php8 support.

    Tracking for ThePay internal development process: https://redmine.havelholding.cz/issues/2281

    https://sentry.io/organizations/thepay/issues/3521136095 https://sentry.io/organizations/thepay/issues/3508867704 https://sentry.io/organizations/thepay/issues/3508867570 https://sentry.io/organizations/thepay/issues/3508866816

    enhancement 
    opened by Triplkrypl 1
  • php 8.1 in checks

    php 8.1 in checks

    http://redmine.havelholding.cz/issues/1951 Finally we have at least partial PHP 8.1 checks, in unit tests are disabled deprecated errors, because we use old phpunit.

    enhancement 
    opened by Triplkrypl 1
  • new better example for setting of allowed ip addresses

    new better example for setting of allowed ip addresses

    https://redmine.havelholding.cz/issues/1951

    We helped one developer with problems in implementation, and we notice than he setup localhost IP in allowed IPs for communication with API , 127.0.0.1 of course does not work. It look than we adviced it to him 😂.

    documentation PHP SDK 
    opened by Triplkrypl 0
  • payment urls

    payment urls

    http://redmine.havelholding.cz/issues/4161

    rendered buttons are identical, they do not look great but maybe I am missing some config, but they looks same so it should be ok

    image

    documentation enhancement feature 
    opened by AlexKratky 0
  • Hotfix 2281 return type change

    Hotfix 2281 return type change

    ReturnTypeWillChange added for better php8 support.

    Tracking for ThePay internal development process: https://redmine.havelholding.cz/issues/2281

    https://sentry.io/organizations/thepay/issues/3521136095 https://sentry.io/organizations/thepay/issues/3508867704 https://sentry.io/organizations/thepay/issues/3508867570 https://sentry.io/organizations/thepay/issues/3508866816

    enhancement 
    opened by Triplkrypl 0
Releases(v1.5.1)
  • v1.5.1(Oct 12, 2022)

    What's Changed

    • 4282 - Fix node-sass certificate issue by @joseftraxler in https://github.com/ThePay/api-client/pull/32
    • Mark old php versions as deprecated by @Triplkrypl in https://github.com/ThePay/api-client/pull/33
    • v1.5.1 by @joseftraxler in https://github.com/ThePay/api-client/pull/34

    Full Changelog: https://github.com/ThePay/api-client/compare/v1.5.0...v1.5.1

    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(Oct 6, 2022)

    What's Changed

    • added description_for_merchant by @AlexKratky in https://github.com/ThePay/api-client/pull/10
    • added support for shipping address by @AlexKratky in https://github.com/ThePay/api-client/pull/17
    • added currency code to filter by @AlexKratky in https://github.com/ThePay/api-client/pull/16
    • new better example for setting of allowed ip addresses by @Triplkrypl in https://github.com/ThePay/api-client/pull/29
    • V1.x summer by @tymajiri in https://github.com/ThePay/api-client/pull/30
    • Update TheClient.php by @tymajiri in https://github.com/ThePay/api-client/pull/31

    Full Changelog: https://github.com/ThePay/api-client/compare/v1.4.3...v1.5.0

    Source code(tar.gz)
    Source code(zip)
  • v1.4.3(Sep 12, 2022)

    What's Changed

    • unnecessary condition removed by @Triplkrypl in https://github.com/ThePay/api-client/pull/26
    • Hotfix 4213 header case sensitivity by @Triplkrypl in https://github.com/ThePay/api-client/pull/27

    Full Changelog: https://github.com/ThePay/api-client/compare/v1.4.2...v1.4.3

    Source code(tar.gz)
    Source code(zip)
  • v1.4.2(Aug 31, 2022)

    What's Changed

    • Hotfix 2281 return type change by @Triplkrypl in https://github.com/ThePay/api-client/pull/24

    Full Changelog: https://github.com/ThePay/api-client/compare/v1.4.1...v1.4.2

    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Aug 29, 2022)

Owner
ThePay.cz s.r.o.
ThePay.cz s.r.o.
Google-api-php-client - A PHP client library for accessing Google APIs

Google APIs Client Library for PHP Reference Docs https://googleapis.github.io/google-api-php-client/main/ License Apache 2.0 The Google API Client Li

Google APIs 8.4k Dec 30, 2022
PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

Sergey Bykov 63 Feb 14, 2022
Simple papara payment api that you can use without the need for an activation key

PaparaQrApi Papara QR Api Simple papara payment api that you can use without the need for an activation key. Explore the docs » View Demo About The Pr

Azad 6 Dec 20, 2022
WHMCS USDT Payment Gateway.

WHMCS USDT Payment Gateway 支持 TRC-20 USDT 转账交易,系统可完成自动化分配地址,入账等操作,配置简单,无需第三方支付平台中转,所有交易直达您的私人账户。 Requirements PHP 7.2 or greater. WHMCS 8.1 or greater

Licson 59 Jan 7, 2023
WeChatPay driver for the Omnipay PHP payment processing library

Omnipay: WechatPay WechatPay driver for the Omnipay PHP payment processing library Omnipay is a framework agnostic, multi-gateway payment processing l

Loki Else 312 Jan 4, 2023
PayPal driver for the Omnipay PHP payment processing library

Omnipay: PayPal PayPal driver for the Omnipay PHP payment processing library Omnipay is a framework agnostic, multi-gateway payment processing library

The League of Extraordinary Packages 276 Dec 9, 2022
Implementation of a library to process SISP vinti4 payment in a easy way.

Implementation of a library to process SISP vinti4 payment in a easy way.

Faxi 6 Nov 3, 2022
2c2p payment gateway Redirect PHP-SDK

2c2p payment gateway Redirect PHP-SDK

Bilions 2 Oct 1, 2022
DigitalOcean API v2 client for Symfony and API Platform

DigitalOcean Bundle for Symfony and API Platform DunglasDigitalOceanBundle allows using the DigitalOcean API from your Symfony and API Platform projec

Kévin Dunglas 25 Jul 27, 2022
Nexmo REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Client Library for PHP Support Notice This library and it's associated packages, nexmo/client and nexmo/client-core have transitioned into a "Maintena

Nexmo 75 Sep 23, 2022
Code Quiz MonoRepo (API, API Client, App)

Code Quiz Welcome to the Code Quiz Open Source project from How To Code Well. This is an Open Source project that includes an API and an App for the d

How To Code Well 2 Nov 20, 2022
A simple PHP GitHub API client, Object Oriented, tested and documented.

PHP GitHub API A simple Object Oriented wrapper for GitHub API, written with PHP. Uses GitHub API v3 & supports GitHub API v4. The object API (v3) is

KNP Labs 2k Jan 7, 2023
A simple Object Oriented PHP Client for Termii SMS API

Termii Client A simple Object Oriented PHP Client for Termii SMS API. Uses Termii API. Requirements PHP >= 7.2 Guzzlehttp ~6|~7 Installation Via Compo

Ilesanmi Olawale Adedotun 5 Feb 24, 2022
Xendit REST API Client for PHP - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

Xendit REST API Client for PHP - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

Xendit 96 Jan 6, 2023
php 8 client for the lemon.markets api

lemon.markets php client This repository contains a php 8+ compatible client for the https://lemon.markets API. The documentation of the API can be fo

Daniel Freudenberger 4 Nov 17, 2022
PHP client for Microsoft Azure Face API.

Microsoft Azure Face API PHP client A PHP library that utilizes Azure Face REST API. Requirements PHP >= 7.4 Installation composer require darmen/php-

Darmen Amanbayev 6 Sep 14, 2022
Google PHP API Client Services

Google PHP API Client Services

Google APIs 1.1k Dec 22, 2022
A2Reviews Client API lets you build apps, extensions or plugins to get reviews from the A2reviews APP

A2Reviews Client API lets you build apps, extensions or plugins to get reviews from the A2reviews APP. Including adding reviews to a store's products. It is used to import and export reviews through the API. This is the official package built and developed by A2Reviews, Inc.

Be Duc Tai 2 Sep 25, 2021
PHP Client for the GoFlink API

GoFlink PHP API Client This project is an unofficial library to communicate with the GoFlink API from your PHP project. Documentation about the API is

Rico Hageman 4 Oct 3, 2022