PHPackages                             gopay/payments-sdk-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. gopay/payments-sdk-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

gopay/payments-sdk-php
======================

GoPay's PHP SDK for Payments REST API

1.10.4(7mo ago)841.6M↓12.5%48[2 PRs](https://github.com/gopaycommunity/payments-sdk-php/pulls)14MITPHPPHP &gt;=8.1CI passing

Since Nov 2Pushed 3mo ago8 watchersCompare

[ Source](https://github.com/gopaycommunity/payments-sdk-php)[ Packagist](https://packagist.org/packages/gopay/payments-sdk-php)[ RSS](/packages/gopay-payments-sdk-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (53)Used By (14)

GoPay's PHP SDK for Payments REST API
=====================================

[](#gopays-php-sdk-for-payments-rest-api)

[![License](https://camo.githubusercontent.com/af9f6bc77703edef77b011e31094b974a1c71c41120a3129c0645e9ac3bca028/68747470733a2f2f706f7365722e707567782e6f72672f676f7061792f7061796d656e74732d73646b2d7068702f6c6963656e7365)](https://packagist.org/packages/gopay/payments-sdk-php)[![Latest Stable Version](https://camo.githubusercontent.com/bb20eb4cebecf6b5b69027e70f214b03a1e93686a6b78b6187088cbd3a75f9ee/68747470733a2f2f706f7365722e707567782e6f72672f676f7061792f7061796d656e74732d73646b2d7068702f762f737461626c65)](https://packagist.org/packages/gopay/payments-sdk-php)[![Total Downloads](https://camo.githubusercontent.com/a4f666eb8ae9b3f1a5395d00ba742cfc6a32b0d12e6b715ab5c63957898c5df6/68747470733a2f2f706f7365722e707567782e6f72672f676f7061792f7061796d656e74732d73646b2d7068702f646f776e6c6f616473)](https://packagist.org/packages/gopay/payments-sdk-php)[![Monthly Downloads](https://camo.githubusercontent.com/f89b694b9576032ac82930fcedaf21f6a63e6672e4e9b3e6a693f39c12158147/68747470733a2f2f706f7365722e707567782e6f72672f676f7061792f7061796d656e74732d73646b2d7068702f642f6d6f6e74686c79)](https://packagist.org/packages/gopay/payments-sdk-php)[![Dependency Status](https://camo.githubusercontent.com/18dc773878e14f52a11d4b4409f70a6a90867dcef1030cae9d26dc900c4a4871/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537306233383365326163613662303030653064656139352f62616467652e737667)](https://www.versioneye.com/user/projects/570b383e2aca6b000e0dea95)

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- enabled extension `curl`, `json`

Installation
------------

[](#installation)

The simplest way to install SDK is to use [Composer](https://getcomposer.org/doc/00-intro.md):

```
composer require gopay/payments-sdk-php
```

Basic usage
-----------

[](#basic-usage)

```
// minimal configuration
$gopay = GoPay\Api::payments([
    'goid' => 'my goid',
    'clientId' => 'my id',
    'clientSecret' => 'my secret',
    'gatewayUrl' => 'gateway url'
]);

// full configuration
$gopay = GoPay\Api::payments([
    'goid' => 'my goid',
    'clientId' => 'my id',
    'clientSecret' => 'my secret',
    'gatewayUrl' => 'gateway url',
    'scope' => GoPay\Definition\TokenScope::ALL,
    'language' => GoPay\Definition\Language::CZECH,
    'timeout' => 30
]);
```

### Configuration

[](#configuration)

#### Required fields

[](#required-fields)

Required fieldData typeDocumentation`goid`stringdefault GoPay account used in `createPayment` if `target` is not specified`clientId`string`clientSecret`string`gatewayUrl`string[test or production environment?](https://help.gopay.com/en/s/uY)#### Optional fields

[](#optional-fields)

Optional fieldData typeDefault valueDocumentation`scope`string[`GoPay\Definition\TokenScope::ALL`](src/Definition/TokenScope.php)`language`string[`GoPay\Definition\Language::ENGLISH`](src/Definition/Language.php)language used in `createPayment` if `lang` is not specified + used for [localization of errors](https://doc.gopay.com/#errors)`timeout`int30Browser timeout in seconds### Available methods

[](#available-methods)

APISDK method[Create a payment](https://doc.gopay.com#payment-creation)`$gopay->createPayment(array $payment)`[Get status of a payment](https://doc.gopay.com#payment-inquiry)`$gopay->getStatus($id)`[Refund a payment](https://doc.gopay.com#payment-refund)`$gopay->refundPayment($id, $amount)`[Create a recurring payment](https://doc.gopay.com#creating-a-recurrence)`$gopay->createRecurrence($id, array $payment)`[Cancel a recurring payment](https://doc.gopay.com#void-a-recurring-payment)`$gopay->voidRecurrence($id)`[Capture a preauthorized payment](https://doc.gopay.com#capturing-a-preauthorized-payment)`$gopay->captureAuthorization($id)`[Capture a preauthorized payment partially](https://doc.gopay.com#partially-capturing-a-preauthorized-payment)`$gopay->captureAuthorizationPartial($id, array $capturePayment)`[Void a preauthorized payment](https://doc.gopay.com#voiding-a-preauthorized-payment)`$gopay->voidAuthorization($id)`[Get payment card details](https://doc.gopay.com#payment-card-inquiry)`$gopay->getCardDetails($cardId)`[Delete a saved card](https://doc.gopay.com#payment-card-deletion)`$gopay->deleteCard($cardId)`[Get allowed payment methods for a currency](https://doc.gopay.com#available-payment-methods-for-a-currency)`$gopay->getPaymentInstruments($goid, $currency)`[Get all allowed payment methods](https://doc.gopay.com#all-available-payment-methods)`$gopay->getPaymentInstrumentsAll($goid)`[Generate an account statement](https://doc.gopay.com#account-statement)`$gopay->getAccountStatement(array $accountStatement)`### SDK response? Has my call succeed?

[](#sdk-response-has-my-call-succeed)

SDK returns wrapped API response. Every method returns [`GoPay\Http\Response` object](src/Http/Response.php). Structure of `json/__toString`should be same as in [documentation](https://doc.gopay.com/en). SDK throws no exception. Please create an issue if you catch one.

```
$response = $gopay->createPayment([/* define your payment  */]);
if ($response->hasSucceed()) {
    echo "hooray, API returned {$response}";
    return $response->json['gw_url']; // url for initiation of gateway
} else {
    // errors format: https://doc.gopay.com/en/?shell#http-result-codes
    echo "oops, API returned {$response->statusCode}: {$response}";
}
```

MethodDescription`$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?

[](#are-required-fields-and-allowed-values-validated)

**No.** API [validates fields](https://doc.gopay.com/#error) 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](https://doc.gopay.com).

---

Advanced usage
--------------

[](#advanced-usage)

### Initiation of the payment gateway

[](#initiation-of-the-payment-gateway)

```
// create payment and pass url to template
$response = $gopay->createPayment([/* define your payment  */]);
if ($response->hasSucceed()) {

        $gatewayUrl => $response->json['gw_url'],
        $embedJs => $gopay->urlToEmbedJs()
        // render template
}
```

#### [Inline gateway](https://doc.gopay.com/#inline)

[](#inline-gateway)

```
