项目作者: click-llc

项目描述 :
This library allows you to integrate payment acceptance using "CLICK" payment system into PHP web applications. For the library to function properly, the user must be connected to Click Merchant using the Shop API scheme.
高级语言: PHP
项目地址: git://github.com/click-llc/click-integration-php.git
创建时间: 2019-02-11T07:53:31Z
项目社区:https://github.com/click-llc/click-integration-php

开源协议:

下载


CLICK Integration PHP

This library allows you to integrate payment acceptance using "CLICK" payment system into PHP web applications.
For the library to function properly, the user must be connected to Click Merchant using the Shop API scheme.
Detailed documentation is available here https://docs.click.uz.

ClickLLC

Installation via Git

  1. git clone https://github.com/click-llc/click-integration-php.git
  2. cd click-integration-php
  3. composer install

After installing, you need to require autoloader

  1. require(__DIR__ . '\vendor\autoload.php');

Documentation

Configuration

Your can set your configurations via click/configs.php file.

Click configuration

  1. return [
  2. ...
  3. 'provider' => [
  4. 'endpoint' => 'https://api.click.uz/v2/merchant/',
  5. 'click' => [
  6. 'merchant_id' => 1111,
  7. 'service_id' => 2222,
  8. 'user_id' => 3333,
  9. 'secret_key' => 'AAAAAAAA'
  10. ]
  11. ]
  12. ...
  13. ]

Database configuration

  1. return [
  2. ...
  3. 'db' => [
  4. 'dsn' => 'mysql:host=localhost;dbname=<your_db_name>',
  5. 'username' => 'root',
  6. 'password' => ''
  7. ]
  8. ...
  9. ]

Quick Start

1) Create Model

You can use the \cick\models\Payments model

  1. use click\models\Payments;
  2. $model = new Payments();

Or can create payments model yourself via \click\models\Payments class

  1. use click\models\Payments;
  2. class MyPayments extends Payments{
  3. ...
  4. }
  5. $model = new MyPayments();

SHOP Api methods

Prepare

  1. $model->prepare([
  2. 'click_trans_id' => 1111,
  3. 'service_id' => 2222,
  4. 'click_paydoc_id' => 3333,
  5. 'merchant_trans_id' => '11111',
  6. 'amount' => 1000.0,
  7. 'action' => 0,
  8. 'error' => 0,
  9. 'error_note' => 'Success',
  10. 'sign_time' => 'YYYY-MM-DD HH:mm:ss',
  11. 'sign_string' => 'AAAAAAAAAAAAAAAAAAAAAAAAAA'
  12. ]);

Complete

  1. $model->complete([
  2. 'click_trans_id' => 1111,
  3. 'service_id' => 2222,
  4. 'click_paydoc_id' => 3333,
  5. 'merchant_trans_id' => '11111',
  6. 'merchant_prepare_id' => 11111,
  7. 'amount' => 1000.0,
  8. 'action' => 1,
  9. 'error' => 0,
  10. 'error_note' => 'Success',
  11. 'sign_time' => 'YYYY-MM-DD HH:mm:ss',
  12. 'sign_string' => 'AAAAAAAAAAAAAAAAAAAAAAAAAA'
  13. ]);

Merchant Api methods

Note : All of the merchant api methods return the CLICK-MERCHANT-API response as arrays

Create invoice

  1. $model->create_invoice([
  2. 'token' => 'aaaa-bbbb-cccc-ddddddd',
  3. 'phone_number' => '998112222222'
  4. ]);

Check invoice status

  1. $model->check_invoice([
  2. 'token' => 'aaaa-bbbb-cccc-ddddddd',
  3. 'invoice_id' => 2222
  4. ]);

Create card token

  1. $model->create_card_token([
  2. 'token' => 'aaaa-bbbb-cccc-ddddddd',
  3. 'card_number' => 'AAAA-BBBB-CCCC-DDDD',
  4. 'expire_date' => 'BBEE',
  5. 'temporary' => 1
  6. ]);

Verify card token

  1. $model->verify_card_token([
  2. 'token' => 'aaaa-bbbb-cccc-ddddddd',
  3. 'sms_code' => '12345'
  4. ]);

