Coder Social home page Coder Social logo

r01261 / gopayinline Goto Github PK

View Code? Open in Web Editor NEW

This project forked from contributte/gopay-inline

0.0 1.0 0.0 68 KB

GoPay Inline Payment

License: BSD 3-Clause "New" or "Revised" License

JavaScript 0.25% PHP 99.48% Shell 0.12% Batchfile 0.15%

gopayinline's Introduction

Markette :: GopayInline

Build Status Code coverage Downloads latests Latest stable HHVM Status

Prolog

This library has no dependencies on other php libraries. It provides easy-to-use API for communication with GoPay REST API v3, known as GoPay Inline.

Install

Install Markette/GopayInline over composer.

$ composer require markette/gopay-inline

Requirements

From GoPay you need:

  • GoID
  • ClientID
  • ClientSecret

On server you need:

  • PHP >= 5.5
  • cURL

Resources / Docs

Examples

All you can find in examples folder.

Library

There are 3 main parts of this library.

1) Client

A core class holding credentials, token, authenticator and http client. It could make authentication and requests to endpoints.

2) HttpClient

Delegates all requests / responses to IO. All requests go over cURL. There is a place for other implementation, go for it.

3) Services

Services provide easy-to-use API for creating and verifying payments.

Supported API

  • Verify payments ($client->payments->verify(..))
  • Standard payments ($client->payments->createPayment(..))
  • Recurrent payments ($client->payments->createRecurrentPayment(..))
  • Preauthorized payments ($client->payments->createPreauthorizedPayment(..))

Usage

Authentication

First you need set up client with credentials.

use Markette\GopayInline\Client;
use Markette\GopayInline\Config;

$goId = '***FILL***';
$clientId = '***FILL***';
$clientSecret = '***FILL***';

// TEST MODE
$client = new Client(new Config($goId, $clientId, $clientSecret));
$client = new Client(new Config($goId, $clientId, $clientSecret, $mode = Config::TEST));

// PROD MODE
$client = new Client(new Config($goId, $clientId, $clientSecret, $mode = Config::PROD));

Then you have to authenticate with oauth2 authority server on GoPay.

For only creating payments use Scope::PAYMENT_CREATE, for the rest Scope::PAYMENT_ALL.

use Markette\GopayInline\Api\Lists\Scope;

$token = $client->authenticate(Scope::PAYMENT_CREATE);

Heureka! We have token, let's make some API request.

Creating payment request

This example of payment data was copied from official documentation.

// Payment data
$payment = [
    'payer' => [
        'default_payment_instrument' => PaymentInstrument::BANK_ACCOUNT,
        'allowed_payment_instruments' => [PaymentInstrument::BANK_ACCOUNT],
        'default_swift' => SwiftCode::FIO_BANKA,
        'allowed_swifts' => [SwiftCode::FIO_BANKA, SwiftCode::MBANK],
        'contact' => [
            'first_name' => 'Zbynek',
            'last_name' => 'Zak',
            'email' => '[email protected]',
            'phone_number' => '+420777456123',
            'city' => 'C.Budejovice',
            'street' => 'Plana 67',
            'postal_code' => '373 01',
            'country_code' => 'CZE',
        ],
    ],
    'amount' => 150,
    'currency' => Currency::CZK,
    'order_number' => '001',
    'order_description' => 'pojisteni01',
    'items' => [
        ['name' => 'item01', 'amount' => 50, 'count' => 2],
        ['name' => 'item02', 'amount' => 100],
    ],
    'additional_params' => [
        array('name' => 'invoicenumber', 'value' => '2015001003')
    ],
    'return_url' => 'http://www.eshop.cz/return',
    'notify_url' => 'http://www.eshop.cz/notify',
    'lang' => Language::CZ,
];

// Create payment request
$response = $client->payments->createPayment(PaymentFactory::create($payment));
$data = $response->getData();

$client->payments returns PaymentsService, you can create this service also by $client->createPaymentsService().

PaymentsService::createPayment need object of Payment, you can set-up it manually by yourself or via PaymentFactory. But over PaymentFactory, there is parameters validation and price validation.

Tips

You cannot combine more payment instruments (according to GoPay Gateway implementation). So, you should create payment only with one payment instrument, for example only with BANK_ACCOUNT or PAYMENT_CARD.

For ALL payment instruments

use Markette\GopayInline\Api\Lists\PaymentInstrument;

$payment['payer']['allowed_payment_instruments']= PaymentInstrument::all();

For ALL / CZ / SK swift codes

Use allowed_swifts and default_swift only with BANK_ACCOUNT.

use Markette\GopayInline\Api\Lists\SwiftCode;

$payment['payer']['allowed_swifts']= SwiftCode::all();
// or
$payment['payer']['allowed_swifts']= SwiftCode::cz();
// or
$payment['payer']['allowed_swifts']= SwiftCode::sk();

Process payment

Now we have a response with payment information. There's same data as we send it before and also new $gw_url. It's in response data.

if ($response->isSuccess()) {
    // ...
}
$data = $response->getData();
$url = $data['gw_url'];

$url = $response->data['gw_url'];
$url = $response->gw_url;
$url = $response['gw_url'];

// Redirect to URL
// ...

// Send over AJAX to inline variant
// ...

In case of inline variant you can use prepared javascript.

Verify payment (check state)

All you need is $paymentId. Response is always the same.

// Verify payment
$response = $client->payments->verify($paymentId);

Bridges

Nette

Fill your credentials in config.

extensions:
    gopay: Markette\GopayInline\Bridges\Nette\DI\GopayExtension
    
gopay:
    goId: ***
    clientId: ***
    clientSecret: ***
    test: on / off

Inject Client into your services / presenters;

use Markette\GopayInline\Client;

/** @var Client @inject */
public $gopay;

Class model

Request

It contains information for cURL.

  • $url
  • $headers
  • $options
  • $data

Response

It contains information after execution request. It could be success or failed.

  • $data
  • $headers
  • $code
  • $error

gopayinline's People

Contributors

f3l1x avatar vojtasvoboda avatar martinknor avatar

Watchers

Kamil Walig avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.