Skip to content

Commit

Permalink
example to creating token and some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
drealecs committed Nov 18, 2015
1 parent bc34141 commit f17d54f
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 46 deletions.
205 changes: 205 additions & 0 deletions examples/createTokenForRecurrentPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<?php
/**
* Include composer class autoloader
*/
require_once dirname(__FILE__) . '/../vendor/autoload.php';

use PayU\Alu\Billing;
use PayU\Alu\Card;
use PayU\Alu\Client;
use PayU\Alu\Delivery;
use PayU\Alu\MerchantConfig;
use PayU\Alu\Order;
use PayU\Alu\Product;
use PayU\Alu\Request;
use PayU\Alu\User;
use PayU\Alu\Exceptions\ConnectionException;
use PayU\Alu\Exceptions\ClientException;


/**
* Create configuration with params:
*
* Merchant Code - Your PayU Merchant Code
* Secret Key - Your PayU Secret Key
* Platform - RO | RU | UA | TR | HU
*/
$cfg = new MerchantConfig('MERCHANT_CODE', 'SECRET_KEY', 'RO');

/**
* Create user with params:
*
* User IP - User's IP address
* Card Number Input Time - Time it took the user to enter credit card number in seconds
* User Time - Time of user computer - optional
*
*/
$user = new User('127.0.0.1');

/**
* Create new order
*/
$order = new Order();

/**
* Setup the order params
*
* Full params available in the documentation
*/
$order->withBackRef('http://path/to/your/returnUrlScript')
->withOrderRef('MerchantOrderRef')
->withCurrency('RON')
->withOrderDate(gmdate('Y-m-d H:i:s'))
->withOrderTimeout(1000)
->withPayMethod('CCVISAMC');

/**
* Create new product
*/
$product = new Product();

/**
* Setup the product params
*
* Full params available in the documentation
*/
$product->withCode('PCODE01')
->withName('PNAME01')
->withPrice(100.0)
->withVAT(24.0)
->withQuantity(1);

/**
* Add the product to the order
*/
$order->addProduct($product);

/**
* Create another product
*/
$product = new Product();

/**
* Setup the product params
*
* Full params available in the documentation
*/
$product->withCode('PCODE02')
->withName('PNAME02')
->withPrice(200.0)
->withVAT(24.0)
->withQuantity(1);

/**
* Add the second product to the same order
*/
$order->addProduct($product);

/**
* Create new billing address
*/
$billing = new Billing();

/**
* Setup the billing address params
*
* Full params available in the documentation
*/
$billing->withAddressLine1('Address1')
->withAddressLine2('Address2')
->withCity('City')
->withCountryCode('RO')
->withEmail('john.doe@mail.com')
->withFirstName('FirstName')
->withLastName('LastName')
->withPhoneNumber('40123456789')
->withIdentityCardNumber('111222');

/**
* Create new delivery address
*
* If you want to have the same delivery as billing, skip these two steps
* and pass the Billing $billing object to the request twice
*/
$delivery = new Delivery();

/**
* Setup the delivery address params
*
* Full params available in the documentation
*/
$delivery->withAddressLine1('Address1')
->withAddressLine2('Address2')
->withCity('City')
->withCountryCode('RO')
->withEmail('john.doe@mail.com')
->withFirstName('FirstName')
->withLastName('LastName')
->withPhoneNumber('40123456789');

/**
* Create new Card with params:
*
* Credit Card Number
* Credit Card Expiration Month
* Credit Card Expiration Year
* Credit Card CVV (Security Code)
* Credit Card Owner
*/
$card = new Card('4111111111111111', '12', 2016, 123, 'Card Owner Name');

/**
* tokenize card for further token payments
*/
$card->enableTokenCreation();

/**
* Create new Request with params:
*
* Config object
* Order object
* Billing object
* Delivery (or Billing object again, if you want to have the delivery address the same as the billing address)
* User object
*/
$request = new Request($cfg, $order, $billing, $delivery, $user);

/**
* Add the Credit Card to the Request
*/
$request->setCard($card);

/**
* Create new API Client, passing the Config object as parameter
*/
$client = new Client($cfg);

/**
* Will throw different Exceptions on errors
*/
try {
/**
* Sends the Request to ALU and returns a Response
*
* See documentation for Response params
*/
$response = $client->pay($request);

/**
* In case of 3DS enrolled cards, PayU will return the URL_3DS that contains a unique url for each
* transaction. The merchant must redirect the browser to this url to allow user to authenticate.
* After the authentication process ends the user will be redirected to BACK_REF url
* with payment result in a HTTP POST request
*/
if ($response->isThreeDs()) {
header("Location:" . $response->getThreeDsUrl());
die();
}

echo $response->getStatus(). ' ' . $response->getReturnCode() . ' ' . $response->getReturnMessage();

} catch (ConnectionException $exception) {
echo $exception->getMessage();
} catch (ClientException $exception) {
echo $exception->getErrorMessage();
}
46 changes: 0 additions & 46 deletions src/PayU/Alu/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ class Order
*/
private $customParams = array();

/**
* @var boolean
*/
private $luEnabledToken;

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

/**
* @var string
*/
Expand Down Expand Up @@ -237,42 +227,6 @@ public function getInstallmentsNumber()
return $this->installmentsNumber;
}

/**
* @param boolean $luEnabledToken
* @return $this
*/
public function withLuEnabledToken($luEnabledToken)
{
$this->luEnabledToken = $luEnabledToken;
return $this;
}

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

/**
* @param string $luTokenType
* @return $this
*/
public function withLuTokenType($luTokenType)
{
$this->luTokenType = $luTokenType;
return $this;
}

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

/**
* @param string $orderDate
* @return $this
Expand Down

2 comments on commit f17d54f

@prgTW
Copy link

@prgTW prgTW commented on f17d54f Jun 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, You did a backwards-incompatible change 👎
I recommend reading and using http://semver.org/ or at least mark unused methods as @deprecated and remove them only in next major version ... not in minors

If You put Your project into packagist at least follow what is written here:
https://getcomposer.org/doc/articles/versions.md#versions

@drealecs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @prgTW,

Indeed, it was a mistake. Thank you for pointing it out. I fixed it in version 1.1.1, re-adding the methods
We will keep it in the next planned release 1.2.0.

If you look closely the values luEnabledToken and luTokenType could only be set and was never used in the creation the the request. They are related to a functionality that was only started and wasn't finished but was by mistake included in the 1.0.0 release.
Considering this we though it would be wise to clean it up.
But methods being in the public API, it will be used so better clear them up.

For now, we will keep the wrong/dummy implementation as it is and think about releasing a fixed implementation. However we need to consider not breaking merchant integrations that might rely on nothing happening when using the methods.

In order to use the token creation functionality, please see Card::enableTokenCreation() method.

Thanks again and sorry for delay. As it was my commit, I think my colleagues didn't received any email notifications.

Please sign in to comment.