Skip to content

Commit

Permalink
Rewritten :)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgurg committed Nov 9, 2020
1 parent 1e957cf commit ef6d664
Show file tree
Hide file tree
Showing 12 changed files with 1,267 additions and 1,157 deletions.
110 changes: 58 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,67 @@

# Direct Pay Online API Wrapper for PHP
Unofficial PHP wrapper for [Direct Pay Online API](https://directpayonline.atlassian.net/wiki/spaces/API/overview)

Inspired by [cy6erlion/direct-pay-online](https://github.com/cy6erlion/direct-pay-online)

## Installation
You can install via [Composer](https://getcomposer.org/).
# Direct Pay Online API Wrapper for PHP
Unofficial PHP wrapper for [Direct Pay Online API](https://directpayonline.atlassian.net/wiki/spaces/API/overview)
Inspired by [cy6erlion/direct-pay-online](https://github.com/cy6erlion/direct-pay-online)
## Installation
You can install via [Composer](https://getcomposer.org/).

composer require dipnot/direct-pay-online-php

## Usage
### createToken
Create a token to start payment process.
```php
use Dipnot\DirectPayOnline;
use Dipnot\Service;
use Dipnot\Transaction;

require_once("./../vendor/autoload.php");

$directPayOnline = new DirectPayOnline("9F416C11-127B-4DE2-AC7F-D5710E4C5E0A");
$transaction = new Transaction(100, "USD");
$service1 = new Service("Test Product", 3854, "2020/02/12 11:21");
$service2 = new Service("Test Service", 5525, "2020/02/12 11:21");

## Usage
You can see the full example in [examples/index.php](https://github.com/dipnot/direct-pay-online-php/tree/main/examples/index.php).
### Config
All request are needs a Config.
```php
use Dipnot\DirectPayOnline\Config;

$createToken = $directPayOnline->createToken(
$transaction,
[$service1, $service2]
);

print_r($createToken); // You can access the token with $createToken["TransToken"]
```

### getPaymentLink
Get the payment link with the created token to redirect the user to the payment page.
```php
...
// You will get the payment URL
$directPayOnline->getPaymentUrl($createToken["TransToken"]);
...
$config = new Config();
$config->setCompanyToken("9F416C11-127B-4DE2-AC7F-D5710E4C5E0A");
$config->setTestMode(true);
```
### Transaction
```php
use Dipnot\DirectPayOnline\Model\Transaction;

### Test mode
You can use test API for testing purpose. Just pass `true` as second parameter.
```php
$directPayOnline = new DirectPayOnline("COMPANY_TOKEN", true);
```
$transaction = new Transaction(100, "USD");
```

## Test values
You can fill the personal info randomly in the payment page.
### Service
```php
use Dipnot\DirectPayOnline\Model\Service;

||Value|
|--|--|
|Company token|9F416C11-127B-4DE2-AC7F-D5710E4C5E0A|
|Card number|5436886269848367|
|Card expiry date (Month/Year)|12/22|
|Card CVV|123|
$service = new Service("Test Product", 3854, "2020/02/12 11:21");
```
### createToken Request
Create a token to start payment process.
```php
use Dipnot\DirectPayOnline\Request\CreateTokenRequest;

## License
[![License: MIT](https://img.shields.io/badge/License-MIT-%232fdcff)](https://github.com/dipnot/direct-pay-online-php/blob/main/LICENSE)
$createTokenRequest = new CreateTokenRequest($config);
$createTokenRequest->setTransaction($transaction);
$createTokenRequest->setServices([$service1, $service2]);
$createToken = $createTokenRequest->execute();
print_r($createToken);
```

### getPaymentLink
Get the payment link with the created token to redirect the user to the payment page.
```php
$paymentUrl = $createTokenRequest->getPaymentUrl($createToken["TransToken"]);
print_r($paymentUrl);
```

## Test values
You can fill the personal info randomly in the payment page.

||Value|
|--|--|
|Company token|9F416C11-127B-4DE2-AC7F-D5710E4C5E0A|
|Card number|5436886269848367|
|Card expiry date (Month/Year)|12/22|
|Card CVV|123|

## License
[![License: MIT](https://img.shields.io/badge/License-MIT-%232fdcff)](https://github.com/dipnot/direct-pay-online-php/blob/main/LICENSE)
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
"require": {
"php": ">=5.6.36",
"ext-curl": "*",
"ext-simplexml": "*"
"ext-simplexml": "*",
"ext-json": "*"
},
"autoload": {
"psr-4": {
"Dipnot\\": "src/Dipnot/"
}
}
}
}
18 changes: 0 additions & 18 deletions examples/createToken.php

This file was deleted.

30 changes: 30 additions & 0 deletions examples/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
use Dipnot\DirectPayOnline\Config;
use Dipnot\DirectPayOnline\Model\Service;
use Dipnot\DirectPayOnline\Model\Transaction;
use Dipnot\DirectPayOnline\Request\CreateTokenRequest;

require_once("./../vendor/autoload.php");

// Config
$config = new Config();
$config->setCompanyToken("9F416C11-127B-4DE2-AC7F-D5710E4C5E0A");
$config->setTestMode(true);

// Transaction
$transaction = new Transaction(100, "USD");

// Service
$service1 = new Service("Test Product", 3854, "2020/02/12 11:21");
$service2 = new Service("Test Service", 5525, "2020/02/12 11:21");

// createToken Request
$createTokenRequest = new CreateTokenRequest($config);
$createTokenRequest->setTransaction($transaction);
$createTokenRequest->setServices([$service1, $service2]);
$createToken = $createTokenRequest->execute();
print_r($createToken);

// Get payment URL with created token
$paymentUrl = $createTokenRequest->getPaymentUrl($createToken["TransToken"]);
print_r($paymentUrl);
82 changes: 0 additions & 82 deletions src/Dipnot/DirectPayOnline.php

This file was deleted.

44 changes: 44 additions & 0 deletions src/Dipnot/DirectPayOnline/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace Dipnot\DirectPayOnline;

/**
* Class Config
* @package Dipnot\DirectPayOnline
*/
class Config
{
private $_companyToken;
private $_testMode;

/**
* @return string
*/
public function getCompanyToken()
{
return $this->_companyToken;
}

/**
* @param string $companyToken
*/
public function setCompanyToken($companyToken)
{
$this->_companyToken = $companyToken;
}

/**
* @return boolean
*/
public function isTestMode()
{
return $this->_testMode;
}

/**
* @param boolean $testMode
*/
public function setTestMode($testMode)
{
$this->_testMode = $testMode;
}
}
46 changes: 23 additions & 23 deletions src/Dipnot/Curl.php → src/Dipnot/DirectPayOnline/Curl.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php
namespace Dipnot;

/**
* Class Curl
* @package Dipnot
*/
class Curl
{
/**
* Creates and executes cURL
*
* @param string $url
* @param array $options
*
* @return bool|string
*/
function execute($url, $options)
{
$curl = curl_init($url);
curl_setopt_array($curl, $options);
return curl_exec($curl);
}
<?php
namespace Dipnot\DirectPayOnline;

/**
* Class Curl
* @package Dipnot\DirectPayOnline
*/
class Curl
{
/**
* Creates and executes cURL
*
* @param string $url
* @param array $options
*
* @return bool|string
*/
function execute($url, $options)
{
$curl = curl_init($url);
curl_setopt_array($curl, $options);
return curl_exec($curl);
}
}
Loading

0 comments on commit ef6d664

Please sign in to comment.