All Projects → gopaycommunity → Gopay Php Api

gopaycommunity / Gopay Php Api

Licence: mit
GoPay's PHP SDK for Payments REST API

Labels

Projects that are alternatives of or similar to Gopay Php Api

Js Api Client
Typeform API js client
Stars: ✭ 51 (-3.77%)
Mutual labels:  api, sdk
Pymessager
Python API to develop chatbot on Facebook Messenger Platform
Stars: ✭ 580 (+994.34%)
Mutual labels:  api, sdk
App
Directus Admin Application — An Intuitive WebApp for Managing Database Content
Stars: ✭ 464 (+775.47%)
Mutual labels:  api, sdk
Vk Io
Modern VK API SDK for Node.js
Stars: ✭ 401 (+656.6%)
Mutual labels:  api, sdk
Vainglory
(*DEPRECATED*: The API no longer exists, so this will no longer work) A Javascript API Client wrapper for Vainglory
Stars: ✭ 32 (-39.62%)
Mutual labels:  api, sdk
Go Binance
A Go SDK for Binance API
Stars: ✭ 441 (+732.08%)
Mutual labels:  api, sdk
Swiftinstagram
Instagram API client written in Swift
Stars: ✭ 570 (+975.47%)
Mutual labels:  api, sdk
Coinapi Sdk
SDKs for CoinAPI
Stars: ✭ 238 (+349.06%)
Mutual labels:  api, sdk
Aeris Ios Library
Contains a demo project utilizing the AerisWeather SDK for iOS to help you get started with using our library.
Stars: ✭ 21 (-60.38%)
Mutual labels:  api, sdk
Gocertcenter
CertCenter API Go Implementation
Stars: ✭ 21 (-60.38%)
Mutual labels:  api, sdk
Huobi python
Python SDK for Huobi Spot API
Stars: ✭ 391 (+637.74%)
Mutual labels:  api, sdk
Nodejs
Everything related to the Node.js ecosystem for the commercetools platform.
Stars: ✭ 47 (-11.32%)
Mutual labels:  api, sdk
Jcabi Github
Object Oriented Wrapper of Github API
Stars: ✭ 252 (+375.47%)
Mutual labels:  api, sdk
Modio Unity
Unity Plugin for integrating mod.io - a modding API for game developers
Stars: ✭ 53 (+0%)
Mutual labels:  api, sdk
Strapi Sdk Javascript
🔌 Official JavaScript SDK for APIs built with Strapi.
Stars: ✭ 247 (+366.04%)
Mutual labels:  api, sdk
Dorita980
Unofficial iRobot Roomba and Braava (i7/i7+, 980, 960, 900, e5, 690, 675, m6, etc) node.js library (SDK) to control your robot
Stars: ✭ 523 (+886.79%)
Mutual labels:  api, sdk
Pymedium
Unofficial Medium Python Flask API and SDK
Stars: ✭ 153 (+188.68%)
Mutual labels:  api, sdk
Huobi java
Java SDK for Huobi Spot API
Stars: ✭ 180 (+239.62%)
Mutual labels:  api, sdk
Themoviedb
A node.js module with support for both callbacks and promises to provide access to the TMDb API
Stars: ✭ 5 (-90.57%)
Mutual labels:  api, sdk
Waliyun
阿里云Node.js Open API SDK(完整版)
Stars: ✭ 40 (-24.53%)
Mutual labels:  api, sdk

GoPay's PHP SDK for Payments REST API

License Latest Stable Version Total Downloads Monthly Downloads Dependency Status

Build Status PHP runtimes

## Requirements

  • PHP >= 5.4.0
  • enabled extension curl, json

## Installation

The simplest way to install SDK is to use Composer:

composer require gopay/payments-sdk-php

Basic usage

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

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

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/en/?shell#oauth
clientSecret string https://doc.gopay.com/en/?shell#oauth
isProductionMode boolean test or production environment?

Optional fields

Optional field Data type Default value Documentation
scope string GoPay\Definition\TokenScope::ALL https://doc.gopay.com/en/?shell#scope
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 standard payment $gopay->createPayment(array $payment)
Status of the payment $gopay->getStatus($id)
Refund of the payment $gopay->refundPayment($id, $amount)
Create recurring payment $gopay->createPayment(array $payment)
Recurring payment on demand $gopay->createRecurrence($id, array $payment)
Cancellation of the recurring payment $gopay->voidRecurrence($id)
Create pre-authorized payment $gopay->createPayment(array $payment)
Charge of pre-authorized payment $gopay->captureAuthorization($id)
Cancellation of the pre-authorized payment $gopay->voidAuthorization($id)

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.

$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}";
}

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->__toString() 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

// create payment and pass url to template 
$response = $gopay->createPayment([/* define your payment  */]);
if ($response->hasSucceed()) {
    $templateParameters = [
        'gatewayUrl' => $response->json['gw_url'],
        'embedJs' => $gopay->urlToEmbedJs()
    ];
    // render template
}

Inline gateway

<form action="<?php echo $gatewayUrl; ?>" method="post" id="gopay-payment-button">
  <button name="pay" type="submit">Pay</button>
  <script type="text/javascript" src="<?php echo $embedJs;>"></script>
</form>

Redirect gateway

<form action="<?php echo $gatewayUrl; ?>" method="post">
  <button name="pay" type="submit">Pay</button>
</form>

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

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, isProductionMode). 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:

// register cache in optional service configuration
$gopay = GoPay\payments(
    [/* your config */],
    ['cache' => new PrimitiveFileCache()]
);
<?php

use GoPay\Token\TokenCache;
use GoPay\Token\AccessToken;

class PrimitiveFileCache implements TokenCache
{
    public function setAccessToken($client, AccessToken $t)
    {
        file_put_contents(__DIR__ . "/{$client}", serialize($t));
    }

    public function getAccessToken($client)
    {
        $file = __DIR__ . "/{$client}";
        if (file_exists($file)) {
            return unserialize(file_get_contents($file));
        }
        return null; 
    }
}

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.

// register logger in optional service configuration
$gopay = GoPay\payments(
    [/* your config */],
    ['logger' => new GoPay\Http\Log\PrintHttpRequest()]
);
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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].