From f17d54fdc15e3337eff11be9cdcd9e9b4fd4ef0c Mon Sep 17 00:00:00 2001 From: Alexandru Patranescu Date: Wed, 18 Nov 2015 07:05:52 +0200 Subject: [PATCH] example to creating token and some code cleanup --- examples/createTokenForRecurrentPayment.php | 205 ++++++++++++++++++++ src/PayU/Alu/Order.php | 46 ----- 2 files changed, 205 insertions(+), 46 deletions(-) create mode 100644 examples/createTokenForRecurrentPayment.php diff --git a/examples/createTokenForRecurrentPayment.php b/examples/createTokenForRecurrentPayment.php new file mode 100644 index 00000000..bd03c992 --- /dev/null +++ b/examples/createTokenForRecurrentPayment.php @@ -0,0 +1,205 @@ +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(); +} diff --git a/src/PayU/Alu/Order.php b/src/PayU/Alu/Order.php index c1f9e3f6..622b9ae5 100644 --- a/src/PayU/Alu/Order.php +++ b/src/PayU/Alu/Order.php @@ -75,16 +75,6 @@ class Order */ private $customParams = array(); - /** - * @var boolean - */ - private $luEnabledToken; - - /** - * @var string - */ - private $luTokenType; - /** * @var string */ @@ -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