Skip to content

Commit

Permalink
Purchase Form
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdnepr committed Jul 3, 2019
1 parent 72676fa commit 9af3585
Show file tree
Hide file tree
Showing 30 changed files with 1,615 additions and 145 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
.idea
composer.lock
composer.lock
pay.html
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ PHP SDK for payment system [WayForPay](https://wayforpay.com).
- [WayForPay documentation](#wayforpay-documentation)
- [How to use](#how-to-use)
- [Wizard](#wizard)
- [Purchase Form](#purchase-form)
- [Transactions List](#transactions-list)
- [Charge](#charge)
- [Complete 3DS](#complete-3ds)
Expand All @@ -30,6 +31,23 @@ PHP SDK for payment system [WayForPay](https://wayforpay.com).

## How to use
### Wizard

#### Purchase Form

See [transaction-list.php](examples/purchase.php).

```bash
$ php examples/purchase.php > pay.html
```

After you can see at `pay.html` form with pay button. Open file in your browser and press `Pay`.

You can open file via default browser in Linux-based OS like:

```bash
$ x-www-browser pay.html
```

#### Transactions List

See [transaction-list.php](examples/transaction-list.php).
Expand Down
4 changes: 0 additions & 4 deletions examples/charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
use WayForPay\SDK\Domain\Card;
use WayForPay\SDK\Domain\Client;
use WayForPay\SDK\Domain\Product;
use WayForPay\SDK\Domain\Transaction;
use WayForPay\SDK\Exception\ApiException;
use WayForPay\SDK\Request\ChargeRequest;
use WayForPay\SDK\Wizard\ChargeWizard;

// Use test credential or yours
Expand All @@ -35,8 +33,6 @@
->setCurrency('USD')
->setOrderDate(new \DateTime())
->setMerchantDomainName('https://google.com')
->setMerchantTransactionType(Transaction::MERCHANT_TRANSACTION_TYPE_SALE)
->setMerchantTransactionSecureType(ChargeRequest::MERCHANT_TRANSACTION_SECURE_TYPE_AUTO)
->setClient(new Client(
'John',
'Dou',
Expand Down
46 changes: 46 additions & 0 deletions examples/purchase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the WayForPay project.
*
* @link https://github.com/wayforpay/php-sdk
*
* @author Vladislav Lyshenko <vladdnepr1989@gmail.com>
* @copyright Copyright 2019 WayForPay
* @license https://opensource.org/licenses/MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

require_once __DIR__ . '/../vendor/autoload.php';

use WayForPay\SDK\Collection\ProductCollection;
use WayForPay\SDK\Credential\AccountSecretTestCredential;
use WayForPay\SDK\Domain\Client;
use WayForPay\SDK\Domain\Product;
use WayForPay\SDK\Wizard\PurchaseWizard;

// Use test credential or yours
$credential = new AccountSecretTestCredential();
//$credential = new AccountSecretCredential('account', 'secret');

$form = PurchaseWizard::get($credential)
->setOrderReference(sha1(microtime(true)))
->setAmount(0.01)
->setCurrency('USD')
->setOrderDate(new \DateTime())
->setMerchantDomainName('https://google.com')
->setClient(new Client(
'John',
'Dou',
'john.dou@gmail.com',
'+12025550152',
'USA'
))
->setProducts(new ProductCollection(array(
new Product('test', 0.01, 1)
)))
->getForm()
->getAsString();

echo '<html><body><h1>Pay Form</h1>' . $form . '</body></html>';
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

use anlutro\cURL\cURL;
use anlutro\cURL\Request;
use WayForPay\SDK\Contract\ClientInterface;
use WayForPay\SDK\Contract\RequestInterface;
use WayForPay\SDK\Contract\RequestTransformerInterface;
use WayForPay\SDK\Contract\ResponseInterface;
use WayForPay\SDK\Contract\TransactionRequestInterface;

class CurlClient implements ClientInterface
class CurlRequestTransformer implements RequestTransformerInterface
{
/**
* @param TransactionRequestInterface $transactionRequest
* @param RequestInterface $transactionRequest
* @return ResponseInterface
*/
public function send(TransactionRequestInterface $transactionRequest)
public function transform(RequestInterface $transactionRequest)
{
$endpoint = $transactionRequest->getEndpoint();

Expand All @@ -35,7 +35,7 @@ public function send(TransactionRequestInterface $transactionRequest)
$request = $curl->newRequest(
$endpoint->getMethod(),
$endpoint->getUrl(),
$transactionRequest->getTransactionData(),
array_filter($transactionRequest->getTransactionData()),
Request::ENCODING_JSON
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace WayForPay\SDK\Contract;


interface TransactionRequestInterface
interface RequestInterface
{
/**
* @return array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
namespace WayForPay\SDK\Contract;


interface ClientInterface
interface RequestTransformerInterface
{
/**
* @param TransactionRequestInterface $transactionRequest
* @param RequestInterface $transactionRequest
* @return ResponseInterface
*/
public function send(TransactionRequestInterface $transactionRequest);
public function transform(RequestInterface $transactionRequest);
}
114 changes: 114 additions & 0 deletions src/Domain/Avia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/*
* This file is part of the WayForPay project.
*
* @link https://github.com/wayforpay/php-sdk
*
* @author Vladislav Lyshenko <vladdnepr1989@gmail.com>
* @copyright Copyright 2019 WayForPay
* @license https://opensource.org/licenses/MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WayForPay\SDK\Domain;

use DateTime;

class Avia
{
/**
* @var string
*/
private $departureDate;

/**
* @var string
*/
private $locationNumber;

/**
* @var string
*/
private $locationCodes;

/**
* @var string
*/
private $nameFirst;

/**
* @var string
*/
private $nameLast;

/**
* @var string
*/
private $reservationCode;

public function __construct(
DateTime $departureDate = null,
$locationNumber = null,
$locationCodes = null,
$nameFirst = null,
$nameLast = null,
$reservationCode = null
) {
$this->departureDate = $departureDate;
$this->locationNumber = strval($locationNumber);
$this->locationCodes = strval($locationCodes);
$this->nameFirst = strval($nameFirst);
$this->nameLast = strval($nameLast);
$this->reservationCode = strval($reservationCode);
}

/**
* @return DateTime
*/
public function getDepartureDate()
{
return $this->departureDate;
}

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

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

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

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

/**
* @return string
*/
public function getReservationCode()
{
return $this->reservationCode;
}
}
20 changes: 10 additions & 10 deletions src/Domain/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ class Client

/**
* Client constructor.
* @param string $nameFirst
* @param string $nameLast
* @param string $email
* @param string $phone
* @param string $country
* @param string|null $nameFirst
* @param string|null $nameLast
* @param string|null $email
* @param string|null $phone
* @param string|null $country
* @param string|null $id
* @param string|null $ip
* @param string|null $address
Expand All @@ -86,11 +86,11 @@ class Client
* @param string|null $zip
*/
public function __construct(
$nameFirst,
$nameLast,
$email,
$phone,
$country,
$nameFirst = null,
$nameLast = null,
$email = null,
$phone = null,
$country = null,
$id = null,
$ip = null,
$address = null,
Expand Down
Loading

0 comments on commit 9af3585

Please sign in to comment.