Download the PHP package ifthenpay/payment-gateway-sdk without Composer

On this page you can find all versions of the php package ifthenpay/payment-gateway-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package payment-gateway-sdk

ifthenpay SDK (PHP)

A small SDK that aims to facilitate integration with the ifthenpay Gateway API using PHP.



⚙️ Installation

Add with composer:


📋 Requirements

This SDK works with PHP 8.4, 8.3, 8.2, 8.1.


🚀 Quick Start and Configuration

The snippet below has all possible configuration properties in this SDK. You are free to omit properties of the configuration, which means you only need to configure the properties of the payment method you are integrating or other functionality like the Webhook.

Important Note: bear in mind that if you try to call a method that relies on a given config, but is not set, it will throw a /ConfigException with a message that will help you realize a config property is missing.

Using you own HTTP client

This package ships with its own HTTP client (compatible with PSR-18), if you wish to replace it with your own, you can inject it when instantiating the IfthenpayGateway class, as long as it is compatible with PSR-18. Find compatible HTTP clients at packagist


📖 Available Methods

To use any of the methods shown next, you must first instantiate the main class, after which you will have access to each payment method service object. There is a payment method service for each of the payment methods that ifthenpay provides, like Multibanco Dynamic, MB WAY, etc. Each service can be slightly different from its siblings, check the methods docs or refer to the examples for more information.

Note: access to a payment method object that does not have the required configuration will return an exception.

Payment Services

Assuming you instantiated IfthenpayGateway to a variable $ifthenpayGateway you can then access the payment services:

You can either assign the service object to a variable or use it directly.

Payment Services methods

With a payment service object, you gain access to its methods, some of which are common to other payment service objects.

Multibanco Dynamic

Multibanco Offline

MB WAY

Payshop

Credit Card

Pix

Cofidis

Pay By Link

Payment object

A payment object is what is returned to you when generating a payment, and other methods like validateWebhook and isExpire expect it as a parameter.

All the payment objects implement the same methods:

💻 Examples

These are some common use cases shown in a simplified manner, more can be found in the examples folder of this project.

Create a payment

Use the initPayment() method to create a payment using the current payment service. It will return a payment object, which you can then use to store in your database or execute some logic. Each payment service provides this method, with some expecting different parameters and return objects.

Register webhook

Ifthenpay has a webhook system that, once registered, whenever a payment is completed, will send a GET request to the URL you have registered. You can use this to update a payment status on your implementation. You may set additional webhook parameters by passing an assoc array in the second parameter, but keep in mind the webhook has a limit of 300 characters.

Validate webhook

If you registered the webhook using this SDK method, you can use the validateWebhook method to validate the webhook.

Check payment expiration

If you configured an expiration time in the configuration, you can use this method to verify if a payment has expired. It is a simple function that compares the expiration date, generated during payment creation, against the current time. Bear in mind that this expiration check serves only to help you update the payment status, for example, set it to Cancelled if not paid in time.

Check if payment is complete/paid

Allows you to check if the payment is complete. Except for Pay By Link (which has its own method isTransactionPaid() ), each payment method service provides this method. Important Note: this method is intended to be used to check the status at a given point in your payment logic. Because this method's endpoint is subject to rate limiting, it should not be used in low-interval cron jobs; in most scenarios, the webhook will do what you need.

Check payment status (MB WAY and Cofidis)

This method is exclusive to MB WAY and Cofidis and is used to get a status enum of the transaction, since these payments can have different statuses at a given time. MB WAY, when initialized with success, is in a "pending" status, it can then be "paid", "rejected_by_user", "declined" or "expired". Cofidis, when initialized with success, is in a "pending" status, it can then be "paid", "declined", "canceled" or "error. D A common use case in MB WAY is using this method together with a frontend countdown timer to display the transaction status to the buyer. Cofidis's method lets you set the number of attempts, this was necessary since a few seconds delay may occur while the status is updated.

Check if payment is complete/paid (Pay By Link)

Check if Pay By Link payment is complete. Important Note: when using Pay By Link, the transaction ID is not readily available; only when the webhook is executed is the transaction ID known, normally in the form of a return on success. This method is used to verify the success URL redirect. If the payment is paid, it will return the enum of the payment method used, else, if not paid, it will return false.

Verify Credit Card Payment is complete (Credit Card)

This method is an alternative to isPaid(). While isPaid() communicates with the ifthenpay server to know if the payment is complete, this verifies the secret key returned in the success redirect.

Creating a factory

If you are using the SDK multiple times across your project, you may want to create a factory to handle the config for you instead of configuring it everytime. Refer to /examples/configuration/factoryWithConfig.php.

Creating a factory with external config

Take it a step further and separate the config to its own file by creating a closure. This is useful if you want to keep all your project configurations in one folder.

❔ FAQ

Q: Do I need an ifthenpay account to use this SDK?
A: Yes, the methods in this SDK won't work without the correct account keys.

Q: How can I test this SDK?
A: This SDK does not have a sandbox functionality, you can ask for a test account from ifthenpay support

Q: How do I use this SDK in my integration?
A: Use the examples provided in this repository as reference, the most common use cases are shown there.

Q: Can I change the code of this package?
A: Sure, if you need to, you are free to customize it as you see fit.

Q: Can I use this SDK on versions of PHP older than 8.1?
A: No, unless you refactor it in order to comply with older versions of PHP.

Q: If I set the daysToExpire/minutesToExpire and a payment goes without completion, can the customer still pay it?
A: Only Multibanco Dynamic, Payshop, and Pay By Link use the expiration time in the endpoint request and will not be payable after it, meaning if you try to access the link or try to pay, you will encounter an error. The secondary purpose of daysToExpire/minutesToExpire is to help you know when to change the status of your order, in most cases, set it to canceled after the time has passed.

Q: How can i set the payments to never expire?
A: You can pass null in the daysToExpire/minutesToExpire parameter, but beware, some methods have inherent expiration that cannot be changed and will not be payable after that expiration has passed, look up the table to know which ones.

Payment method Inherent expiration Expiration parameter prevents access to payment
Multibanco Dynamic Configurable from 0 to 365 days or null yes
Multibanco Offline none no
Payshop Configurable from 0 to 365 days or null yes
Ifthenpay Gateway Configurable from 0 to 365 days or null yes
MB WAY 4 minutes no
Credit Card none no
Cofidis 60 minutes no
Pix 5 minutes no

Note: an expiration of 0 days means it expires on the same day at 23:59.


All versions of payment-gateway-sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
nyholm/psr7 Version ^1.8
php-http/curl-client Version ^2.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ifthenpay/payment-gateway-sdk contains the following files

Loading the files please wait ...