Download the PHP package fei/payment-client without Composer
On this page you can find all versions of the php package fei/payment-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package payment-client
Payment Client
You can use this client to consume the Payment service.
With this client you can use two kind of transports to send the requests :
- Asynchronous transport implemented by
BeanstalkProxyTransport
- Synchronous transport implemented by
BasicTransport
BeanstalkProxyTransport
delegates the API consumption to workers by sending payments entities to a Beanstalkd queue.
BasicTransport
uses the classic HTTP layer to send payments synchronously.
You can find examples of how to use payment client methods in the examples folder.
Installation
Payer client needs at least PHP 5.5 to work properly.
Add this requirement to your composer.json: "fei/payment-client": : "^1.0"
Or execute composer.phar require fei/payment-client in your terminal.
If you want use the asynchronous functionality of the Payer client (and we know you want), you need an instance of Beanstalkd which running properly and an instance of api-client-worker.php which will consume the Beanstalk's pipe and forward messages payload to the Payment API:
Beanstalkd configuration
Running Beanstalkd is very simple. However, you must pay attention to the z option which set the maximum job (or message) size in bytes.
Run api-client-worker.php
You could see below an example of running api-client-worker.php
:
Options | Shortcut | Description | Default |
---|---|---|---|
host | -h |
The host of Beanstalkd instance | localhost |
port | -p |
The port which Beanstalkd instance listening | 11300 |
delay | -d |
The delay between two treatment of the worker | 3 seconds |
verbose | -v |
Print verbose information | - |
You can control the api-client-worker.php process by using Supervisor.
Entities and classes
Payment entity
In addition to traditional id
and createdAt
fields, Payment entity has eleven important properties:
Properties | Type |
---|---|
id | integer |
uuid | string |
createdAt | datetime |
payedAt | datetime |
expirationDate | datetime |
status | integer |
cancellationReason | string |
requiredPrice | float |
capturedPrice | float |
authorizedPayment | integer |
selectedPayment | integer |
contexts | ArrayCollection |
callbackUrl | ArrayCollection |
orderId | string |
paymentMethod | string |
uuid
is a string representing a unique identifier of the payment entity- `createdAt' represent the creation date
- `payedAt' represent the date when the payment has been made
- `expirationDate' represent the date when the payment expires
status
indicate in which status the payment currently isorderId
Store your OrderId from your applicationpaymentMethod
Payment method to be used on the platform (example: VISA in payzen)cancellationReason
is a string representing the reason of the cancellation of the paymentrequiredPrice
is a float representing the price requiredcapturedPrice
is a float representing the price capturedauthorizedPayment
is an int that represent the list of the payment authorised (used like binary flags)selectedPayment
is an integer representing the payment method that has been chosencontexts
is an ArrayCollection of all the contexts for the entitycallbackUrl
is an array of callbacks url that will be used is some events in the application (when the payment is saved for example). Here are the possible value and purpose of the callback url:succeeded
: the url that will be called when an payment authorization successesfailed
: the url that will be called when an payment authorization failedcancelled
: the url that will be called when an payment is cancelled
Context entity
In addition to traditional id
field, Context entity has three important properties:
Properties | Type |
---|---|
id | integer |
key | string |
value | string |
payment | Payment |
key
is a string representing the key of the contextvalue
is a string representing the value attach to this contextpayment
is a Payment entity representing the Payment related to this context
Basic usage
In order to consume Payer
methods, you have to define a new Payer
instance and set the right transport (Asynchronously or Synchronously).
Payer
client instance will first attempt to transfer the messages with Beanstalkd, if the process fail then the client will try to send Payment payload directly to the right API endpoint.
There are several methods in Payer
class, all listed in the following table:
Method | Parameters | Return |
---|---|---|
request | Payment $payment |
integer |
update | Payment $payment |
integer |
retrieve | int $paymentId |
Payment |
search | SearchBuilder $search |
array |
cancel | Payment|int $payment, int $reason |
intger |
reject | Payment|int $payment, int $reason |
intger |
capture | Payment|int $payment, float $amount |
intger |
refund | Payment|int $payment, float $amount |
intger |
getPaymentLink | Payment|int|string $payment |
string |
Client option
Only one option is available which can be passed either by the constructor or by calling the setOptions
method Payer::setOptions(array $options)
:
Option | Description | Type | Possible Values | Default |
---|---|---|---|---|
OPTION_BASEURL | This is the server to which send the requests. | string | Any URL, including protocol but excluding path | - |
Note: All the examples below are also available in the examples directory.
Request
You can create new Payment by using the request()
method of the Payer
client:
Example
Update
You can update an existing Payment by using the update()
method of the Payer
client:
Example
Retrieve
You can retrieve one Payment by using the retrieve()
method of the Payer
client that takes one parameter: the id
the the payment entity OR the uuid
of the payment.
Example
Search
You can search for payments by using the search()
method of the Payer
client that takes a SearchBuilder
instance.
Example
Cancel
You can cancel one payment by using the cancel()
method of the Payer
client that takes a Payment
instance (or id) and a string
for the reason of the cancellation.
Example
Reject
You can reject one payment by using the reject()
method of the Payer
client that takes a Payment
instance (or id) and a string
for the reason of the cancellation.
Example
Capture
You can capture one payment by using the capture()
method of the Payer
client that takes a Payment
instance (or id) and a float
for the amount to capture.
Example
GetPaymentLink
You can get the public payment link to process a payment by using the getPaymentLink()
method of the Payer
client that takes either a Payment
instance or an id or an uuid.
Example