Payment with card token

  1. $model->payment_with_card_token([
  2. 'token' => 'aaaa-bbbb-cccc-ddddddd',
  3. 'card_token' => 'AAAAAA-BBBB-CCCC-DDDDDDD'
  4. ]);

Delete card token

  1. $model->delete_card_token([
  2. 'token' => 'aaaa-bbbb-cccc-ddddddd',
  3. 'card_token' => 'AAAAAA-BBBB-CCCC-DDDDDDD'
  4. ]);

Check payment status by payment_id

  1. $model->check_payment([
  2. 'token' => 'aaaa-bbbb-cccc-ddddddd',
  3. 'payment_id' => 1111
  4. ]);

Check payment status by merchant_trans_id

  1. $model->merchant_trans_id([
  2. 'token' => 'aaaa-bbbb-cccc-ddddddd',
  3. 'merchant_trans_id' => 1111
  4. ]);

Cancel payment (reversal)

  1. $model->cancel([
  2. 'token' => 'aaaa-bbbb-cccc-dddddddd',
  3. 'payment_id' => 1111
  4. ]);

2) Overwrite the some methods over the Payments

  1. use click\models\Payments;
  2. class MyPayments extends Payments{
  3. /**
  4. * @param data array
  5. * @return response \GuzzleHttp\Client
  6. */
  7. public function on_invoice_creating($data){
  8. ...
  9. $response = $this->client->request('POST', 'invoice/create', [
  10. ...
  11. ]);
  12. ...
  13. return $response;
  14. }
  15. /**
  16. * @param request array
  17. * @param response \GuzzleHttp\Client object
  18. * @param token string
  19. * @return response array|null
  20. */
  21. public function on_invoice_created($request, $response, $token){
  22. ...
  23. if($response->getStatusCode() == 200){
  24. $result = (array)json_decode((string) $response->getBody());
  25. ...
  26. $this->model->update_by_token($token, [
  27. ...
  28. ]);
  29. ...
  30. }
  31. ...
  32. return $result;
  33. }
  34. }

List of the Payments methods
1) on_invoice_creating and on_invoice_created for create invoice
2) on_invoice_checking and on_invoice_checked for check invoice
3) on_canceling and on_canceled for cancel payment
4) on_card_token_creating and on_card_token_created for create card token
5) on_card_token_verifying and on_card_token_verified for verify card token
6) on_card_token_paying and on_card_token_payed for payment via card token
7) on_card_token_deleting and on_card_token_deleted for delete card token
8) on_payment_checking and on_payment_checked for check payment status by merchant_id
9) on_checking_with_merchant_trans_id and on_checked_with_merchant_trans_id for check payment status by merchant_trans_id

If you want check whether the payment user exists, complete this method

  1. use click\models\Payments;
  2. class MyPayments extends Payments{
  3. /**
  4. * @name on_user_is_exists method
  5. * @param payment array
  6. * @return response boolean|null
  7. */
  8. protected function on_user_is_exists($payment){
  9. ...
  10. }
  11. }

Advanced

1) Create the application for rest api

  1. use click\applications\Application;
  2. use click\models\Payments;
  3. $model = new Payments();
  4. $application = new Application([
  5. 'model' => $model
  6. ]);

2) Create the application with application session for authorization via token

  1. use click\applications\Application;
  2. use click\models\Payments;
  3. Application::session('<YOUR_AUTH_TOKEN>', ['/prepare', '/complete'], function(){
  4. $model = new Payments();
  5. $application = new Application([
  6. 'model' => $model
  7. ]);
  8. $application->run();
  9. });

SHOP Api methods

1) /prepare for prepare
2) /complete for complete

Merchant Api methods

1) /invoice/create for create invoice
2) /invoice/check for check invoice
3) /payment/status for check payment status via payment_id
4) /payment/merchant_train_id for check payment status via merchant_trans_id
5) /cancel for cancel payment
6) /card/create for create card token
7) /card/verify for verify card token
8) /card/payment for payment with card token
9) /card/delete for delete card token