Download the PHP package gopay/payments-sdk-php without Composer
On this page you can find all versions of the php package gopay/payments-sdk-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package payments-sdk-php
GoPay's PHP SDK for Payments REST API
Requirements
- PHP >= 8.1
- enabled extension
curl
,json
Installation
The simplest way to install SDK is to use Composer:
Basic usage
Configuration
Required fields
Required field | Data type | Documentation |
---|---|---|
goid |
string | default GoPay account used in createPayment if target is not specified |
clientId |
string | https://doc.gopay.com/#access-token |
clientSecret |
string | https://doc.gopay.com/#access-token |
gatewayUrl |
string | test or production environment? |
Optional fields
Optional field | Data type | Default value | Documentation |
---|---|---|---|
scope |
string | GoPay\Definition\TokenScope::ALL |
https://doc.gopay.com/#access-token |
language |
string | GoPay\Definition\Language::ENGLISH |
language used in createPayment if lang is not specified + used for localization of errors |
timeout |
int | 30 | Browser timeout in seconds |
Available methods
API | SDK method |
---|---|
Create a payment | $gopay->createPayment(array $payment) |
Get status of a payment | $gopay->getStatus($id) |
Refund a payment | $gopay->refundPayment($id, $amount) |
Create a recurring payment | $gopay->createRecurrence($id, array $payment) |
Cancel a recurring payment | $gopay->voidRecurrence($id) |
Capture a preauthorized payment | $gopay->captureAuthorization($id) |
Capture a preauthorized payment partially | $gopay->captureAuthorizationPartial($id, array $capturePayment) |
Void a preauthorized payment | $gopay->voidAuthorization($id) |
Get payment card details | $gopay->getCardDetails($cardId) |
Delete a saved card | $gopay->deleteCard($cardId) |
Get allowed payment methods for a currency | $gopay->getPaymentInstruments($goid, $currency) |
Get all allowed payment methods | $gopay->getPaymentInstrumentsAll($goid) |
Generate an account statement | $gopay->getAccountStatement(array $accountStatement) |
SDK response? Has my call succeed?
SDK returns wrapped API response. Every method returns
GoPay\Http\Response
object. Structure of json/__toString
should be same as in documentation.
SDK throws no exception. Please create an issue if you catch one.
Method | Description |
---|---|
$response->hasSucceed() |
checks if API returns status code 200 |
$response->json |
decoded response, returned objects are converted into associative arrays |
$response->statusCode |
HTTP status code |
$response->rawBody |
raw body from HTTP response |
Are required fields and allowed values validated?
No. API validates fields pretty extensively so there is no need to duplicate validation in SDK. It would only introduce new type of error. Or we would have to perfectly simulate API error messages. That's why SDK just calls API which behavior is well documented in doc.gopay.com.
Advanced usage
Initiation of the payment gateway
Inline gateway
Redirect gateway
Asynchronous initialization using JavaScript
Enums (Code lists)
Instead of hardcoding bank codes string you can use predefined enums. Check using enums in create-payment example
Type | Description |
---|---|
Language | Payment language, localization of error messages |
Token scope | Authorization scope for OAuth2 |
Payment enums | Enums for creating payment |
Response enums | Result of creating payment, executing payment operations |
ItemType enums | Type of an item |
VatRate enums | VatRate of an item |
Framework integration
- Symfony2
Cache access token
Access token expires after 30 minutes so it's expensive to use new token for every request.
Unfortunately it's default behavior of GoPay\Token\InMemoryTokenCache
.
But you can implement your cache and store tokens in Memcache, Redis, files, ... It's up to you.
Your cache must implement GoPay\Token\TokenCache
interface.
Be aware that there are two scopes (TokenScope
) and
SDK can be used for different clients (clientId
, gatewayUrl
). So client
passed to
methods is unique identifier (string
) that is built for current environment.
Below you can see example implementation of caching tokens in file:
Log HTTP communication
You can log every request and response from communication with API. Check available loggers
below. Or you can implement your own logger,
just implement GoPay\Http\Log\Logger
interface.
Available logger | Description |
---|---|
NullLogger | Default logger which does nothing |
PrintHttpRequest | Prints basic information about request and response, used in remote tests |
Contributing
Contributions from others would be very much appreciated! Send pull request/ issue. Thanks!
License
Copyright (c) 2015 GoPay.com. MIT Licensed, see LICENSE for details.
All versions of payments-sdk-php with dependencies
guzzlehttp/guzzle Version ^7.7.0
symfony/deprecation-contracts Version ^3.3.0