├── .github
└── workflows
│ └── run-tests.yml
├── .gitignore
├── README.md
├── autoload.php
├── composer.json
├── examples
├── .gitkeep
├── Checkout
│ ├── button.php
│ ├── form.php
│ ├── token.php
│ └── url.php
├── Order
│ ├── capture.php
│ ├── list.php
│ ├── reverse.php
│ ├── settlement_scheme_1.php
│ ├── settlement_scheme_3.php
│ └── status.php
├── P2pcredit
│ └── p2pcredit.php
├── Payment
│ ├── recurring.php
│ └── reports.php
├── Pcidss
│ ├── 3dsresult.php
│ ├── non3ds.php
│ └── with3ds.php
├── Subscription
│ ├── cancel.php
│ ├── token.php
│ └── url.php
├── Verification
│ ├── form.php
│ └── url.php
├── configuration.php
├── result.php
└── resultTest.php
├── init.php
├── lib
├── Api
│ ├── Api.php
│ ├── Checkout
│ │ ├── Button.php
│ │ ├── Form.php
│ │ ├── Token.php
│ │ ├── Url.php
│ │ └── Verification.php
│ ├── Order
│ │ ├── Atol.php
│ │ ├── Capture.php
│ │ ├── Reverse.php
│ │ ├── Settlements.php
│ │ ├── Status.php
│ │ ├── Subscription.php
│ │ └── TransactionList.php
│ ├── P2pcredit
│ │ └── Credit.php
│ └── Payment
│ │ ├── Pcidss
│ │ ├── StepOne.php
│ │ └── StepTwo.php
│ │ ├── Rectoken.php
│ │ └── Reports.php
├── Checkout.php
├── Configuration.php
├── Exception
│ ├── ApiException.php
│ ├── HttpClientException.php
│ └── MainException.php
├── Helper
│ ├── ApiHelper.php
│ ├── RequestHelper.php
│ ├── ResponseHelper.php
│ ├── ResultHelper.php
│ └── ValidationHelper.php
├── HttpClient
│ ├── ClientInterface.php
│ ├── HttpCurl.php
│ └── HttpGuzzle.php
├── Order.php
├── P2pcredit.php
├── Payment.php
├── Pcidss.php
├── Response
│ ├── OrderResponse.php
│ ├── PcidssResponse.php
│ └── Response.php
├── Result
│ └── Result.php
├── Subscription.php
└── Verification.php
├── result.php
└── tests
├── .gitkeep
├── CheckoutTest.php
├── ConfigurationTest.php
├── OrderTest.php
├── P2pcreditTest.php
├── PaymentTest.php
├── PcidssTest.php
├── SubscriptionTest.php
├── ValidationTest.php
└── VerificationTest.php
/.github/workflows/run-tests.yml:
--------------------------------------------------------------------------------
1 | name: run-tests
2 |
3 | on: [ push, pull_request ]
4 |
5 | jobs:
6 | test:
7 | runs-on: ubuntu-latest
8 |
9 | strategy:
10 | fail-fast: true
11 | matrix:
12 | php: ["5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1"]
13 |
14 | name: php-${{ matrix.php }}
15 |
16 | steps:
17 | - name: Checkout code
18 | uses: actions/checkout@v2
19 |
20 | - name: Setup PHP
21 | uses: shivammathur/setup-php@v2
22 | with:
23 | php-version: ${{ matrix.php }}
24 |
25 | - name: Validate composer.json and composer.lock
26 | run: composer validate --strict
27 |
28 | - name: Cache Composer packages
29 | id: composer-cache
30 | uses: actions/cache@v2
31 | with:
32 | path: vendor
33 | key: ${{ matrix.php }}-php-${{ hashFiles('**/composer.lock') }}
34 | restore-keys: |
35 | ${{ matrix.php }}-php-
36 |
37 | - name: Install dependencies
38 | run: composer update --no-interaction --prefer-dist --no-progress
39 |
40 | - name: Execute tests
41 | run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests
42 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | composer.lock
3 | composer.phar
4 | /vendor/
5 | *.cache
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IPSP PHP-SDK-v2
2 |
3 |
4 |
5 |
6 |
7 | ## Payment service provider
8 | A payment service provider (PSP) offers shops online services for accepting electronic payments by a variety of payment methods including credit card, bank-based payments such as direct debit, bank transfer, and real-time bank transfer based on online banking. Typically, they use a software as a service model and form a single payment gateway for their clients (merchants) to multiple payment methods.
9 | [read more](https://en.wikipedia.org/wiki/Payment_service_provider)
10 |
11 | ## Installation
12 |
13 | This SDK uses composer.
14 |
15 | Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
16 |
17 | For more information on how to use/install composer, please visit https://github.com/composer/composer
18 |
19 | #### Composer installation
20 | ```cmd
21 | composer require cloudipsp/php-sdk-v2
22 | ```
23 | #### Manual installation
24 | ```cmd
25 | git clone -b master https://github.com/cloudipsp/php-sdk-v2.git
26 | ```
27 |
28 | ```php
29 | 'USD',
40 | 'amount' => 1000
41 | ];
42 | $data = \Cloudipsp\Checkout::url($data);
43 | $url = $data->getUrl();
44 | //$data->toCheckout() - redirect to checkout
45 | ```
46 | # Api
47 |
48 | See [php-docs](https://cloudipsp.github.io/php-docs/)
49 | ## Examples
50 | To check it you can use build-in php server
51 | ```cmd
52 | cd ~/php-sdk-v2
53 | php -S localhost:8000
54 | ```
55 | [Checkout examples](https://github.com/cloudipsp/php-sdk-v2/tree/master/examples)
56 |
57 | ## Author
58 |
59 | D.M.
--------------------------------------------------------------------------------
/autoload.php:
--------------------------------------------------------------------------------
1 | 'USD',
11 | 'amount' => 1000 // convert to 10.00$
12 | ];
13 | $dataBig = [
14 | 'order_desc' => 'tests SDK',
15 | 'currency' => 'USD',
16 | 'amount' => 1000,
17 | 'default_payment_system' => 'card',
18 | 'response_url' => 'http://site.com/responseurl',
19 | 'server_callback_url' => 'http://site.com/callbackurl',
20 | 'merchant_data' => array(
21 | 'fields' => [
22 | [
23 | 'label' => 'Account Id',
24 | 'name' => 'account_id',
25 | 'value' => '127318273',
26 | 'readonly' => true,
27 | 'required' => true,
28 | 'valid' => [
29 | 'pattern' => '[a-z]+'
30 | ]
31 | ],
32 | [
33 | 'label' => 'Comment',
34 | 'name' => 'comment',
35 | 'value' => '',
36 | 'readonly' => false,
37 | 'required' => false,
38 | 'valid' => [
39 | 'pattern' => '[a-z]+'
40 | ]
41 | ]
42 | ]
43 | )
44 | ];
45 | //Call method to generate button
46 | $url = Cloudipsp\Checkout::button($data);
47 | $urlBig = Cloudipsp\Checkout::button($dataBig);
48 | //getting returned data
49 | ?>
50 |
51 |
52 |
53 |
54 | Generate Payment Button
55 |
60 |
61 |
62 |
63 |
64 |
65 | Request data |
66 |
67 |
68 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
70 |
71 |
72 |
73 |
74 | Response status |
75 | There is no response_status |
76 |
77 |
78 | Response button url |
79 | = $url ?> |
80 |
81 |
82 |
83 |
84 |
85 |
86 | Request Data |
87 |
88 |
89 | %s", json_encode(['request' => $dataBig], JSON_PRETTY_PRINT)) ?> |
91 |
92 |
93 |
94 |
95 | Response status |
96 | There is no response_status |
97 |
98 |
99 | Response url |
100 | = $urlBig ?> |
101 |
102 |
103 |
104 |
105 |
106 | getMessage();
109 | }
--------------------------------------------------------------------------------
/examples/Checkout/form.php:
--------------------------------------------------------------------------------
1 | 'USD',
11 | 'amount' => 1000, // convert to 10.00$
12 | 'order_id' => time(),
13 | 'order_desc' => 'test description'
14 | ];
15 | //Call method to generate form
16 | $form_string = Cloudipsp\Checkout::form($data);
17 | //getting returned data
18 | ?>
19 |
20 |
21 |
22 |
23 | Generate form string
24 |
29 |
30 |
31 |
32 |
33 |
34 | Request Data |
35 |
36 |
37 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
39 |
40 |
41 |
42 |
43 | Response status: |
44 | There is no response_status |
45 |
46 |
47 | Rendered form: |
48 | = $form_string ?> |
49 |
50 |
51 | Rendered form fields: |
52 | |
53 |
54 |
55 |
56 |
57 |
58 | getMessage();
61 | }
--------------------------------------------------------------------------------
/examples/Checkout/token.php:
--------------------------------------------------------------------------------
1 | 'USD',
11 | 'amount' => 1000, // convert to 10.00$
12 | 'order_id' => time(),
13 | 'order_desc' => 'test description'
14 | ];
15 | //Call method to generate token
16 | $token = Cloudipsp\Checkout::token($data);
17 | //getting returned data
18 | ?>
19 |
20 |
21 |
22 |
23 | Generate payment token
24 |
29 |
30 |
31 |
32 |
33 |
34 | Request Data |
35 |
36 |
37 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
39 |
40 |
41 |
42 |
43 | Response status: |
44 | = $token->getData()['response_status'] ?> |
45 |
46 |
47 | Response token: |
48 | = $token->getData()['token'] ?> |
49 |
50 |
51 |
52 |
53 |
54 | getMessage();
57 | }
--------------------------------------------------------------------------------
/examples/Checkout/url.php:
--------------------------------------------------------------------------------
1 | 'USD',
11 | 'amount' => 1000 // convert to 10.00$
12 | ];
13 | //some other params
14 | $dataBig = [
15 | 'order_desc' => 'tests SDK',
16 | 'currency' => 'USD',
17 | 'amount' => 1000,
18 | 'default_payment_system' => 'card',
19 | 'response_url' => 'http://site.com/responseurl',
20 | 'server_callback_url' => 'http://site.com/callbackurl',
21 | 'payment_systems' => 'qiwi,yandex,webmoney,card,p24',
22 | 'preauth' => 'N',
23 | 'sender_email' => 'tests@fondy.eu',
24 | 'delayed' => 'Y',
25 | 'lang' => 'ru',
26 | 'product_id' => 'some_product_id',
27 | 'required_rectoken' => 'N',
28 | 'lifetime' => 36000,
29 | 'verification' => 'N',
30 | 'subscription' => 'N',
31 | 'merchant_data' => array(
32 | 'custom_data1' => 'Some string',
33 | 'custom_data2' => '2222',
34 | 'custom_data3' => '3!@#$%^&(()_+?"}',
35 | 'custom_data4' => ['custom_data4_test', 'custom_data4_test2', 'custom_data4_test3' => ['custom_data4_test3_33' => 'custom_data4_test3_33_string']]
36 | )
37 | ];
38 | //Call method to generate url
39 | $url = Cloudipsp\Checkout::url($data);
40 | $urlBig = Cloudipsp\Checkout::url($dataBig);
41 | //getting returned data
42 | ?>
43 |
44 |
45 |
46 |
47 | Generate payment url
48 |
53 |
54 |
55 |
56 |
57 |
58 | Request Data |
59 |
60 |
61 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
63 |
64 |
65 |
66 |
67 | Response status: |
68 | = $url->getData()['response_status'] ?> |
69 |
70 |
71 | Normal Response: |
72 |
73 | getData()) ?>
74 | |
75 |
76 |
77 | Response url: |
78 | = $url->getUrl() ?> |
79 |
80 |
81 |
82 |
83 |
84 |
85 | Request Data: |
86 |
87 |
88 | %s", json_encode(['request' => $dataBig], JSON_PRETTY_PRINT)) ?> |
90 |
91 |
92 |
93 |
94 | Response status: |
95 | = $urlBig->getData()['response_status'] ?> |
96 |
97 |
98 | Normal Response: |
99 |
100 | getData()) ?>
101 | |
102 |
103 |
104 | Response url: |
105 | = $urlBig->getUrl() ?> |
106 |
107 |
108 |
109 |
110 |
111 | getMessage();
114 | }
--------------------------------------------------------------------------------
/examples/Order/capture.php:
--------------------------------------------------------------------------------
1 | time(),
11 | 'card_number' => '4444555511116666',
12 | 'cvv2' => '333',
13 | 'expiry_date' => '1232',
14 | 'currency' => 'USD',
15 | 'preauth' => 'Y',
16 | 'amount' => 1000,
17 | 'client_ip' => '127.2.2.1'
18 | ];
19 | //Call method to generate order for capture
20 | $captured_order_data = Cloudipsp\Pcidss::start($TestOrderData); //next order will be captured
21 | //Capture request always generated by merchant using host-to-host
22 | // Required param to capture it prev order_id see more https://docs.fondy.eu/docs/page/12/
23 | if ($captured_order_data->isApproved()) {// Checking if prev payment valid(signature)
24 | $dataToCapture = [
25 | 'currency' => 'USD',
26 | 'amount' => 1000,
27 | 'order_id' => $TestOrderData['order_id']
28 | ];
29 | $capture_order = Cloudipsp\Order::capture($dataToCapture);
30 | }
31 | //getting returned data
32 | ?>
33 |
34 |
35 |
36 |
37 | Capture pre-purchase
38 |
43 |
44 |
45 |
46 |
47 |
48 | Request to capture order |
49 |
50 |
51 | %s", json_encode(['request' => $dataToCapture], JSON_PRETTY_PRINT)) ?> |
53 |
54 |
55 |
56 |
57 | Response status: |
58 | = $capture_order->getData()['response_status'] ?> |
59 |
60 |
61 | Normal response: |
62 |
63 | getData()); ?>
64 | |
65 |
66 |
67 | Check order is captured: |
68 | isCaptured(true)); ?> |
69 |
70 |
71 |
72 |
73 |
74 | getMessage();
77 | }
78 |
--------------------------------------------------------------------------------
/examples/Order/list.php:
--------------------------------------------------------------------------------
1 | time(),
11 | 'card_number' => '4444555511116666',
12 | 'cvv2' => '333',
13 | 'expiry_date' => '1232',
14 | 'currency' => 'USD',
15 | 'amount' => 1000,
16 | 'client_ip' => '127.2.2.1'
17 | ];
18 | //Call method to generate order
19 | $status_order_data = Cloudipsp\Pcidss::start($TestOrderData);
20 | if ($status_order_data->isApproved()) {// Checking if prev payment valid(signature)
21 | $dataToGetList = [
22 | 'order_id' => $TestOrderData['order_id']
23 | ];
24 | $listData = Cloudipsp\Order::transactionList($dataToGetList);
25 | }
26 | //getting returned data
27 | ?>
28 |
29 |
30 |
31 |
32 | Order transactions list
33 |
38 |
39 |
40 |
41 |
42 |
43 | Request transaction list data |
44 |
45 |
46 | %s", json_encode(['request' => $dataToGetList], JSON_PRETTY_PRINT)) ?> |
48 |
49 |
50 |
51 |
52 | Normal response: |
53 |
54 | getData()); ?>
55 | |
56 |
57 |
58 | Is captured transaction: |
59 |
60 | isCapturedByList()); ?>
61 | |
62 |
63 |
64 |
65 |
66 |
67 |
68 | getMessage();
71 | }
--------------------------------------------------------------------------------
/examples/Order/reverse.php:
--------------------------------------------------------------------------------
1 | time(),
11 | 'card_number' => '4444555511116666',
12 | 'cvv2' => '333',
13 | 'expiry_date' => '1232',
14 | 'currency' => 'USD',
15 | 'amount' => 1000,
16 | 'client_ip' => '127.2.2.1'
17 | ];
18 | // Call method to generate order for refund
19 | $reverse_order_data = Cloudipsp\Pcidss::start($TestOrderData); //next order will be refunded
20 | // Refund request always generated by merchant using host-to-host
21 | // Required param to refund it "order_id" see more https://docs.fondy.eu/docs/page/12/
22 | if ($reverse_order_data->isApproved()) {// Checking if prev payment valid(signature)
23 | $dataToReverse = [
24 | 'currency' => 'USD',
25 | 'amount' => 100,
26 | 'order_id' => $TestOrderData['order_id']
27 | ];
28 | $refund_order = Cloudipsp\Order::reverse($dataToReverse);
29 | }
30 | //getting returned data
31 | ?>
32 |
33 |
34 |
35 |
36 | Order refund
37 |
42 |
43 |
44 |
45 |
46 |
47 | Request data |
48 |
49 |
50 | %s", json_encode(['request' => $dataToReverse], JSON_PRETTY_PRINT)) ?> |
52 |
53 |
54 |
55 |
56 | Response status: |
57 | = $refund_order->getData()['response_status'] ?> |
58 |
59 |
60 | Normal response: |
61 |
62 | getData()); ?>
63 | |
64 |
65 |
66 | Check if order is refunded: |
67 | isReversed()); ?> |
68 |
69 |
70 |
71 |
72 |
73 | getMessage();
76 | }
--------------------------------------------------------------------------------
/examples/Order/settlement_scheme_1.php:
--------------------------------------------------------------------------------
1 | 'USD',
11 | 'amount' => 1000, // convert to 10.00$
12 | 'order_desc' => 'tests SDK',
13 | ];
14 | //some other params
15 | $receiver = [
16 | [
17 | 'requisites' => [
18 | 'amount' => 500,
19 | 'merchant_id' => 600001
20 | ],
21 | 'type' => 'merchant'
22 | ],
23 | [
24 | 'requisites' => [
25 | 'amount' => 500,
26 | 'merchant_id' => 700001
27 | ],
28 | 'type' => 'merchant'
29 | ]
30 | ];
31 | $data['receiver'] = $receiver;
32 | //Call method to generate url
33 | \Cloudipsp\Configuration::setMerchantId(600001);
34 | \Cloudipsp\Configuration::setApiVersion('2.0');
35 | $url = Cloudipsp\Checkout::url($data);
36 | //getting returned data
37 | ?>
38 |
39 |
40 |
41 |
42 | Capture pre-purchase
43 |
48 |
49 |
50 |
51 |
52 |
53 | Request Data |
54 |
55 |
56 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
58 |
59 |
60 |
61 |
62 | Normal Response: |
63 |
64 | getData()) ?>
65 | |
66 |
67 |
68 | Response url: |
69 | = $url->getUrl() ?> |
70 |
71 |
72 |
73 |
74 |
75 | getMessage();
78 | }
79 |
--------------------------------------------------------------------------------
/examples/Order/settlement_scheme_3.php:
--------------------------------------------------------------------------------
1 | 'settelment_' . time(),
12 | 'card_number' => '4444555511116666',
13 | 'cvv2' => '333',
14 | 'expiry_date' => '1232',
15 | 'currency' => 'USD',
16 | 'preauth' => 'Y',
17 | 'amount' => 1000,
18 | 'client_ip' => '127.2.2.1'
19 | ];
20 | //Call method to generate order for capture
21 | $captured_order_data = Cloudipsp\Pcidss::start($TestOrderData); //next order will be captured
22 | //Minimal data set, all other required params will generated automatically
23 | $data = [
24 | 'currency' => 'USD',
25 | 'amount' => 1000, // convert to 10.00$
26 | 'order_desc' => 'tests SDK',
27 | 'operation_id' => $TestOrderData['order_id']
28 | ];
29 | //some other params
30 | $receiver = [
31 | [
32 | 'requisites' => [
33 | 'amount' => 500,
34 | 'merchant_id' => 600001
35 | ],
36 | 'type' => 'merchant'
37 | ],
38 | [
39 | 'requisites' => [
40 | 'amount' => 500,
41 | 'merchant_id' => 700001
42 | ],
43 | 'type' => 'merchant'
44 | ]
45 | ];
46 | $data['receiver'] = $receiver;
47 | //Call method to generate url
48 | \Cloudipsp\Configuration::setApiVersion('2.0');
49 | $url = Cloudipsp\Order::settlement($data);
50 | //getting returned data
51 | ?>
52 |
53 |
54 |
55 |
56 | Capture pre-purchase
57 |
62 |
63 |
64 |
65 |
66 |
67 | Request Data |
68 |
69 |
70 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
72 |
73 |
74 |
75 |
76 | Normal Response: |
77 |
78 | getData()) ?>
79 | |
80 |
81 |
82 |
83 |
84 |
85 | getMessage();
88 | }
89 |
--------------------------------------------------------------------------------
/examples/Order/status.php:
--------------------------------------------------------------------------------
1 | time(),
11 | 'card_number' => '4444555511116666',
12 | 'cvv2' => '333',
13 | 'expiry_date' => '1232',
14 | 'currency' => 'USD',
15 | 'amount' => 1000,
16 | 'client_ip' => '127.2.2.1'
17 | ];
18 | //Call method to generate order
19 | $status_order_data = Cloudipsp\Pcidss::start($TestOrderData);
20 | if ($status_order_data->isApproved()) {// Checking if prev payment valid(signature)
21 | $dataToGetStatus = [
22 | 'order_id' => $TestOrderData['order_id']
23 | ];
24 | $s_order = Cloudipsp\Order::status($dataToGetStatus);
25 | }
26 | //getting returned data
27 | ?>
28 |
29 |
30 |
31 |
32 | Order Status
33 |
38 |
39 |
40 |
41 |
42 |
43 | Request data |
44 |
45 |
46 | %s", json_encode(['request' => $dataToGetStatus], JSON_PRETTY_PRINT)) ?> |
48 |
49 |
50 |
51 |
52 | Response status: |
53 | = $s_order->getData()['response_status'] ?> |
54 |
55 |
56 | Normal response: |
57 |
58 | getData()); ?>
59 | |
60 |
61 |
62 | Check order is valid: |
63 | isValid()); ?> |
64 |
65 |
66 |
67 |
68 |
69 | getMessage();
72 | }
--------------------------------------------------------------------------------
/examples/P2pcredit/p2pcredit.php:
--------------------------------------------------------------------------------
1 | 'USD',
12 | 'amount' => 111,
13 | 'receiver_card_number' => '4444555511116666'
14 | ];
15 | //Call method to generate order
16 | $orderData = Cloudipsp\P2pcredit::start($TestOrderData);
17 | //getting returned data
18 | ?>
19 |
20 |
21 |
22 |
23 | P2P card credit
24 |
29 |
30 |
31 |
32 |
33 |
34 | P2P card credit |
35 |
36 |
37 | %s", json_encode(['request' => $TestOrderData], JSON_PRETTY_PRINT)) ?> |
39 |
40 |
41 |
42 |
43 | Response status: |
44 | = $orderData->getData()['response_status'] ?> |
45 |
46 |
47 | Normal response: |
48 |
49 | getData()); ?>
50 | |
51 |
52 |
53 | Check order is approved: |
54 | isApproved()); ?> |
55 |
56 |
57 | Check order data is valid: |
58 | isValid()); ?> |
59 |
60 |
61 |
62 |
63 |
64 | getMessage();
67 | }
--------------------------------------------------------------------------------
/examples/Payment/recurring.php:
--------------------------------------------------------------------------------
1 | time(),
11 | 'card_number' => '4444555511116666',
12 | 'cvv2' => '333',
13 | 'expiry_date' => '1232',
14 | 'currency' => 'USD',
15 | 'required_rectoken' => 'Y',
16 | 'amount' => 1000,
17 | 'client_ip' => '127.2.2.1'
18 | ];
19 | //Call method to generate order for getting token required
20 | $Token = Cloudipsp\Pcidss::start($TestOrderData); //next order will be captured
21 | //Capture request always generated by merchant using host-to-host
22 | // Required params see more https://docs.fondy.eu/docs/page/10/
23 | if ($Token->isApproved()) {// Checking if prev payment valid(signature)
24 | $recurringData = [
25 | 'currency' => 'USD',
26 | 'amount' => 1000,
27 | 'rectoken' => $Token->getData()['rectoken']
28 | ];
29 | $recurring_order = Cloudipsp\Payment::recurring($recurringData);
30 | }
31 | //getting returned data
32 | ?>
33 |
34 |
35 |
36 |
37 | Purchase using card token
38 |
43 |
44 |
45 |
46 |
47 |
48 | Request using card token |
49 |
50 |
51 | %s", json_encode(['request' => $recurringData], JSON_PRETTY_PRINT)) ?> |
53 |
54 |
55 |
56 |
57 | Response status: |
58 | = $recurring_order->getData()['response_status'] ?> |
59 |
60 |
61 | Normal response: |
62 |
63 | getData()); ?>
64 | |
65 |
66 |
67 | Check order is approved: |
68 | isApproved()); ?> |
69 |
70 |
71 |
72 |
73 |
74 | getMessage();
77 | }
--------------------------------------------------------------------------------
/examples/Payment/reports.php:
--------------------------------------------------------------------------------
1 | date('d.m.Y H:i:s', time() - 7200),
10 | "date_to" => date('d.m.Y H:i:s', time() - 3600),
11 | ];
12 | $reports = \Cloudipsp\Payment::reports($data);
13 | //getting returned data
14 | ?>
15 |
16 |
17 |
18 |
19 | Payment reports
20 |
25 |
26 |
27 |
28 |
29 |
30 | Payment reports request |
31 |
32 |
33 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
35 |
36 |
37 |
38 |
39 | Normal response: |
40 |
41 | getData()); ?>
42 | |
43 |
44 |
45 |
46 |
47 |
48 | getMessage();
51 | }
--------------------------------------------------------------------------------
/examples/Pcidss/3dsresult.php:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
21 | Pcidss 3ds
22 |
27 |
28 |
29 |
30 |
31 |
32 | Submit request 3ds card |
33 |
34 |
35 | %s", json_encode(['request' => $dataTo3dsSubmit], JSON_PRETTY_PRINT)) ?> |
38 |
39 |
40 |
41 |
42 | Response status: |
43 | = $orderData->getData()['response_status'] ?> |
44 |
45 |
46 | Normal response: |
47 |
48 | getData()); ?>
49 | |
50 |
51 |
52 |
53 |
54 |
55 | getMessage();
58 | }
--------------------------------------------------------------------------------
/examples/Pcidss/non3ds.php:
--------------------------------------------------------------------------------
1 | time(),
11 | 'card_number' => '4444555511116666',
12 | 'cvv2' => '333',
13 | 'expiry_date' => '1232',
14 | 'currency' => 'USD',
15 | 'amount' => 1000,
16 | 'client_ip' => '127.2.2.1'
17 | ];
18 | //Call method to generate order
19 | $orderData = Cloudipsp\Pcidss::start($TestOrderData);
20 | //getting returned data
21 | ?>
22 |
23 |
24 |
25 |
26 | Pcidss non-3ds
27 |
32 |
33 |
34 |
35 |
36 |
37 | Request non-3ds card |
38 |
39 |
40 | %s", json_encode(['request' => $TestOrderData], JSON_PRETTY_PRINT)) ?> |
42 |
43 |
44 |
45 |
46 | Response status: |
47 | = $orderData->getData()['response_status'] ?> |
48 |
49 |
50 | Normal response: |
51 |
52 | getData()); ?>
53 | |
54 |
55 |
56 | Check if card is 3ds: |
57 | is3ds()); ?> |
58 |
59 |
60 |
61 |
62 |
63 | getMessage();
66 | }
--------------------------------------------------------------------------------
/examples/Pcidss/with3ds.php:
--------------------------------------------------------------------------------
1 | time(),
11 | 'card_number' => '4444555566661111', //test card with 3ds
12 | 'cvv2' => '333',
13 | 'expiry_date' => '1232',
14 | 'currency' => 'USD',
15 | 'amount' => 1000,
16 | 'client_ip' => '127.2.2.1'
17 | ];
18 | //Call method to generate order
19 | $orderData = Cloudipsp\Pcidss::start($TestOrderData);
20 | //getting returned data
21 |
22 | //getting response url
23 | $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
24 | $domainName = $_SERVER['HTTP_HOST'] . '/';
25 | $response_url = $protocol . $domainName;
26 | //starting session to write order_id
27 | session_start();
28 | $_SESSION['order_id'] = $TestOrderData['order_id'];
29 | ?>
30 |
31 |
32 |
33 |
34 | Pcidss 3ds
35 |
40 |
41 |
42 |
43 |
44 |
45 | Request 3ds card |
46 |
47 |
48 | %s", json_encode(['request' => $TestOrderData], JSON_PRETTY_PRINT)) ?> |
50 |
51 |
52 |
53 |
54 | Response status: |
55 | = $orderData->getData()['response_status'] ?> |
56 |
57 |
58 | Normal response: |
59 |
60 | getData()); ?>
61 | |
62 |
63 |
64 | Check if card has 3ds: |
65 | is3ds()); ?> |
66 |
67 |
68 | Build an HTML form and using it submit customer to acs_url: |
69 | getData(), $response_url . '/examples/Pcidss/3dsresult.php')); ?> |
70 |
71 |
72 |
73 |
74 |
75 | getMessage();
78 | }
79 |
--------------------------------------------------------------------------------
/examples/Subscription/cancel.php:
--------------------------------------------------------------------------------
1 | time(),
11 | 'card_number' => '4444555511116666',
12 | 'cvv2' => '333',
13 | 'expiry_date' => '1232',
14 | 'currency' => 'UAH',
15 | 'amount' => 1000,
16 | 'client_ip' => '127.2.2.1',
17 | 'recurring_data' => [
18 | 'start_time' => date("Y-m-d"),
19 | 'amount' => 1000,
20 | 'every' => 30,
21 | 'period' => 'day',
22 | 'state' => 'y',
23 | 'readonly' => 'y'
24 | ]
25 | ];
26 | //Call method to start calendar order subscription
27 | \Cloudipsp\Configuration::setApiVersion('2.0'); //allow only json, api protocol 2.0
28 | $orderData = Cloudipsp\Pcidss::start($TestOrderData);
29 | $cancel = Cloudipsp\Subscription::stop($orderData->getData()['order_id']);
30 | //getting returned data
31 | ?>
32 |
33 |
34 |
35 |
36 | Generate subscription Payment token
37 |
42 |
43 |
44 |
45 |
46 |
47 | Request Data: |
48 |
49 |
50 | %s", json_encode(['request' => $TestOrderData], JSON_PRETTY_PRINT)) ?> |
52 |
53 |
54 |
55 |
56 | Normal cancel response: |
57 |
58 | getData()) ?>
59 | |
60 |
61 |
62 | Response subscription stop order_id: |
63 | getData()['order_id']) ?> |
64 |
65 |
66 |
67 |
68 |
69 | getMessage();
72 | }
73 |
--------------------------------------------------------------------------------
/examples/Subscription/token.php:
--------------------------------------------------------------------------------
1 | 'USD',
11 | 'amount' => 1000, // convert to 10.00$
12 | 'recurring_data' => [
13 | 'start_time' => '2021-12-24',
14 | 'amount' => 1000,
15 | 'every' => 30,
16 | 'period' => 'day',
17 | 'state' => 'y',
18 | 'readonly' => 'y'
19 | ]
20 |
21 | ];
22 | //Call method to generate token
23 | \Cloudipsp\Configuration::setApiVersion('2.0'); //allow only json, api protocol 2.0
24 | $url = Cloudipsp\Subscription::token($data);
25 | //getting returned data
26 | ?>
27 |
28 |
29 |
30 |
31 | Generate subscription Payment token
32 |
37 |
38 |
39 |
40 |
41 |
42 | Request Data: |
43 |
44 |
45 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
47 |
48 |
49 |
50 |
51 | Normal Response: |
52 |
53 | getData()) ?>
54 | |
55 |
56 |
57 | Response subscription token: |
58 | getData()['token']) ?> |
59 |
60 |
61 |
62 |
63 |
64 | getMessage();
67 | }
--------------------------------------------------------------------------------
/examples/Subscription/url.php:
--------------------------------------------------------------------------------
1 | 'USD',
11 | 'amount' => 1000, // convert to 10.00$
12 | 'recurring_data' => [
13 | 'start_time' => '2021-12-24',
14 | 'amount' => 1000,
15 | 'every' => 30,
16 | 'period' => 'day',
17 | 'state' => 'y',
18 | 'readonly' => 'y'
19 | ]
20 |
21 | ];
22 | //Call method to generate url
23 | \Cloudipsp\Configuration::setApiVersion('2.0'); //allow only json, api protocol 2.0
24 | $url = Cloudipsp\Subscription::url($data);
25 | //getting returned data
26 | ?>
27 |
28 |
29 |
30 |
31 | Generate subscription Payment Url
32 |
37 |
38 |
39 |
40 |
41 |
42 | Request Data |
43 |
44 |
45 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
47 |
48 |
49 |
50 |
51 | Payment id: |
52 | = $url->getData()['payment_id'] ?> |
53 |
54 |
55 | Normal response: |
56 |
57 | getData()) ?>
58 | |
59 |
60 |
61 | Response subscription url: |
62 | getUrl()) ?> |
63 |
64 |
65 |
66 |
67 |
68 | getMessage();
71 | }
--------------------------------------------------------------------------------
/examples/Verification/form.php:
--------------------------------------------------------------------------------
1 | 'code', //default - amount
11 | 'currency' => 'USD',
12 | 'amount' => 100 // convert to 1.00$
13 | ];
14 | //Call method to generate form
15 | $form_string = \Cloudipsp\Verification::form($data);
16 | //getting returned data
17 | ?>
18 |
19 |
20 |
21 |
22 | Generate verification form string
23 |
28 |
29 |
30 |
31 |
32 |
33 | Request data: |
34 |
35 |
36 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
38 |
39 |
40 |
41 |
42 | Response status: |
43 | There is no response_status |
44 |
45 |
46 | Rendered form: |
47 | = $form_string ?> |
48 |
49 |
50 | Rendered form string: |
51 | |
52 |
53 |
54 |
55 |
56 |
57 | getMessage();
60 | }
--------------------------------------------------------------------------------
/examples/Verification/url.php:
--------------------------------------------------------------------------------
1 | 'code', //default - amount
11 | 'currency' => 'USD',
12 | 'amount' => 100 // convert to 1.00$
13 | ];
14 | //Call method to generate url
15 | $url = \Cloudipsp\Verification::url($data);
16 | //getting returned data
17 | ?>
18 |
19 |
20 |
21 |
22 | Generate verification url
23 |
28 |
29 |
30 |
31 |
32 |
33 | Request data: |
34 |
35 |
36 | %s", json_encode(['request' => $data], JSON_PRETTY_PRINT)) ?> |
38 |
39 |
40 |
41 |
42 | Response status: |
43 | = $url->getData()['response_status'] ?> |
44 |
45 |
46 | Normal Response: |
47 |
48 | getData()) ?>
49 | |
50 |
51 |
52 | Response url: |
53 | = $url->getUrl() ?> |
54 |
55 |
56 |
57 |
58 |
59 | getMessage();
62 | }
--------------------------------------------------------------------------------
/examples/configuration.php:
--------------------------------------------------------------------------------
1 |
23 |
24 |
25 |
26 |
27 |
28 | Checking payment result
29 |
30 |
35 |
36 |
37 |
38 |
39 |
40 | Result data: |
41 |
42 |
43 | %s", json_encode($callbackData, JSON_PRETTY_PRINT)) ?> |
45 |
46 |
47 |
48 |
49 | Result status: |
50 | = $result->getData()['response_status'] ?> |
51 |
52 |
53 | Normal result: |
54 |
55 | getData()) ?>
56 | |
57 |
58 |
59 | Result is valid: |
60 | isValid()); ?> |
61 |
62 |
63 | Payment is approved: |
64 | isApproved()); ?> |
65 |
66 |
67 | Payment is expired: |
68 | isExpired()); ?> |
69 |
70 |
71 |
72 |
73 |
74 | getMessage();
77 | }
--------------------------------------------------------------------------------
/examples/resultTest.php:
--------------------------------------------------------------------------------
1 | $_SERVER['SERVER_PORT'],
10 | CURLOPT_URL => $response_url . "/examples/result.php",
11 | CURLOPT_RETURNTRANSFER => true,
12 | CURLOPT_ENCODING => "",
13 | CURLOPT_MAXREDIRS => 10,
14 | CURLOPT_TIMEOUT => 30,
15 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
16 | CURLOPT_CUSTOMREQUEST => "POST",
17 | CURLOPT_POSTFIELDS => "{\"rrn\": \"\", \"masked_card\": \"444455XXXXXX6666\", \"sender_cell_phone\": \"\", \"response_signature_string\": \"**********|111|USD|111|123456|444455|VISA|USD|7|444455XXXXXX6666|1396424|1396424_1da4a65b81fdaf934c535e352a776744|approved|21.05.2018 13:50:55|93088761|card|success|0|0|purchase\", \"response_status\": \"success\", \"sender_account\": \"\", \"fee\": \"\", \"rectoken_lifetime\": \"\", \"reversal_amount\": \"0\", \"settlement_amount\": \"0\", \"actual_amount\": \"111\", \"order_status\": \"approved\", \"response_description\": \"\", \"verification_status\": \"\", \"order_time\": \"21.05.2018 13:50:55\", \"actual_currency\": \"USD\", \"order_id\": \"1396424_1da4a65b81fdaf934c535e352a776744\", \"parent_order_id\": \"\", \"merchant_data\": \"\", \"tran_type\": \"purchase\", \"eci\": \"7\", \"settlement_date\": \"\", \"payment_system\": \"card\", \"rectoken\": \"\", \"approval_code\": \"123456\", \"merchant_id\": 1396424, \"settlement_currency\": \"\", \"payment_id\": 93088761, \"product_id\": \"\", \"currency\": \"USD\", \"card_bin\": 444455, \"response_code\": \"\", \"card_type\": \"VISA\", \"amount\": \"111\", \"sender_email\": \"\", \"signature\": \"7725ca95944de78550c3ca132c1e6602707afa90\"}",
18 | CURLOPT_HTTPHEADER => array(
19 | "cache-control: no-cache",
20 | "content-type: application/json"
21 | ),
22 | ));
23 |
24 | $response = curl_exec($curl);
25 | $err = curl_error($curl);
26 |
27 | curl_close($curl);
28 |
29 | if ($err) {
30 | echo "cURL Error #:" . $err;
31 | } else {
32 | print ($response);
33 | }
--------------------------------------------------------------------------------
/init.php:
--------------------------------------------------------------------------------
1 | time(),
19 | 'currency' => 'USD',
20 | 'amount' => 111,
21 | 'response_url' => 'http://localhost/result.php'// response page
22 | ];
23 |
24 | $data = \Cloudipsp\Checkout::url($dataC);
25 | $data->toCheckout();
26 | //end
27 |
--------------------------------------------------------------------------------
/lib/Api/Api.php:
--------------------------------------------------------------------------------
1 | version = Configuration::getApiVersion();
39 | $this->mid = Configuration::getMerchantId();
40 | $this->setKeyByOperationType($type);
41 | if (empty($this->mid) or !is_numeric($this->mid))
42 | throw new ApiException('Merchant ID is empty or invalid.');
43 | if (empty($this->secretKey))
44 | throw new ApiException('Secret Key is empty or invalid.');
45 | $this->client = Configuration::getHttpClient();
46 | $this->requestType = Configuration::getRequestType();
47 | }
48 |
49 | /**
50 | * @param $method
51 | * @param $url
52 | * @param $headers
53 | * @param $data
54 | * @return mixed
55 | * @throws ApiException
56 | */
57 | public function Request($method, $url, $headers, $data)
58 | {
59 | $result = [];
60 | $url = $this->createUrl($url);
61 | if (isset($data['order_id']))
62 | $result['order_id'] = $data['order_id'];
63 | $data = $this->getDataByVersion($data);
64 | $headers = Helper\RequestHelper::parseHeaders($headers, $this->requestType);
65 | $response = $this->client->request($method, $url, $headers, $data);
66 | if (!$response)
67 | throw new ApiException('Unknown error.');
68 | $result['response'] = $response;
69 | return $result;
70 |
71 | }
72 |
73 | /**
74 | * @param $data
75 | * @return string or array
76 | */
77 | protected function converDataV1($data)
78 | {
79 | if (!isset($data['signature']))
80 | $data['signature'] = Helper\ApiHelper::generateSignature($data, $this->secretKey, $this->version);
81 | switch ($this->requestType) {
82 | case 'xml':
83 | $convertedData = Helper\ApiHelper::toXML(['request' => $data]);
84 | break;
85 | case 'form':
86 | $convertedData = Helper\ApiHelper::toFormData($data);
87 | break;
88 | case 'json':
89 | $convertedData = Helper\ApiHelper::toJSON(['request' => $data]);
90 | break;
91 | default:
92 | $convertedData = null;
93 | }
94 |
95 | return $convertedData;
96 | }
97 |
98 | /**
99 | * @param $data
100 | * @return string
101 | */
102 | protected function converDataV2($data)
103 | {
104 | if (isset($data['signature']))
105 | unset($data['signature']);
106 | $convertedData = [
107 | "version" => "2.0",
108 | "data" => base64_encode(Helper\ApiHelper::toJSON(['order' => $data]))
109 | ];
110 |
111 | $convertedData["signature"] = Helper\ApiHelper::generateSignature($convertedData["data"], $this->secretKey, $this->version);
112 |
113 | return Helper\ApiHelper::toJSON(['request' => $convertedData]);
114 | }
115 |
116 | /**
117 | * @param $params
118 | * @return mixed
119 | */
120 | protected function prepareParams($params)
121 | {
122 | $prepared_params = $params;
123 |
124 | if (!isset($prepared_params['merchant_id'])) {
125 | $prepared_params['merchant_id'] = $this->mid;
126 | }
127 |
128 | if (!isset($prepared_params['order_id'])) {
129 | $prepared_params['order_id'] = Helper\ApiHelper::generateOrderID($this->mid);
130 | }
131 |
132 | if (!isset($prepared_params['order_desc'])) {
133 | $prepared_params['order_desc'] = Helper\ApiHelper::generateOrderDesc($prepared_params['order_id']);
134 | }
135 |
136 | if (isset($prepared_params['merchant_data']) && is_array($prepared_params['merchant_data'])) {
137 | $prepared_params['merchant_data'] = Helper\ApiHelper::toJSON($prepared_params['merchant_data']);
138 | }
139 |
140 | if (isset($prepared_params['recurring_data']) && $this->version === '1.0')
141 | throw new \InvalidArgumentException('Reccuring_data allowed only for api version \'2.0\'');
142 |
143 | if (isset($prepared_params['reservation_data']) && is_array($prepared_params['reservation_data'])) {
144 | $prepared_params['reservation_data'] = base64_encode(Helper\ApiHelper::toJSON($prepared_params['reservation_data']));
145 | }
146 |
147 | return $prepared_params;
148 | }
149 |
150 | /**
151 | * @param $data
152 | * @return string
153 | * @throws ApiException
154 | */
155 | protected function getDataByVersion($data)
156 | {
157 | if (!$this->version)
158 | throw new ApiException('Unknown api version');
159 |
160 | switch ($this->version) {
161 | case '1.0':
162 | $convertedData = $this->converDataV1($data);
163 | break;
164 | case '2.0':
165 | if ($this->requestType != 'json') {
166 | throw new ApiException('Invalid request type. In protocol \'2.0\' only \'json\' allowed.');
167 | }
168 | $convertedData = $this->converDataV2($data);
169 | break;
170 | default:
171 | $convertedData = null;
172 | }
173 | return $convertedData;
174 | }
175 |
176 | protected function validate($params, $required, $dateFormat = '')
177 | {
178 | Helper\ValidationHelper::validateRequiredParams($params, $required, $dateFormat);
179 | }
180 |
181 | /**
182 | * @param $url
183 | * @return string
184 | */
185 | protected function createUrl($url)
186 | {
187 | return Configuration::getApiUrl() . $url;
188 | }
189 |
190 | /**
191 | * setting secret key by operation type
192 | * @param $type
193 | */
194 | protected function setKeyByOperationType($type = '')
195 | {
196 | if ($type === 'credit') {
197 | $this->secretKey = Configuration::getCreditKey();
198 | } else {
199 | $this->secretKey = Configuration::getSecretKey();
200 | }
201 | }
202 | }
203 |
--------------------------------------------------------------------------------
/lib/Api/Checkout/Button.php:
--------------------------------------------------------------------------------
1 | 'integer',
19 | 'order_desc' => 'string',
20 | 'amount' => 'integer',
21 | 'currency' => 'string'
22 | ];
23 |
24 | /**
25 | * @param $data
26 | * @return string
27 | */
28 | public function get($data)
29 | {
30 | if (Configuration::getApiVersion() !== $this->requiredApiVersion) {
31 | trigger_error('Button method allowed only for api version \'1.0\'', E_USER_NOTICE);
32 | Configuration::setApiVersion($this->requiredApiVersion);
33 | }
34 | $requestData = $this->prepareButtonParams($data);
35 | $url = $this->createUrl($this->url);
36 | $this->validate($requestData, $this->requiredParams);
37 | return ApiHelper::generateButtonUrl($requestData, $url);
38 | }
39 |
40 | /**
41 | * @param $params
42 | * @return mixed
43 | */
44 | protected function prepareButtonParams($params)
45 | {
46 | $prepared_params = $params;
47 |
48 | if (!isset($prepared_params['merchant_id'])) {
49 | $prepared_params['merchant_id'] = $this->mid;
50 | }
51 | if (!isset($prepared_params['order_id'])) {
52 | $prepared_params['order_id'] = ApiHelper::generateOrderID($this->mid);
53 | }
54 | if (!isset($prepared_params['order_desc'])) {
55 | $prepared_params['order_desc'] = ApiHelper::generateOrderDesc($prepared_params['order_id']);
56 | }
57 | if (isset($prepared_params['merchant_data']['fields'])) {
58 | $prepared_params['fields'] = $prepared_params['merchant_data']['fields'];
59 | }
60 | if (isset($prepared_params['amount'])) {
61 | $prepared_params['amount'] = $prepared_params['amount'] / 100;
62 | }
63 | unset($prepared_params['merchant_data']);
64 | return $prepared_params;
65 | }
66 | }
--------------------------------------------------------------------------------
/lib/Api/Checkout/Form.php:
--------------------------------------------------------------------------------
1 | 'integer',
19 | 'order_desc' => 'string',
20 | 'amount' => 'integer',
21 | 'currency' => 'string',
22 | 'signature' => 'string'
23 | ];
24 |
25 | /**
26 | * @param $data
27 | * @return string
28 | */
29 | public function get($data)
30 | {
31 |
32 | if (Configuration::getApiVersion() !== $this->requiredApiVersion) {
33 | trigger_error('Form method allowed only for api version \'1.0\'', E_USER_NOTICE);
34 | Configuration::setApiVersion($this->requiredApiVersion);
35 | }
36 | $requestData = $this->prepareParams($data);
37 | if (!isset($requestData['signature']))
38 | $requestData['signature'] = ApiHelper::generateSignature($requestData, $this->secretKey, $this->version);
39 | $url = $this->createUrl($this->url);
40 | $this->validate($requestData, $this->requiredParams);
41 | return ApiHelper::generatePaymentForm($requestData, $url);
42 | }
43 | }
--------------------------------------------------------------------------------
/lib/Api/Checkout/Token.php:
--------------------------------------------------------------------------------
1 | 'integer',
17 | 'order_desc' => 'string',
18 | 'amount' => 'integer',
19 | 'currency' => 'string'
20 | ];
21 |
22 | /**
23 | * @param $data
24 | * @param array $headers
25 | * @return mixed
26 | * @throws \Cloudipsp\Exception\ApiException
27 | */
28 | public function get($data, $headers = [], $requiredParams = [])
29 | {
30 | if ($this->requestType != 'json')
31 | throw new ApiException('Invalid request type. In this method only \'json\' allowed.');
32 | if (!empty($requiredParams))
33 | $this->requiredParams = array_merge($requiredParams, $this->requiredParams);
34 | $requestData = $this->prepareParams($data);
35 | $this->validate($requestData, $this->requiredParams);
36 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/lib/Api/Checkout/Url.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_desc' => 'string',
17 | 'amount' => 'integer',
18 | 'currency' => 'string'
19 | ];
20 |
21 | /**
22 | * @param $data
23 | * @param array $headers
24 | * @param array $requiredParams
25 | * @return mixed
26 | * @throws \Cloudipsp\Exception\ApiException
27 | */
28 | public function get($data, $headers = [], $requiredParams = [])
29 | {
30 | if (!empty($requiredParams))
31 | $this->requiredParams = array_merge($requiredParams, $this->requiredParams);
32 | $requestData = $this->prepareParams($data);
33 | $this->validate($requestData, $this->requiredParams);
34 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/lib/Api/Checkout/Verification.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_desc' => 'string',
17 | 'amount' => 'integer',
18 | 'currency' => 'string'
19 | ];
20 |
21 | /**
22 | * @param $data
23 | * @param array $headers
24 | * @return mixed
25 | * @throws \Cloudipsp\Exception\ApiException
26 | */
27 | public function get($data, $headers = [])
28 | {
29 | $requestData = $this->prepareParams($data);
30 | $this->validate($requestData, $this->requiredParams);
31 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/lib/Api/Order/Atol.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_id' => 'string'
17 | ];
18 |
19 | /**
20 | * @param $data
21 | * @param array $headers
22 | * @return mixed
23 | * @throws \Cloudipsp\Exception\ApiException
24 | */
25 | public function get($data, $headers = [])
26 | {
27 | $requestData = $this->prepareParams($data);
28 | $this->validate($requestData, $this->requiredParams);
29 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
30 | }
31 |
32 | /**
33 | * @param $params
34 | * @return mixed
35 | */
36 | protected function prepareParams($params)
37 | {
38 | $prepared_params = $params;
39 |
40 | if (!isset($prepared_params['merchant_id'])) {
41 | $prepared_params['merchant_id'] = $this->mid;
42 | }
43 | return $prepared_params;
44 | }
45 | }
--------------------------------------------------------------------------------
/lib/Api/Order/Capture.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_id' => 'string',
17 | 'amount' => 'integer',
18 | 'currency' => 'string'
19 | ];
20 |
21 | /**
22 | * @param $data
23 | * @param array $headers
24 | * @return mixed
25 | * @throws \Cloudipsp\Exception\ApiException
26 | */
27 | public function get($data, $headers = [])
28 | {
29 | $requestData = $this->prepareParams($data);
30 | $this->validate($requestData, $this->requiredParams);
31 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
32 | }
33 |
34 | /**
35 | * @param $params
36 | * @return mixed
37 | */
38 | protected function prepareParams($params)
39 | {
40 | $prepared_params = $params;
41 |
42 | if (!isset($prepared_params['merchant_id'])) {
43 | $prepared_params['merchant_id'] = $this->mid;
44 | }
45 | return $prepared_params;
46 | }
47 | }
--------------------------------------------------------------------------------
/lib/Api/Order/Reverse.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_id' => 'string',
17 | 'amount' => 'integer',
18 | 'currency' => 'string'
19 | ];
20 |
21 | /**
22 | * @param $data
23 | * @param array $headers
24 | * @return mixed
25 | * @throws \Cloudipsp\Exception\ApiException
26 | */
27 | public function get($data, $headers = [])
28 | {
29 | $requestData = $this->prepareParams($data);
30 | $this->validate($requestData, $this->requiredParams);
31 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
32 | }
33 |
34 | /**
35 | * @param $params
36 | * @return mixed
37 | */
38 | protected function prepareParams($params)
39 | {
40 | $prepared_params = $params;
41 |
42 | if (!isset($prepared_params['merchant_id'])) {
43 | $prepared_params['merchant_id'] = $this->mid;
44 | }
45 | return $prepared_params;
46 | }
47 | }
--------------------------------------------------------------------------------
/lib/Api/Order/Settlements.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'operation_id' => 'string'
17 | ];
18 |
19 | /**
20 | * @param $data
21 | * @param array $headers
22 | * @return mixed
23 | * @throws \Cloudipsp\Exception\ApiException
24 | */
25 | public function get($data, $headers = [])
26 | {
27 | $data['order_type'] = 'settlement';
28 | $requestData = $this->prepareParams($data);
29 | $this->validate($requestData, $this->requiredParams);
30 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/lib/Api/Order/Status.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_id' => 'string'
17 | ];
18 |
19 | /**
20 | * @param $data
21 | * @param array $headers
22 | * @return mixed
23 | * @throws \Cloudipsp\Exception\ApiException
24 | */
25 | public function get($data, $headers = [])
26 | {
27 | $requestData = $this->prepareParams($data);
28 | $this->validate($requestData, $this->requiredParams);
29 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
30 | }
31 |
32 | /**
33 | * @param $params
34 | * @return mixed
35 | */
36 | protected function prepareParams($params)
37 | {
38 | $prepared_params = $params;
39 |
40 | if (!isset($prepared_params['merchant_id'])) {
41 | $prepared_params['merchant_id'] = $this->mid;
42 | }
43 | return $prepared_params;
44 | }
45 | }
--------------------------------------------------------------------------------
/lib/Api/Order/Subscription.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'action' => 'string',
17 | 'order_id' => 'string'
18 | ];
19 |
20 | /**
21 | * @param $data
22 | * @param array $headers
23 | * @return mixed
24 | * @throws \Cloudipsp\Exception\ApiException
25 | */
26 | public function get($data, $headers = [])
27 | {
28 | $requestData = $this->prepareParams($data);
29 | $this->validate($requestData, $this->requiredParams);
30 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/lib/Api/Order/TransactionList.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_id' => 'string'
17 | ];
18 |
19 | /**
20 | * @param $data
21 | * @param array $headers
22 | * @return mixed
23 | * @throws \Cloudipsp\Exception\ApiException
24 | */
25 | public function get($data, $headers = [])
26 | {
27 | $requestData = $this->prepareParams($data);
28 | $this->validate($requestData, $this->requiredParams);
29 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
30 | }
31 |
32 | /**
33 | * @param $params
34 | * @return mixed
35 | */
36 | protected function prepareParams($params)
37 | {
38 | $prepared_params = $params;
39 |
40 | if (!isset($prepared_params['merchant_id'])) {
41 | $prepared_params['merchant_id'] = $this->mid;
42 | }
43 | return $prepared_params;
44 | }
45 | }
--------------------------------------------------------------------------------
/lib/Api/P2pcredit/Credit.php:
--------------------------------------------------------------------------------
1 | 'integer',
17 | 'order_desc' => 'string',
18 | 'amount' => 'integer',
19 | 'currency' => 'string'
20 | ];
21 |
22 | /**
23 | * @param $data
24 | * @param array $headers
25 | * @param array $requiredParams
26 | * @return mixed
27 | * @throws \Cloudipsp\Exception\ApiException
28 | */
29 | public function get($data, $headers = [], $requiredParams = [])
30 | {
31 | if ($requiredParams)
32 | $this->requiredParams = array_merge($requiredParams, $this->requiredParams);
33 | $requestData = $this->prepareParams($data);
34 | $this->validate($requestData, $this->requiredParams);
35 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
36 | }
37 |
38 | /**
39 | * @param $params
40 | * @return mixed
41 | */
42 | protected function prepareParams($params)
43 | {
44 | $prepared_params = $params;
45 |
46 | if (!isset($prepared_params['merchant_id'])) {
47 | $prepared_params['merchant_id'] = $this->mid;
48 | }
49 | if (!isset($prepared_params['order_id'])) {
50 | $prepared_params['order_id'] = Helper\ApiHelper::generateOrderID($this->mid);
51 | }
52 | if (!isset($prepared_params['order_desc'])) {
53 | $prepared_params['order_desc'] = Helper\ApiHelper::generateOrderDesc($prepared_params['order_id']);
54 | }
55 | if (empty($prepared_params['receiver_card_number']) && empty($prepared_params['receiver_rectoken'])) {
56 | throw new \InvalidArgumentException('Request must contain additional parameter receiver_card_number or receiver_rectoken');
57 | }
58 | return $prepared_params;
59 | }
60 |
61 | }
--------------------------------------------------------------------------------
/lib/Api/Payment/Pcidss/StepOne.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_id' => 'string',
17 | 'order_desc' => 'string',
18 | 'currency' => 'string',
19 | 'amount' => 'integer',
20 | 'card_number' => 'ccnumber',
21 | 'cvv2' => 'integer',
22 | 'expiry_date' => 'integer',
23 | 'client_ip' => 'ip'
24 | ];
25 |
26 | /**
27 | * @param $data
28 | * @param array $headers
29 | * @return mixed
30 | * @throws \Cloudipsp\Exception\ApiException
31 | */
32 | public function get($data, $headers = [])
33 | {
34 | $requestData = $this->prepareParams($data);
35 | $this->validate($requestData, $this->requiredParams);
36 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/lib/Api/Payment/Pcidss/StepTwo.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_id' => 'string',
17 | 'pares' => 'string',
18 | 'md' => 'string'
19 | ];
20 |
21 | /**
22 | * @param $data
23 | * @param array $headers
24 | * @return mixed
25 | * @throws \Cloudipsp\Exception\ApiException
26 | */
27 | public function get($data, $headers = [])
28 | {
29 | $requestData = $this->prepareParams($data);
30 | $this->validate($requestData, $this->requiredParams);
31 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
32 | }
33 |
34 | /**
35 | * @param $params
36 | * @return mixed
37 | */
38 | protected function prepareParams($params)
39 | {
40 | if (!isset($params['merchant_id'])) {
41 | $params['merchant_id'] = $this->mid;
42 | }
43 | $returnData = [];
44 | foreach ($params as $key => $value) {
45 | $returnData[strtolower($key)] = trim($value);
46 | }
47 | return $returnData;
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/lib/Api/Payment/Rectoken.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'order_id' => 'string',
17 | 'order_desc' => 'string',
18 | 'currency' => 'string',
19 | 'amount' => 'integer',
20 | 'rectoken' => 'string'
21 | ];
22 |
23 | /**
24 | * @param $data
25 | * @param array $headers
26 | * @return mixed
27 | * @throws \Cloudipsp\Exception\ApiException
28 | */
29 | public function get($data, $headers = [])
30 | {
31 | $requestData = $this->prepareParams($data);
32 | $this->validate($requestData, $this->requiredParams);
33 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
34 | }
35 | }
--------------------------------------------------------------------------------
/lib/Api/Payment/Reports.php:
--------------------------------------------------------------------------------
1 | 'integer',
16 | 'date_from' => 'date',
17 | 'date_to' => 'date',
18 | ];
19 |
20 | /**
21 | * @param $data
22 | * @param array $headers
23 | * @return mixed
24 | * @throws \Cloudipsp\Exception\ApiException
25 | */
26 | public function get($data, $headers = [])
27 | {
28 | $requestData = $this->prepareParams($data);
29 | $this->validate($requestData, $this->requiredParams, $dateFormat = 'd.m.Y H:i:s');
30 | return $this->Request($method = 'POST', $this->url, $headers, $requestData);
31 | }
32 |
33 | /**
34 | * @param $params
35 | * @return mixed
36 | */
37 | protected function prepareParams($params)
38 | {
39 | $prepared_params = $params;
40 |
41 | if (!isset($prepared_params['merchant_id'])) {
42 | $prepared_params['merchant_id'] = $this->mid;
43 | }
44 | return $prepared_params;
45 | }
46 | }
--------------------------------------------------------------------------------
/lib/Checkout.php:
--------------------------------------------------------------------------------
1 | get($data, $headers);
26 | return new Response($result);
27 | }
28 |
29 | /**
30 | * render payment form
31 | * @param $data
32 | * @return string
33 | * @throws Exception\ApiException
34 | */
35 | public static function form($data)
36 | {
37 | $api = new Api\Form();
38 | return $api->get($data);
39 | }
40 |
41 | /**
42 | * generate payment button string
43 | * @param $data
44 | * @return string
45 | * @throws Exception\ApiException
46 | */
47 | public static function button($data)
48 | {
49 | $api = new Api\Button();
50 | return $api->get($data);
51 | }
52 |
53 | /**
54 | * generate payment token
55 | * @param $data
56 | * @param array $headers
57 | * @return Response
58 | * @throws Exception\ApiException
59 | */
60 | public static function token($data, $headers = [])
61 | {
62 | $api = new Api\Token;
63 | $result = $api->get($data, $headers);
64 | return new Response($result);
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/lib/Configuration.php:
--------------------------------------------------------------------------------
1 | httpStatus = $httpStatus;
20 | $this->json = $json;
21 | $this->fondyCode = isset($json["response"]["response_status"]) ? $message = $json["response"]["error_message"] . ".\n" . $message : null;
22 | $this->requestId = isset($json["response"]["request_id"]) ? $message .= ' Request ID: ' . $json["response"]["request_id"] . "\n" : null;
23 | parent::__construct($message);
24 | }
25 |
26 | public function getFondyCode()
27 | {
28 | return $this->fondyCode;
29 | }
30 |
31 | public function getHttpBody()
32 | {
33 | return $this->httpBody;
34 | }
35 |
36 | public function getJsonBody()
37 | {
38 | return $this->json;
39 | }
40 |
41 | public function getRequestId()
42 | {
43 | return $this->requestId;
44 | }
45 | }
--------------------------------------------------------------------------------
/lib/Helper/ApiHelper.php:
--------------------------------------------------------------------------------
1 | $params]));
27 | $signature = sha1($secret_key . self::signatureSeparator . $params);
28 | } else {
29 | $signature = sha1($secret_key . self::signatureSeparator . $params);
30 | }
31 | } else {
32 | $signature = $secret_key . self::signatureSeparator . $params;
33 | }
34 | } else {
35 | $data = array_filter($params,
36 | function ($var) {
37 | return $var !== '' && $var !== null;
38 | });
39 | ksort($data);
40 | $sign_str = $secret_key;
41 | foreach ($data as $k => $v) {
42 | $sign_str .= self::signatureSeparator . $v;
43 | }
44 | if ($encoded) {
45 | $signature = sha1($sign_str);
46 | } else {
47 | $signature = $sign_str;
48 | }
49 | }
50 |
51 | return strtolower($signature);
52 | }
53 |
54 | /**
55 | * @param string $merchant_id
56 | * @return string
57 | */
58 | public static function generateOrderID($merchant_id)
59 | {
60 | return $merchant_id . '_' . md5(uniqid(rand(), 1));
61 | }
62 |
63 | /**
64 | * @param $order_id
65 | * @return string
66 | */
67 | public static function generateOrderDesc($order_id)
68 | {
69 | return sprintf('Order pay #: %s', $order_id);
70 | }
71 |
72 | /**
73 | * @param $data
74 | * @param $url
75 | * @return string
76 | */
77 | public static function generatePaymentForm($data, $url)
78 | {
79 | $form = sprintf("";
88 | return $form;
89 | }
90 |
91 | /**
92 | * @param $data
93 | * @param $url
94 | * @return string
95 | */
96 | public static function generateButtonUrl($data, $url)
97 | {
98 | return $url . '?button=' . urlencode(json_encode($data));
99 | }
100 |
101 | /**
102 | * @param $data
103 | * @param string $wrap
104 | * @return string
105 | */
106 | public static function toXML($data, $wrap = '?xml version="1.0" encoding="UTF-8"?')
107 | {
108 | $xml = '';
109 | if ($wrap != null) {
110 | $xml .= "<$wrap>\n";
111 | }
112 | foreach ($data as $key => $value) {
113 |
114 | if (empty($value))
115 | continue;
116 | if (is_numeric($key))
117 | continue;
118 | $xml .= "<$key>";
119 | if (is_array($value)) {
120 | $child = self::toXML($value, null);
121 | $xml .= $child;
122 | } else {
123 | if (!is_array($value))
124 | $xml .= htmlspecialchars(trim($value)) . "$key>";
125 | }
126 | }
127 | if ($wrap != null) {
128 | $xml .= "\n\n";
129 | }
130 |
131 | return $xml;
132 | }
133 |
134 | /**
135 | * @param $data
136 | * @return string
137 | */
138 | public static function toJSON($data)
139 | {
140 | return json_encode($data);
141 | }
142 |
143 | /**
144 | * @param $data
145 | * @return string
146 | */
147 | public static function toFormData($data)
148 | {
149 | return http_build_query($data, NULL, '&');
150 | }
151 | }
--------------------------------------------------------------------------------
/lib/Helper/RequestHelper.php:
--------------------------------------------------------------------------------
1 | 'application/json',
12 | 'xml' => 'application/xml',
13 | 'form' => 'application/x-www-form-urlencoded'
14 | ];
15 |
16 | /**
17 | * @param $headers
18 | * @param $type
19 | * @return array headers
20 | */
21 | public static function parseHeaders($headers, $type)
22 | {
23 | if (is_array($headers)) {
24 | array_push($headers, 'Content-Type: ' . self::$type[$type]);
25 | } else {
26 | $headers[] = 'Content-Type: ' . self::$type[$type];
27 | }
28 |
29 | return $headers;
30 | }
31 | }
--------------------------------------------------------------------------------
/lib/Helper/ResponseHelper.php:
--------------------------------------------------------------------------------
1 | $xmlTag) {
65 | $result = null;
66 | $attributesData = null;
67 | if (isset($xmlTag['value'])) {
68 | if ($tagPriority) {
69 | $result = $xmlTag['value'];
70 | } else {
71 | $result['value'] = $xmlTag['value'];
72 | }
73 | }
74 | if (isset($xmlTag['attributes']) and $getAttributes) {
75 | foreach ($xmlTag['attributes'] as $attr => $val) {
76 | if ($tagPriority) {
77 | $attributesData[$attr] = $val;
78 | } else {
79 | $result['@attributes'][$attr] = $val;
80 | }
81 | }
82 | }
83 | if ($xmlTag['type'] == 'open') {
84 | $parent[$xmlTag['level'] - 1] = &$current;
85 | if (!is_array($current) or (!in_array($xmlTag['tag'], array_keys($current)))) {
86 | $current[$xmlTag['tag']] = $result;
87 | unset($result);
88 | if ($attributesData) {
89 | $current['@' . $xmlTag['tag']] = $attributesData;
90 | }
91 | $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']] = 1;
92 | $current = &$current[$xmlTag['tag']];
93 | } else {
94 | if (isset($current[$xmlTag['tag']]['0'])) {
95 | $current[$xmlTag['tag']][$repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']]] = $result;
96 | unset($result);
97 | if ($attributesData) {
98 | if (isset($repeatedTagIndex['@' . $xmlTag['tag'] . '_' . $xmlTag['level']])) {
99 | $current[$xmlTag['tag']][$repeatedTagIndex['@' . $xmlTag['tag'] . '_' . $xmlTag['level']]] = $attributesData;
100 | }
101 | }
102 | $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']] += 1;
103 | } else {
104 | $current[$xmlTag['tag']] = [$current[$xmlTag['tag']], $result];
105 | unset($result);
106 | $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']] = 2;
107 | if (isset($current['@' . $xmlTag['tag']])) {
108 | $current[$xmlTag['tag']]['@0'] = $current['@' . $xmlTag['tag']];
109 | unset($current['@' . $xmlTag['tag']]);
110 | }
111 | if ($attributesData) {
112 | $current[$xmlTag['tag']]['@1'] = $attributesData;
113 | }
114 | }
115 | $lastItemIndex = $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']] - 1;
116 | $current = &$current[$xmlTag['tag']][$lastItemIndex];
117 | }
118 | } elseif ($xmlTag['type'] == 'complete') {
119 | if (!isset($current[$xmlTag['tag']]) and empty($current['@' . $xmlTag['tag']])) {
120 | $current[$xmlTag['tag']] = $result;
121 | unset($result);
122 | $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']] = 1;
123 | if ($tagPriority and $attributesData) {
124 | $current['@' . $xmlTag['tag']] = $attributesData;
125 | }
126 | } else {
127 | if (isset($current[$xmlTag['tag']]['0']) and is_array($current[$xmlTag['tag']])) {
128 | $current[$xmlTag['tag']][$repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']]] = $result;
129 | unset($result);
130 | if ($tagPriority and $getAttributes and $attributesData) {
131 | $current[$xmlTag['tag']]['@' . $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']]] = $attributesData;
132 | }
133 | $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']] += 1;
134 | } else {
135 | $current[$xmlTag['tag']] = [
136 | $current[$xmlTag['tag']],
137 | $result,
138 | ];
139 | unset($result);
140 | $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']] = 1;
141 | if ($tagPriority and $getAttributes) {
142 | if (isset($current['@' . $xmlTag['tag']])) {
143 | $current[$xmlTag['tag']]['@0'] = $current['@' . $xmlTag['tag']];
144 | unset($current['@' . $xmlTag['tag']]);
145 | }
146 | if ($attributesData) {
147 | $current[$xmlTag['tag']]['@' . $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']]] = $attributesData;
148 | }
149 | }
150 | $repeatedTagIndex[$xmlTag['tag'] . '_' . $xmlTag['level']] += 1;
151 | }
152 | }
153 | } elseif ($xmlTag['type'] == 'close') {
154 | $current = &$parent[$xmlTag['level'] - 1];
155 | }
156 | unset($xmlValues[$num]);
157 | }
158 | return $xmlArray;
159 | }
160 |
161 | /**
162 | * @param string
163 | * @return array
164 | */
165 | public static function formToArray($data)
166 | {
167 | $response = [];
168 | parse_str($data, $response);
169 | return $response;
170 | }
171 | }
--------------------------------------------------------------------------------
/lib/Helper/ResultHelper.php:
--------------------------------------------------------------------------------
1 | $param) {
21 | if (is_array($param))
22 | self::validateRequiredParams($params[$key], $param);
23 | if (!array_key_exists($key, $params)) {
24 | throw new InvalidArgumentException(sprintf('Required param "%s" is missing', $key));
25 | }
26 | if (array_key_exists($key, $required) && empty($param)) {
27 | throw new InvalidArgumentException(sprintf('Required param "%s" is empty', $key));
28 | }
29 | switch ($param) {
30 | case 'integer':
31 | self::validateInteger($params[$key], $key);
32 | break;
33 | case 'string':
34 | self::validateString($params[$key], $key);
35 | break;
36 | case 'date':
37 | self::validateDate($params[$key], $key, $dateFormat);
38 | break;
39 | case 'ccnumber':
40 | self::validateCCard($params[$key]);
41 | break;
42 | case 'ip':
43 | self::validateIP($params[$key]);
44 | break;
45 | }
46 |
47 | }
48 |
49 | return true;
50 | }
51 |
52 | /**
53 | * Helper method for validating URLs
54 | * @param $url
55 | * @throws InvalidArgumentException
56 | */
57 | public static function validateURL($url)
58 | {
59 | if (filter_var($url, FILTER_VALIDATE_URL) === false) {
60 | throw new InvalidArgumentException(sprintf("%s is not a fully qualified URL", $url));
61 | }
62 | }
63 |
64 | /**
65 | * Helper method for validating date
66 | * @param $date
67 | * @param $key
68 | * @param $format
69 | * @return bool
70 | */
71 | public static function validateDate($date, $key, $format)
72 | {
73 | $d = DateTime::createFromFormat($format, $date);
74 | if ($d && $d->format($format) == $date) {
75 | return true;
76 | } else {
77 | throw new InvalidArgumentException(sprintf('Date %s is incorrect! Accepted format is: %s', $key, $format));
78 | }
79 | }
80 |
81 | /**
82 | * @param $param
83 | * @param string $key
84 | */
85 | public static function validateInteger($param, $key = '')
86 | {
87 | if (trim($param) != null && !is_numeric($param)) {
88 | throw new InvalidArgumentException(sprintf('%s is not a valid numeric', $key));
89 | }
90 | }
91 |
92 | /**
93 | * @param $param
94 | * @param string $key
95 | */
96 | public static function validateString($param, $key = '')
97 | {
98 | if ($key !== 'order_id' && $param != null && !is_string($param)) {
99 | throw new InvalidArgumentException(sprintf('%s is not a valid string', $key));
100 | }
101 | if ($key === 'order_id' && $param == null) {
102 | throw new InvalidArgumentException(sprintf('%s is not a valid string', $key));
103 | }
104 | }
105 |
106 | /**
107 | * Luhn algorithm
108 | * @param $number
109 | * @return bool
110 | */
111 | protected static function validateCCard($number)
112 | {
113 | $checksum = 0;
114 | for ($i = (2 - (strlen($number) % 2)); $i <= strlen($number); $i += 2) {
115 | $checksum += (int)($number[$i - 1]);
116 | }
117 | // Analyze odd digits in even length strings or even digits in odd length strings.
118 | for ($i = (strlen($number) % 2) + 1; $i < strlen($number); $i += 2) {
119 | $digit = (int)($number[$i - 1]) * 2;
120 | if ($digit < 10) {
121 | $checksum += $digit;
122 | } else {
123 | $checksum += ($digit - 9);
124 | }
125 | }
126 | if (($checksum % 10) == 0) {
127 | return true;
128 | } else {
129 | throw new InvalidArgumentException(sprintf('\'%s\' is not a valid credit card number', $number));
130 | }
131 | }
132 |
133 | /**
134 | * @param $ip
135 | * @return bool
136 | */
137 | protected static function validateIP($ip)
138 | {
139 | if (filter_var($ip, FILTER_VALIDATE_IP)) {
140 | return true;
141 | } else {
142 | throw new InvalidArgumentException(sprintf('\'%s\' is not a valid ip', $ip));
143 | }
144 | }
145 | }
--------------------------------------------------------------------------------
/lib/HttpClient/ClientInterface.php:
--------------------------------------------------------------------------------
1 | false,
14 | CURLOPT_HEADER => false,
15 | CURLOPT_RETURNTRANSFER => true,
16 | CURLOPT_CONNECTTIMEOUT => 60,
17 | CURLOPT_USERAGENT => 'php-sdk-v2',
18 | CURLOPT_SSL_VERIFYHOST => 2,
19 | CURLOPT_SSL_VERIFYPEER => 1,
20 | CURLOPT_TIMEOUT => 60
21 | ];
22 |
23 | /**
24 | * @param string $method
25 | * @param string $url
26 | * @param array $headers
27 | * @param array $params
28 | * @return string
29 | * @throws Exception\HttpClientException
30 | */
31 | public function request($method, $url, $headers = [], $params = [])
32 | {
33 | $method = strtoupper($method);
34 | if (!$this->curlEnabled())
35 | throw new Exception\HttpClientException('Curl not enabled.');
36 | if (empty($url))
37 | throw new Exception\HttpClientException('The url is empty.');
38 |
39 | $ch = curl_init($url);
40 | foreach ($this->options as $option => $value) {
41 | curl_setopt($ch, $option, $value);
42 | }
43 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
44 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
45 | if ($params) {
46 | curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
47 | }
48 | $response = curl_exec($ch);
49 | $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
50 | if ($httpStatus != 200)
51 | throw new Exception\HttpClientException(sprintf('Status is: %s', $httpStatus));
52 | curl_close($ch);
53 | return trim($response);
54 | }
55 |
56 | /**
57 | * @return bool
58 | */
59 | private function curlEnabled()
60 | {
61 | return function_exists('curl_init');
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/lib/HttpClient/HttpGuzzle.php:
--------------------------------------------------------------------------------
1 | false,
14 | CURLOPT_HEADER => false,
15 | CURLOPT_RETURNTRANSFER => true,
16 | CURLOPT_CONNECTTIMEOUT => 60,
17 | CURLOPT_USERAGENT => 'php-sdk-v2',
18 | CURLOPT_SSL_VERIFYHOST => 2,
19 | CURLOPT_SSL_VERIFYPEER => 1,
20 | CURLOPT_TIMEOUT => 60
21 | ];
22 |
23 | /**
24 | * @param string $method
25 | * @param string $url
26 | * @param array $headers
27 | * @param array $params
28 | * @return $this
29 | * @throws \Cloudipsp\Exception\HttpClientException
30 | */
31 | public function request($method = 'post', $url = '', $headers = [], $params = [])
32 | {
33 | $method = strtolower($method);
34 | $this->isGuzzleHere();
35 | $client = new \GuzzleHttp\Client();
36 | $guzzleHeaders = [];
37 | foreach ($headers as $header) {
38 | $guzzleHeaders = explode(':', $header);
39 | $guzzleHeaders = [$guzzleHeaders[0] => $guzzleHeaders[1]];
40 | }
41 | $data = [
42 | 'body' => $params,
43 | 'headers' => $guzzleHeaders,
44 | 'config' => [
45 | 'curl' => [
46 | $this->curlOptions,
47 | ]
48 | ]
49 | ];
50 | $request = $client->$method($url, $data);
51 | $response = $request->getBody()->getContents();
52 | return $response;
53 | }
54 |
55 | /**
56 | * @throws \Cloudipsp\Exception\HttpClientException
57 | */
58 | private function isGuzzleHere()
59 | {
60 | if (!class_exists('\GuzzleHttp\Client'))
61 | throw new \Cloudipsp\Exception\HttpClientException('Guzzle not found.');
62 | }
63 | }
--------------------------------------------------------------------------------
/lib/Order.php:
--------------------------------------------------------------------------------
1 | get($data, $headers);
21 | return new OrderResponse($result);
22 | }
23 |
24 | /**
25 | * Generate request to reverse order
26 | * @param $data
27 | * @param array $headers
28 | * @return OrderResponse
29 | * @throws Exception\ApiException
30 | */
31 | public static function reverse($data, $headers = [])
32 | {
33 | $api = new Api\Reverse();
34 | $result = $api->get($data, $headers);
35 | return new OrderResponse($result);
36 | }
37 |
38 | /**
39 | * Generate request to get order info
40 | * @param $data
41 | * @param array $headers
42 | * @return OrderResponse
43 | * @throws Exception\ApiException
44 | */
45 | public static function status($data, $headers = [])
46 | {
47 | $api = new Api\Status();
48 | $result = $api->get($data, $headers);
49 | return new OrderResponse($result);
50 | }
51 |
52 | /**
53 | * Generate request to get transaction list of order
54 | * @param $data
55 | * @param array $headers
56 | * @return OrderResponse
57 | * @throws Exception\ApiException
58 | */
59 | public static function transactionList($data, $headers = [])
60 | {
61 | $api = new Api\TransactionList();
62 | $result = $api->get($data, $headers);
63 | return new OrderResponse($result);
64 | }
65 |
66 | /**
67 | * Generate request to get transaction list of order
68 | * @param $data
69 | * @param array $headers
70 | * @return OrderResponse
71 | * @throws Exception\ApiException
72 | */
73 | public static function atolLogs($data, $headers = [])
74 | {
75 | $api = new Api\Atol();
76 | $result = $api->get($data, $headers);
77 | return new OrderResponse($result);
78 | }
79 | /**
80 | * Generate request to create settlement order
81 | * @param $data
82 | * @param array $headers
83 | * @return Response\Response
84 | * @throws Exception\ApiException
85 | */
86 | public static function settlement($data, $headers = [])
87 | {
88 | $api = new Api\Settlements();
89 | $result = $api->get($data, $headers);
90 | return new Response\Response($result);
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/lib/P2pcredit.php:
--------------------------------------------------------------------------------
1 | get($data, $headers);
23 | return new Response($result, 'credit');
24 | }
25 | }
--------------------------------------------------------------------------------
/lib/Payment.php:
--------------------------------------------------------------------------------
1 | get($data, $headers);
21 | return new Response($result);
22 | }
23 |
24 | /**
25 | * Generate request to get payments reports
26 | * @param $data
27 | * @param array $headers
28 | * @return Response
29 | * @throws Exception\ApiException
30 | */
31 | public static function reports($data, $headers = [])
32 | {
33 | $api = new Api\Reports();
34 | $result = $api->get($data, $headers);
35 | return new Response($result);
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/lib/Pcidss.php:
--------------------------------------------------------------------------------
1 | get($data, $headers);
23 | return new PcidssResponse($result);
24 | }
25 |
26 | /**
27 | * generate payment 3ds step 2
28 | * @param $data
29 | * @param array $headers
30 | * @return PcidssResponse
31 | * @throws Exception\ApiException
32 | */
33 | public static function submit($data, $headers = [])
34 | {
35 | $api = new Api\Payment\Pcidss\StepTwo();
36 | $result = $api->get($data, $headers);
37 | return new PcidssResponse($result);
38 | }
39 |
40 | /**
41 | * generate form 3ds step 2
42 | * @param $data
43 | * @param string $response_url
44 | * @return string
45 | * @throws ApiException
46 | */
47 | public static function get3dsFrom($data, $response_url = '')
48 | {
49 | if (!$data['acs_url']) {
50 | throw new ApiException('Required param acs_url is missing or empty.');
51 | }
52 | Helper\ValidationHelper::validateURL($data['acs_url']);
53 | foreach ($data as $key => $value) {
54 | $data[strtolower($key)] = $value;
55 | }
56 | $formData = [
57 | 'PaReq' => $data['pareq'],
58 | 'MD' => $data['md'],
59 | 'TermUrl' => $response_url ? $response_url : $data['termurl']
60 | ];
61 | $form3ds = Helper\ApiHelper::generatePaymentForm($formData, $data['acs_url']);
62 | return $form3ds;
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/lib/Response/OrderResponse.php:
--------------------------------------------------------------------------------
1 | apiVersion === '2.0') {
16 | if (isset($this->response['response']['data'])) {
17 | return ResponseHelper::getBase64Data($this->response);
18 | } else {
19 | return $this->response['response'];
20 | }
21 | } else {
22 | return $this->response['response'];
23 | }
24 | }
25 |
26 | /**
27 | * @return bool
28 | */
29 | public function isReversed()
30 | {
31 | $data = $this->buildVerifyData();
32 | if (!isset($data['reverse_status']))
33 | return false;
34 | $valid = $this->isValid($data);
35 | if ($valid && $data['reverse_status'] === 'approved')
36 | return true;
37 |
38 | return false;
39 | }
40 |
41 | /**
42 | * @param bool $direct if synchronous call
43 | * @return bool
44 | */
45 | public function isCaptured($direct = false)
46 | {
47 | $data = $this->buildVerifyData();
48 | if (!isset($data['capture_status']))
49 | return false;
50 | $valid = $direct ? $direct : $this->isValid($data);
51 | if ($valid && $data['capture_status'] === 'captured')
52 | return true;
53 |
54 | return false;
55 | }
56 |
57 | /**
58 | * Checking if Captured transaction
59 | * @return bool
60 | * @throws \Exception
61 | */
62 | public function isCapturedByList()
63 | {
64 | $data = $this->getCapturedTransAction();
65 |
66 | if (!array_key_exists('capture_status', $data)) throw new \Exception('invalid response');
67 | return $data['capture_status'] != 'captured' ? false : true;
68 | }
69 |
70 | /**
71 | * @return mixed
72 | * @throws ApiException
73 | */
74 | private function getCapturedTransAction()
75 | {
76 | foreach ($this->getData() as $data) {
77 | if (($data['tran_type'] == 'purchase' || $data['tran_type'] == 'verification')
78 | && $data['preauth'] == 'Y'
79 | && $data['transaction_status'] == 'approved'
80 | ) {
81 | return $data;
82 | } else {
83 | throw new ApiException('Nothing to capture');
84 | }
85 | }
86 | return false;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/lib/Response/PcidssResponse.php:
--------------------------------------------------------------------------------
1 | response['response'])) {
15 | return true;
16 | } else {
17 | return false;
18 | }
19 | }
20 |
21 | /**
22 | * @param string $response_url
23 | * @return mixed
24 | * @throws \Cloudipsp\Exception\ApiException
25 | */
26 | public function get3dsFormContent($response_url = '')
27 | {
28 | trigger_error('Deprecated: this function is deprecated use get3dsForm instead!', E_NOTICE);
29 | $data = $this->getData();
30 | return Pcidss::get3dsFrom($data, $response_url);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/lib/Response/Response.php:
--------------------------------------------------------------------------------
1 | orderID = $data['order_id'];
43 | $data = $data['response'];
44 | $this->requestType = Configuration::getRequestType();
45 | $this->apiVersion = Configuration::getApiVersion();
46 | $this->setKeyByOperationType($type);
47 | switch ($this->requestType) {
48 | case 'xml':
49 | $response = ResponseHelper::xmlToArray($data);
50 | break;
51 | case 'form':
52 | $response['response'] = ResponseHelper::formToArray($data);
53 | break;
54 | case 'json':
55 | $response = ResponseHelper::jsonToArray($data);
56 | break;
57 | default:
58 | $response = null;
59 | }
60 |
61 | $this->checkResponse($response);
62 |
63 | $this->response = $response;
64 |
65 | }
66 |
67 | /**
68 | * Check response on errors
69 | * @param $response
70 | * @return mixed
71 | * @throws ApiException
72 | */
73 | private function checkResponse($response)
74 | {
75 | if (isset($response['response']['response_status']) && $response['response']['response_status'] == 'failure')
76 | throw new ApiException('Request is incorrect.', 200, $response);
77 | if (isset($response['response']['error_code']))
78 | throw new ApiException('Request is incorrect.', 200, $response);
79 | return $response;
80 | }
81 |
82 | /**
83 | * Redirect to checkout
84 | */
85 | public function toCheckout()
86 | {
87 | $url = $this->getData()['checkout_url'];
88 | if (isset($url)) {
89 | header(sprintf('location: %s', $url));
90 | exit;
91 | }
92 | }
93 |
94 | /**
95 | * Getting checkout_url from response
96 | * @return bool|string
97 | */
98 | public function getUrl()
99 | {
100 | if (isset($this->response['response']['checkout_url'])) {
101 | return $this->response['response']['checkout_url'];
102 | }
103 | if (isset($this->getData()['checkout_url'])) {
104 | return $this->getData()['checkout_url'];
105 | } else {
106 | return false;
107 | }
108 | }
109 |
110 | /**
111 | * @return mixed
112 | */
113 | public function getData()
114 | {
115 | if ($this->apiVersion === '2.0') {
116 | return ResponseHelper::getBase64Data($this->response);
117 | } else {
118 | return $this->response['response'];
119 | }
120 | }
121 |
122 | /**
123 | * @return array|mixed
124 | */
125 | protected function buildVerifyData()
126 | {
127 | if ($this->apiVersion === '2.0') {
128 | $data = ResponseHelper::getBase64Data($this->response);
129 | $data['encodedData'] = $this->response['response']['data'];
130 | $data['signature'] = $this->response['response']['signature'];
131 | } else {
132 | $data = $this->getData();
133 | }
134 | return $data;
135 | }
136 |
137 | /**
138 | * Get order id
139 | * @return mixed
140 | */
141 | public function getOrderID()
142 | {
143 | return $this->orderID ? $this->orderID : false;
144 | }
145 |
146 | /**
147 | * Checking if order is approved
148 | * @return bool
149 | */
150 | public function isApproved()
151 | {
152 | $data = $this->buildVerifyData();
153 | return ResultHelper::isPaymentApproved($data, $this->paymentKey, $this->apiVersion);
154 | }
155 |
156 | /**
157 | * Checking if order signature is valid
158 | * @param null $data
159 | * @return bool
160 | */
161 | public function isValid($data = null)
162 | {
163 | if ($data == null)
164 | $data = $this->buildVerifyData();
165 | return ResultHelper::isPaymentValid($data, $this->paymentKey, $this->apiVersion);
166 | }
167 |
168 | /**
169 | * setting secret key by operation type
170 | * @param $type
171 | */
172 | protected function setKeyByOperationType($type = '')
173 | {
174 | if ($type === 'credit') {
175 | $this->paymentKey = Configuration::getCreditKey();
176 | } else {
177 | $this->paymentKey = Configuration::getSecretKey();
178 | }
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/lib/Result/Result.php:
--------------------------------------------------------------------------------
1 | apiVersion = Configuration::getApiVersion();
38 | if (!$type) {
39 | $this->requestType = Configuration::getRequestType();
40 | } else {
41 | $this->requestType = $type;
42 | }
43 | if (!$data) {
44 | $this->result = $this->parseResult();
45 | } else {
46 | $this->result = $data;
47 | }
48 | if (!$key) {
49 | $this->secretKey = Configuration::getSecretKey();
50 | } else {
51 | $this->secretKey = $key;
52 | }
53 | if ($formatted)
54 | $this->result = $this->formatResult($this->result);
55 | }
56 |
57 | /**
58 | * @return array|string
59 | */
60 | private function parseResult()
61 | {
62 | $result = $_POST;
63 | if (empty($result))
64 | $result = file_get_contents('php://input');
65 | return $result;
66 |
67 | }
68 |
69 | /**
70 | * @param $result
71 | * @return array|string
72 | */
73 | private function formatResult($result)
74 | {
75 | if ($this->apiVersion === '1.0' && is_string($result)) {
76 | switch ($this->requestType) {
77 | case 'xml':
78 | $result = ResponseHelper::xmlToArray($result, true, true, 'UTF-8');
79 | break;
80 | case 'json':
81 | $result = ResponseHelper::jsonToArray($result);
82 | break;
83 | }
84 | } else if ($this->apiVersion === '2.0' and is_string($result)) {
85 | $result = ResponseHelper::jsonToArray($result);
86 | }
87 | return $result;
88 | }
89 |
90 | /**
91 | * Get formatted data
92 | * @return array
93 | */
94 | public function getData()
95 | {
96 | if(!$this->result or $this->result == '')
97 | return [];
98 |
99 | if(isset($this->result['response']))
100 | $this->result = $this->result['response'];
101 |
102 | if ($this->apiVersion === '2.0') {
103 | if(!isset($this->result['data']))
104 | return [];
105 | $result = ResponseHelper::getBase64Data(['response' => $this->result]);
106 | $result['encodedData'] = $this->result['data'];
107 | $result['signature'] = $this->result['signature'];
108 | return $result;
109 | } else {
110 | return $this->result;
111 | }
112 | }
113 |
114 | /**
115 | * @return bool
116 | */
117 | public function isApproved()
118 | {
119 | $data = $this->getData();
120 | return ResultHelper::isPaymentApproved($data, $this->secretKey, $this->apiVersion);
121 | }
122 |
123 | /**
124 | * @return bool
125 | */
126 | public function getToken()
127 | {
128 | $data = $this->getData();
129 | return $data['rectoken'] ? $data['rectoken'] : false;
130 | }
131 |
132 | /**
133 | * @param $param
134 | * @return bool
135 | */
136 | public function getParam($param)
137 | {
138 | $data = $this->getData();
139 | return $data[$param] ? $data[$param] : false;
140 | }
141 |
142 | /**
143 | * @param null $data
144 | * @return bool
145 | */
146 | public function isValid($data = null)
147 | {
148 | if ($data == null)
149 | $data = $this->getData();
150 | return ResultHelper::isPaymentValid($data, $this->secretKey, $this->apiVersion);
151 | }
152 |
153 | /**
154 | * @return bool
155 | */
156 | public function isProcessing()
157 | {
158 | $data = $this->getData();
159 | if (!isset($data['order_status']))
160 | return false;
161 | $valid = $this->isValid($data);
162 | if ($valid && $data['order_status'] === 'processing')
163 | return true;
164 |
165 | return false;
166 | }
167 |
168 | /**
169 | * @return bool
170 | */
171 | public function isDeclined()
172 | {
173 | $data = $this->getData();
174 | if (!isset($data['order_status']))
175 | return false;
176 | $valid = $this->isValid($data);
177 | if ($valid && $data['order_status'] === 'declined')
178 | return true;
179 |
180 | return false;
181 | }
182 |
183 | /**
184 | * @return bool
185 | */
186 | public function isExpired()
187 | {
188 | $data = $this->getData();
189 | if (!isset($data['order_status']))
190 | return false;
191 | $valid = $this->isValid($data);
192 | if ($valid && $data['order_status'] === 'expired')
193 | return true;
194 |
195 | return false;
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/lib/Subscription.php:
--------------------------------------------------------------------------------
1 | [
19 | 'start_time' => 'date',
20 | 'amount' => 'integer',
21 | 'every' => 'integer',
22 | 'period' => 'string'
23 | ]
24 | ];
25 | private static $defaultParams = [
26 | 'subscription' => 'Y'
27 | ];
28 |
29 | /**
30 | * return checkout url with calendar
31 | * @param $data
32 | * @param array $headers
33 | * @return Response
34 | * @throws Exception\ApiException
35 | */
36 | public static function url($data, $headers = [])
37 | {
38 | if (\Cloudipsp\Configuration::getApiVersion() !== self::$requiredApiVersion) {
39 | trigger_error('Reccuring_data allowed only for api version \'2.0\'', E_USER_NOTICE);
40 | \Cloudipsp\Configuration::setApiVersion(self::$requiredApiVersion);
41 | }
42 | $data = array_merge($data, self::$defaultParams);
43 | $api = new Api\Url();
44 | $result = $api->get($data, $headers, self::$requiredParams);
45 | return new Response($result);
46 | }
47 |
48 | /**
49 | * stop calendar recurring payments
50 | * @param $order_id
51 | * @param array $headers
52 | * @return Response
53 | * @throws Exception\ApiException
54 | */
55 | public static function stop($order_id, $headers = [])
56 | {
57 | if (\Cloudipsp\Configuration::getApiVersion() !== self::$requiredApiVersion) {
58 | trigger_error('Reccuring_data allowed only for api version \'2.0\'', E_USER_NOTICE);
59 | \Cloudipsp\Configuration::setApiVersion(self::$requiredApiVersion);
60 | }
61 | $api = new ApiRecurring\Subscription();
62 | $data = [
63 | "order_id" => $order_id,
64 | "action" => "stop"
65 | ];
66 | $result = $api->get($data, $headers);
67 | return new Response($result);
68 | }
69 |
70 | /**
71 | * return checkout token with calendar
72 | * @param $data
73 | * @param array $headers
74 | * @return Response
75 | * @throws Exception\ApiException
76 | */
77 | public static function token($data, $headers = [])
78 | {
79 | if (\Cloudipsp\Configuration::getApiVersion() !== self::$requiredApiVersion) {
80 | trigger_error('Reccuring_data allowed only for api version \'2.0\'', E_USER_NOTICE);
81 | \Cloudipsp\Configuration::setApiVersion(self::$requiredApiVersion);
82 | }
83 | $data = array_merge($data, self::$defaultParams);
84 | $api = new Api\Token;
85 | $result = $api->get($data, $headers, self::$requiredParams);
86 | return new Response($result);
87 | }
88 |
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/lib/Verification.php:
--------------------------------------------------------------------------------
1 | 'Y',
17 | 'verification_type' => 'amount'
18 | ];
19 |
20 | /**
21 | * return checkout url with card verify
22 | * @param $data
23 | * @param array $headers
24 | * @return Response
25 | * @throws Exception\ApiException
26 | */
27 | public static function url($data, $headers = [])
28 | {
29 | $data = array_merge($data, self::$defaultParams);
30 | $api = new Api\Verification();
31 | $result = $api->get($data, $headers);
32 | return new Response($result);
33 | }
34 |
35 | /**
36 | * return checkout form with card verify
37 | * @param $data
38 | * @return string
39 | * @throws Exception\ApiException
40 | */
41 | public static function form($data)
42 | {
43 | $api = new Api\Form();
44 | return $api->get($data);
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/result.php:
--------------------------------------------------------------------------------
1 | getData());
12 | var_dump($result->isValid());
13 | var_dump($result->isApproved());
14 |
--------------------------------------------------------------------------------
/tests/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cloudipsp/php-sdk-v2/20699e5966d7b06095b7b3ca278316d86eba5859/tests/.gitkeep
--------------------------------------------------------------------------------
/tests/CheckoutTest.php:
--------------------------------------------------------------------------------
1 | 'tests SDK',
14 | 'currency' => 'USD',
15 | 'amount' => 21321312,
16 | 'default_payment_system' => 'card',
17 | 'response_url' => 'http://site.com/responseurl',
18 | 'server_callback_url' => 'http://site.com/callbackurl',
19 | 'payment_systems' => 'qiwi,yandex,webmoney,card,p24',
20 | 'preauth' => 'N',
21 | 'sender_email' => 'tests@fondy.eu',
22 | 'delayed' => 'Y',
23 | 'lang' => 'ru',
24 | 'product_id' => 'some_product_id',
25 | 'required_rectoken' => 'N',
26 | 'lifetime' => 36000,
27 | 'verification' => 'N',
28 | 'subscription' => 'N',
29 | 'merchant_data' => array(
30 | 'custom_field1' => 1111,
31 | 'custom_field2' => '2222',
32 | 'custom_field3' => '3!@#$%^&(()_+?"}',
33 | 'custom_field4' => ['custom_field4_test', 'custom_field4_test2', 'custom_field4_test3' => ['custom_field4_test3_33' => 'hello world!']]
34 | )
35 | ];
36 |
37 | /**
38 | * Setup config
39 | */
40 | private function setTestConfig()
41 | {
42 | Configuration::setMerchantId($this->mid);
43 | Configuration::setSecretKey($this->secret_key);
44 | Configuration::setApiVersion('1.0');
45 | }
46 |
47 | /**
48 | * @throws Exception\ApiException
49 | */
50 | public function testUrl()
51 | {
52 | $this->setTestConfig();
53 | foreach ($this->request_types as $type) {
54 | Configuration::setRequestType($type);
55 | $result = Checkout::url($this->fullTestData)->getData();
56 | $this->validateCheckoutUrlResult($result);
57 | }
58 | }
59 |
60 | /**
61 | * @throws Exception\ApiException
62 | */
63 | public function testToken()
64 | {
65 | $this->setTestConfig();
66 | Configuration::setRequestType('json');
67 | $result = Checkout::token($this->fullTestData)->getData();
68 | $this->validateTokenResult($result);
69 | }
70 |
71 | /**
72 | * @throws Exception\ApiException
73 | */
74 | public function testForm()
75 | {
76 | $this->setTestConfig();
77 | $result = Checkout::form($this->fullTestData);
78 | $this->assertIsMyString($result, "Got a " . gettype($result) . " instead of a string");
79 | }
80 |
81 | /**
82 | * Checking correct result for token request
83 | * @param $result
84 | */
85 | private function validateTokenResult($result)
86 | {
87 | $this->assertNotEmpty($result['token'], 'payment_id is empty');
88 | $this->assertIsMyString($result['token'], "Got a " . gettype($result['token']) . " instead of a string");
89 | }
90 |
91 | /**
92 | * @param $string
93 | * @param $message
94 | */
95 | private function assertIsMyString($string, $message)
96 | {
97 | if (method_exists(get_parent_class($this), 'assertIsString')) {
98 | $this->assertIsString($string, $message);
99 | } else {
100 | $this->assertInternalType('string', $string, $message);
101 | }
102 | }
103 |
104 | /**
105 | * Checking correct result of get checkout url
106 | * @param $result
107 | */
108 | private function validateCheckoutUrlResult($result)
109 | {
110 | $this->assertNotEmpty($result['checkout_url'], 'checkout_url is empty');
111 | $this->assertNotEmpty($result['payment_id'], 'payment_id is empty');
112 | $this->assertEquals($result['response_status'], 'success');
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/tests/ConfigurationTest.php:
--------------------------------------------------------------------------------
1 | assertEquals('https://api.fondy.eu/api', Configuration::getApiUrl());
12 | Configuration::setApiUrl('api.saas.com');
13 | $this->assertEquals(
14 | 'https://api.saas.com/api',
15 | Configuration::getApiUrl()
16 | );
17 | Configuration::setApiUrl('api.fondy.eu');
18 | $this->assertEquals(
19 | 'https://api.fondy.eu/api',
20 | Configuration::getApiUrl()
21 | );
22 | }
23 |
24 | public function testSetApiVersion()
25 | {
26 | $this->assertEquals(
27 | '1.0',
28 | Configuration::getApiVersion()
29 | );
30 | Configuration::setApiVersion('2.0');
31 | $this->assertEquals(
32 | '2.0',
33 | Configuration::getApiVersion()
34 | );
35 | }
36 |
37 | public function testSetHttpClient()
38 | {
39 | Configuration::setHttpClient('HttpGuzzle');
40 | $this->assertInstanceOf('\\Cloudipsp\\HttpClient\\HttpGuzzle', Configuration::getHttpClient());
41 | Configuration::setHttpClient('HttpCurl');
42 | $this->assertInstanceOf('\\Cloudipsp\\HttpClient\\HttpCurl', Configuration::getHttpClient());
43 | if (method_exists(get_parent_class($this), 'expectNotice')){
44 | $this->expectNotice();
45 | } else {
46 | $this->expectException('PHPUnit_Framework_Error_Notice');
47 | }
48 | $this->assertFalse(Configuration::setHttpClient('Unknown'));
49 | }
50 |
51 | public function testSetHttpClientClass()
52 | {
53 | Configuration::setHttpClient(new HttpClient\HttpCurl());
54 | $this->assertInstanceOf('\\Cloudipsp\\HttpClient\\HttpCurl', Configuration::getHttpClient());
55 | }
56 |
57 | public function testSetSecretKey()
58 | {
59 | Configuration::setSecretKey('something-secret');
60 | $this->assertEquals('something-secret', Configuration::getSecretKey());
61 | }
62 |
63 |
64 | public function testSetMerchantId()
65 | {
66 | Configuration::setMerchantId(123);
67 | $this->assertEquals(123, Configuration::getMerchantId());
68 | }
69 |
70 | public function testSetCreditKey()
71 | {
72 | Configuration::setCreditKey('something-secret');
73 | $this->assertEquals('something-secret', Configuration::getCreditKey());
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/tests/OrderTest.php:
--------------------------------------------------------------------------------
1 | '4444555511116666',
19 | 'cvv2' => '333',
20 | 'expiry_date' => '1222'
21 | ];
22 | private $TestPcidssData = [
23 | 'currency' => 'USD',
24 | 'preauth' => 'Y',
25 | 'amount' => 1000,
26 | 'client_ip' => '127.2.2.1'
27 | ];
28 | private $orderID = null;
29 |
30 | public function __construct($name = null, array $data = array(), $dataName = '')
31 | {
32 | $this->setTestConfig();
33 | $TestData = array_merge($this->TestPcidssData, $this->TestCardnon3ds);
34 | $this->orderID['order_id'] = $this->createOrder($TestData);
35 | parent::__construct($name, $data, $dataName);
36 | }
37 |
38 | private function setTestConfig()
39 | {
40 | Configuration::setMerchantId($this->mid);
41 | Configuration::setSecretKey($this->secret_key);
42 | Configuration::setApiVersion('1.0');
43 | }
44 |
45 | /**
46 | * @throws Exception\ApiException
47 | */
48 | public function testStatus()
49 | {
50 | $this->setTestConfig();
51 | $data = Order::status($this->orderID);
52 | $result = $data->getData();
53 | $this->assertNotEmpty($result['order_id'], 'order_id is empty');
54 | $this->assertNotEmpty($result['order_status'], 'order_status is empty');
55 | $this->assertEquals($result['response_status'], 'success');
56 | $this->assertEquals( true, $data->isApproved());
57 | $this->assertEquals( true, $data->isValid());
58 |
59 | }
60 |
61 | /**
62 | * @throws Exception\ApiException
63 | */
64 | public function testCapture()
65 | {
66 | $this->setTestConfig();
67 | $captureData = [
68 | 'currency' => 'USD',
69 | 'amount' => 1000,
70 | 'order_id' => $this->orderID['order_id']
71 | ];
72 | $data = Order::capture($captureData);
73 | $result = $data->getData();
74 | $this->assertIsMyArray($result);
75 | $this->assertEquals($result['capture_status'], 'captured');
76 | $this->assertEquals(true, $data->isCaptured(true));
77 | }
78 |
79 | /**
80 | * @throws Exception\ApiException
81 | */
82 | public function testReverse()
83 | {
84 | $this->setTestConfig();
85 | $reverseData = [
86 | 'currency' => 'USD',
87 | 'amount' => 1000,
88 | 'order_id' => $this->orderID['order_id']
89 | ];
90 | $data = Order::reverse($reverseData);
91 | $result = $data->getData();
92 | $this->assertNotEmpty($result['order_id'], 'order_id is empty');
93 | $this->assertEquals($result['response_status'], 'success');
94 | $this->assertEquals($result['reverse_status'], 'approved');
95 | $this->assertEquals(true, $data->isReversed());
96 | }
97 |
98 | /**
99 | * @throws Exception\ApiException
100 | */
101 | public function testTransactionList()
102 | {
103 | $this->setTestConfig();
104 | $data = Order::transactionList($this->orderID);
105 | $result = $data->getData();
106 | $this->assertIsMyArray($result);
107 | $this->assertEquals('approved', $result[0]['transaction_status']);
108 |
109 | }
110 |
111 | /**
112 | * @param $array
113 | * @param $message
114 | */
115 | private function assertIsMyArray($array, $message = '')
116 | {
117 | if (method_exists(get_parent_class($this), 'assertIsArray')) {
118 | $this->assertIsArray($array, $message);
119 | } else {
120 | $this->assertInternalType('array', $array, $message);
121 | }
122 | }
123 |
124 | /**
125 | * @param $data
126 | * @return mixed
127 | * @throws Exception\ApiException
128 | */
129 | private function createOrder($data)
130 | {
131 | $data = Pcidss::start($data);
132 | return $data->getData()['order_id'];
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/tests/P2pcreditTest.php:
--------------------------------------------------------------------------------
1 | 'USD',
14 | 'amount' => 111,
15 | 'receiver_card_number' => '4444555511116666'
16 | ];
17 |
18 | private function setTestConfig()
19 | {
20 | Configuration::setMerchantId($this->mid);
21 | Configuration::setSecretKey('');
22 | Configuration::setCreditKey($this->CreditKey);
23 | Configuration::setApiVersion('1.0');
24 | }
25 |
26 | /**
27 | * @throws Exception\ApiException
28 | */
29 | public function testCredit()
30 | {
31 | $this->setTestConfig();
32 | foreach ($this->request_types as $type) {
33 | Configuration::setRequestType($type);
34 | $result = P2pcredit::start($this->TestData);
35 | $this->validateResult($result->getData());
36 | $this->isValid($result->isValid());
37 | }
38 | }
39 |
40 | private function validateResult($result)
41 | {
42 | $this->assertNotEmpty($result['order_id'], 'order_id is empty');
43 | $this->assertNotEmpty($result['payment_id'], 'payment_id is empty');
44 | $this->assertEquals($result['response_status'], 'success');
45 | }
46 |
47 | private function isValid($result)
48 | {
49 | $this->assertEquals($result, true);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/PaymentTest.php:
--------------------------------------------------------------------------------
1 | 'USD',
20 | 'amount' => 111,
21 | 'rectoken' => ''
22 | ];
23 | private $TestCardnon3ds = [
24 | 'card_number' => '4444555511116666',
25 | 'cvv2' => '333',
26 | 'expiry_date' => '1222',
27 | 'required_rectoken' => 'Y'
28 | ];
29 | private $TestPcidssData = [
30 | 'currency' => 'USD',
31 | 'amount' => 1,
32 | 'client_ip' => '127.2.2.1'
33 | ];
34 |
35 | /**
36 | * PaymentTest constructor.
37 | * @param null $name
38 | * @param array $data
39 | * @param string $dataName
40 | * @throws Exception\ApiException
41 | */
42 | public function __construct($name = null, array $data = array(), $dataName = '')
43 | {
44 | $this->setTestConfig();
45 | $this->TestData['rectoken'] = $this->getToken(array_merge($this->TestPcidssData, $this->TestCardnon3ds));
46 | parent::__construct($name, $data, $dataName);
47 | }
48 |
49 | /**
50 | * Setting test config
51 | */
52 | private function setTestConfig()
53 | {
54 | Configuration::setMerchantId($this->mid);
55 | Configuration::setSecretKey($this->Secret);
56 |
57 | }
58 |
59 | /**
60 | * @throws Exception\ApiException
61 | */
62 | public function testRecurring()
63 | {
64 | $this->setTestConfig();
65 | Configuration::setApiVersion('1.0');
66 | foreach ($this->request_types as $type) {
67 | Configuration::setRequestType($type);
68 | $result = Payment::recurring($this->TestData);
69 | $this->assertEquals($result->isApproved(), true);
70 | $this->assertEquals($result->isValid(), true);
71 | $this->assertEquals($result->getData()['response_status'], 'success');
72 | }
73 | }
74 |
75 | /**
76 | * @throws Exception\ApiException
77 | */
78 | public function testRecurringv2()
79 | {
80 | $this->setTestConfig();
81 | Configuration::setApiVersion('2.0');
82 | Configuration::setRequestType('json');
83 | $result = Payment::recurring($this->TestData);
84 | $this->assertEquals($result->isApproved(), true);
85 | $this->assertEquals($result->isValid(), true);
86 | $this->assertEquals($result->getData()['response_status'], 'success');
87 |
88 | }
89 |
90 | /**
91 | * @throws Exception\ApiException
92 | */
93 | public function testReports()
94 | {
95 | $this->setTestConfig();
96 | $data = [
97 | "date_from" => date('d.m.Y H:i:s', time() - 7200),
98 | "date_to" => date('d.m.Y H:i:s', time() - 3600),
99 | ];
100 | $reports = Payment::reports($data);
101 | $this->assertEquals($reports->getData()[0]['response_status'], 'success');
102 |
103 | }
104 |
105 | /**
106 | * @param $data
107 | * @return mixed
108 | * @throws Exception\ApiException
109 | */
110 | private function getToken($data)
111 | {
112 | $data = Pcidss::start($data);
113 | return $data->getData()['rectoken'];
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/tests/PcidssTest.php:
--------------------------------------------------------------------------------
1 | '4444555566661111',
14 | 'cvv2' => '444',
15 | 'expiry_date' => '1221'
16 | ];
17 | private $TestCardnon3ds = [
18 | 'card_number' => '4444555511116666',
19 | 'cvv2' => '333',
20 | 'expiry_date' => '1222'
21 | ];
22 | private $TestPcidssData = [
23 | 'currency' => 'USD',
24 | 'amount' => 1000,
25 | 'client_ip' => '127.2.2.1'
26 | ];
27 |
28 | private function setTestConfig()
29 | {
30 | Configuration::setMerchantId($this->mid);
31 | Configuration::setSecretKey($this->secret_key);
32 | Configuration::setApiVersion('1.0');
33 | }
34 |
35 | /**
36 | * @throws Exception\ApiException
37 | */
38 | public function testStartNon3ds()
39 | {
40 | $this->setTestConfig();
41 | $data = array_merge($this->TestPcidssData, $this->TestCardnon3ds);
42 | foreach ($this->request_types as $type) {
43 | Configuration::setRequestType($type);
44 | $result = Pcidss::start($data)->getData();
45 |
46 | $this->validateNon3dResult($result);
47 | }
48 | }
49 |
50 | /**
51 | * @throws Exception\ApiException
52 | */
53 | public function testgetFrom()
54 | {
55 | $data = [
56 | 'acs_url' => 'http://some-url.com',
57 | 'pareq' => 'pareq',
58 | 'md' => 'pareq',
59 | 'TermUrl' => 'http://some-url.com'
60 | ];
61 | $form = Pcidss::get3dsFrom($data, 'some_url');
62 | $this->assertTrue(is_string($form), "Got a " . gettype($form) . " instead of a string");
63 | }
64 |
65 | /**
66 | * @throws Exception\ApiException
67 | */
68 | public function testStart3ds()
69 | {
70 | $this->setTestConfig();
71 | $data = array_merge($this->TestPcidssData, $this->TestCard3ds);
72 | foreach ($this->request_types as $type) {
73 | Configuration::setRequestType($type);
74 | $result = Pcidss::start($data)->getData();
75 | $this->validate3dResult($result);
76 | }
77 | }
78 |
79 | private function validate3dResult($result)
80 | {
81 | $this->assertNotEmpty($result['acs_url'], 'asc_url is empty');
82 | $this->assertEquals($result['response_status'], 'success');
83 | }
84 |
85 | private function validateNon3dResult($result)
86 | {
87 | $this->assertNotEmpty($result['order_id'], 'order_id is empty');
88 | $this->assertNotEmpty($result['order_status'], 'order_status is empty');
89 | $this->assertEquals($result['response_status'], 'success');
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/tests/SubscriptionTest.php:
--------------------------------------------------------------------------------
1 | 'USD',
13 | 'amount' => 10000,
14 | 'recurring_data' => [
15 | 'start_time' => '2021-12-24',
16 | 'amount' => 1000,
17 | 'every' => 30,
18 | 'period' => 'day',
19 | 'state' => 'y',
20 | 'readonly' => 'y'
21 | ]
22 | ];
23 |
24 | private function setTestConfig()
25 | {
26 | Configuration::setMerchantId($this->mid);
27 | Configuration::setSecretKey($this->secret_key);
28 | Configuration::setRequestType('json');
29 | Configuration::setApiVersion('2.0');
30 | }
31 |
32 | /**
33 | * @throws Exception\ApiException
34 | */
35 | public function testSubscriptionToken()
36 | {
37 | $this->setTestConfig();
38 | $result = Subscription::token($this->TestSubscriptionData)->getData();
39 | $this->assertNotEmpty($result['token'], 'payment_id is empty');
40 | }
41 |
42 | /**
43 | * @throws Exception\ApiException
44 | */
45 | public function testSubscriptionUrl()
46 | {
47 | $this->setTestConfig();
48 | $result = Subscription::url($this->TestSubscriptionData)->getData();
49 | $this->validate($result);
50 |
51 | }
52 |
53 | /**
54 | * @param $result
55 | */
56 | private function validate($result)
57 | {
58 | $this->assertNotEmpty($result['checkout_url'], 'checkout_url is empty');
59 | $this->assertNotEmpty($result['payment_id'], 'payment_id is empty');
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/tests/ValidationTest.php:
--------------------------------------------------------------------------------
1 | 1396424,
12 | 'card_number' => '4444555511116666',
13 | 'cvv2' => '333',
14 | 'order_desc' => 'testing',
15 | 'date' => '1994-08-05',
16 | 'client_ip' => '127.0.0.1'
17 | ];
18 | private $requiredParams = [
19 | 'merchant_id' => 'integer',
20 | 'order_desc' => 'string',
21 | 'card_number' => 'ccnumber',
22 | 'date' => 'date',
23 | 'client_ip' => 'ip'
24 | ];
25 |
26 | public function __construct($name = null, array $data = array(), $dataName = '')
27 | {
28 | parent::__construct($name, $data, $dataName);
29 | }
30 |
31 | /**
32 | * @throws InvalidArgumentException
33 | */
34 | public function testValidateCard()
35 | {
36 | try {
37 | $is_true = Helper\ValidationHelper::validateRequiredParams($this->TestData, $this->requiredParams);
38 | $this->assertTrue($is_true, 'Params is valid');
39 | } catch (InvalidArgumentException $e) {
40 | $this->fail($e);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/VerificationTest.php:
--------------------------------------------------------------------------------
1 | 'USD',
11 | 'amount' => 1000,
12 | ];
13 | private $mid = 1396424;
14 | private $secret_key = 'test';
15 | private $request_types = ['json', 'xml', 'form'];
16 |
17 | private function setTestConfig()
18 | {
19 | Configuration::setMerchantId($this->mid);
20 | Configuration::setSecretKey($this->secret_key);
21 | Configuration::setApiVersion('1.0');
22 | }
23 |
24 | /**
25 | * @throws Exception\ApiException
26 | */
27 | public function testVerificationUrl()
28 | {
29 | $this->setTestConfig();
30 | foreach ($this->request_types as $type) {
31 | Configuration::setRequestType($type);
32 | $result = Verification::url($this->minTestData)->getData();
33 | $this->validateUrlResult($result);
34 | }
35 | }
36 |
37 | private function validateUrlResult($result)
38 | {
39 | $this->assertNotEmpty($result['checkout_url'], 'checkout_url is empty');
40 | $this->assertNotEmpty($result['payment_id'], 'payment_id is empty');
41 | $this->assertEquals($result['response_status'], 'success');
42 | }
43 | }
44 |
--------------------------------------------------------------------------------