Download the PHP package pumuklisk8/barion-web-php without Composer
On this page you can find all versions of the php package pumuklisk8/barion-web-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pumuklisk8/barion-web-php
More information about pumuklisk8/barion-web-php
Files in pumuklisk8/barion-web-php
Package barion-web-php
Short Description Barion web API for Yii 2
License BSD-3-Clause
Informations about the package barion-web-php
BarionPHP
BarionPHP is a compact PHP library to manage online e-money and card payments via the Barion Smart Gateway. It allows you to accept credit card and e-money payments in just a few lines of code.
BarionPHP lets you
- Start an online immediate or reservation payment easily
- Get details about a given payment
- Finish an ongoing reservation payment completely or partially, with automatic refund support
- Refund a completed payment transaction completely or partially
All with just a few simple pieces of code!
Version history
- 1.1.0 November 27. 2015.
- 1.0.1 November 26. 2015.
- 1.0.0 November 17. 2015.
For details about version changes, please refer to the changelog.txt file.
System requirements
- PHP 5.2 or higher
- cURL module enabled
- SSL enabled
Installation
Copy the contents of the barion library into the desired folder. Be sure to have access to the path when running your PHP script.
Basic usage
Include the BarionClient class in your PHP script:
Then instantiate a Barion client. To achieve this, you must supply three parameters.
First, the secret key of the online store registered in Barion (called POSKey)
The API version number (2 by default)
The environment to connect to. This can be the test system, or the production environment.
With these parameters you can create an instance of the BarionClient class:
Examples
Starting an online payment
Let's see a basic example of using the Barion library. We are going to start an immediate online payment, where the user can pay for one product which costs 1 000 HUF.
1. Creating the request object
To start an online payment, you have to create one or more Payment Transaction objects, add transaction Items to them, then group these transactions together in a Payment object.
First, create an ItemModel:
Then create a PaymentTransactionModel and add the Item mentioned above to it:
Finally, create a PreparePaymentRequestModel and add the PaymentTransactionModel mentioned above to it:
At this point, the complete request object looks like this:
Note: the secret POSKey used for authentication is not part of the request object. The Barion client class automatically injects this value into every request sent to the Barion API.
2. Calling the Barion API
Now you can call the PreparePayment method of the Barion client with the request model you just created:
The Barion API now prepares a payment entity that can be paid by anyone.
The $myPayment variable holds the response received from the Barion API, which is an instance of a PreparePaymentResponseModel object. It should look something like this:
The RequestSuccessful parameter shows that the request was successfully made. PaymentId holds the public identifier of the payment you just created in the Barion system, and the Transactions array contains the transactions related to this payment. The fist element is the transaction you constructed before, and the other two are fee transactions generated by the Barion Smart Gateway. In this case, these are gateway usage and bank card processing fees.
Note: The amount and types of the related fee transactions depend on the request caller identity - please refer to the documentation at https://docs.barion.com or contact our Sales Department.
3. Redirecting the user to the Barion Smart Gateway
You can use the PaymentId value in the response to redirect the user to the Barion Smart Gateway. You have to supply this identifier in the Id query string parameter. The complete redirect URL looks like this:
The user can now complete the payment at the Barion Smart Gateway.
Getting information about a payment
In this example we are going to get detailed information about the payment we just created above.
1. Creating the request object
To request details about a payment, you only need one parameter: the payment identifier. This is the PaymentId we have used earlier to redirect the user.
2. Calling the Barion API
To request payment details, we call the GetPaymentState method of the Barion client class with the identifier above:
The $paymentDetails variable holds the response received from the Barion API, which is an instance of a PaymentStateResponseModel object. It should look something like this:
The payment is in Prepared status, which means it is still waiting to be paid. If we wait until the user completes the payment, and send the request again, we should get a slightly different result with more information:
As you can see, the payment status is now Succeeded, which means the payment has been completed successfully. The FundingSource paramter shows that the payment was completed using a bank card. Also, the Payer parameter of the first transaction shows that the payment was completed by the John Doe ([email protected]) user account.
Further examples
To view more examples about the usage of the Barion library, refer to the example files found in the Samples folder of the repository.
© 2015 Barion Payment Inc.