├── tests ├── .gitignore ├── Bootstrap.php ├── phpunit.xml ├── CurrencyTest.php ├── ConfigurationTest.php └── ClientTest.php ├── .gitignore ├── src └── Payu │ ├── Component │ ├── ComponentInterface.php │ ├── Currency.php │ ├── Card.php │ ├── Basket.php │ ├── Product.php │ ├── Billing.php │ ├── Delivery.php │ └── Order.php │ ├── Exception │ ├── BadResponseError.php │ ├── ConnectionError.php │ └── ValidationError.php │ ├── Parser │ ├── ParserInterface.php │ ├── ResponseParser.php │ ├── LoyaltyInquiryResponseParser.php │ └── PaymentResponseParser.php │ ├── Validator │ ├── Validator │ │ ├── DeliveryValidator.php │ │ ├── BillingValidator.php │ │ ├── ProductValidator.php │ │ ├── ValidatorAbstract.php │ │ ├── BasketValidator.php │ │ ├── CardValidator.php │ │ └── OrderValidator.php │ ├── ValidatorAbstract.php │ ├── LoyaltyInquiryRequestValidator.php │ └── PaymentRequestValidator.php │ ├── Request │ ├── RequestAbstract.php │ ├── LoyaltyInquiryRequest.php │ └── PaymentRequest.php │ ├── Serializer │ ├── LoyaltyInquiryRequestSerializer.php │ ├── SerializerAbstract.php │ └── PaymentRequestSerializer.php │ ├── Builder │ ├── BuilderAbstract.php │ ├── LoyaltyInquiryRequestBuilder.php │ └── PaymentRequestBuilder.php │ ├── Response │ ├── PaymentResponse.php │ ├── LoyaltyInquiryResponse.php │ └── ResponseAbstract.php │ ├── Client.php │ └── Configuration.php ├── docs ├── contributors.md ├── index.md ├── birim_testlerin_calistirilmasi.md ├── 3d-secure-ile-satis.md ├── puan_kullanimi.md ├── puan_sorgulama.md └── satis.md ├── composer.json ├── README.md └── LICENSE.txt /tests/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | vendor 3 | *.lock 4 | tests/testresults/ 5 | .DS_Store 6 | *.swp 7 | -------------------------------------------------------------------------------- /src/Payu/Component/ComponentInterface.php: -------------------------------------------------------------------------------- 1 | rawData = $rawData; 19 | return $this; 20 | } 21 | 22 | /** 23 | * @return array 24 | */ 25 | public function getRawData() 26 | { 27 | return $this->rawData; 28 | } 29 | 30 | abstract public function getCard(); 31 | } -------------------------------------------------------------------------------- /src/Payu/Validator/ValidatorAbstract.php: -------------------------------------------------------------------------------- 1 | request = $request; 19 | } 20 | 21 | 22 | 23 | /** 24 | * @return void 25 | * @throws \Payu\Exception\ValidationError 26 | */ 27 | abstract public function validate(); 28 | } -------------------------------------------------------------------------------- /tests/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | ./ 10 | 11 | 12 | 13 | 14 | 15 | ./../src 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Payu/Validator/Validator/BillingValidator.php: -------------------------------------------------------------------------------- 1 | request->getBilling(); 20 | if(!$object || !$object instanceof Billing) { 21 | throw new ValidationError('Billing information does not be empty.'); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/Payu/Validator/LoyaltyInquiryRequestValidator.php: -------------------------------------------------------------------------------- 1 | validators as $class) { 17 | /** @var $instance \Payu\Validator\Validator\ValidatorAbstract */ 18 | $instance = new $class($this->request); 19 | $instance->validate(); 20 | unset($instance); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Payu/Parser/ResponseParser.php: -------------------------------------------------------------------------------- 1 | parser = $parser; 23 | $this->rawResponse = $rawResponse; 24 | } 25 | 26 | /** 27 | * @return \Payu\Response\ResponseAbstract 28 | */ 29 | public function parse() 30 | { 31 | return $this->parser->parse($this->rawResponse); 32 | } 33 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ibrahimgunduz34/payuclient", 3 | "type": "library", 4 | "description": "Payment client for Payu Turkey provider.", 5 | "keywords": ["payment", "e-commerce", "payu"], 6 | "require": { 7 | "php": "> 5.3.0", 8 | "guzzle/guzzle": "3.9.2" 9 | }, 10 | "require-dev": { 11 | "phpunit/phpunit": "3.7.*" 12 | }, 13 | "license": "MIT", 14 | "authors": [ 15 | { 16 | "name": "ibrahimgunduz34", 17 | "email": "ibrahimgunduz34@gmail.com", 18 | "homepage": "http://ibrahimgunduz.net" 19 | } 20 | ], 21 | "autoload": { 22 | "psr-0": { 23 | "Payu": "src/", 24 | "Payu\\Tests": "tests/" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/Payu/Validator/Validator/ProductValidator.php: -------------------------------------------------------------------------------- 1 | product = $product; 17 | } 18 | 19 | /** 20 | * @return void 21 | * @throws \Payu\Exception\ValidationError 22 | */ 23 | protected function validateObject() 24 | { 25 | if(!$this->product || !$this->product instanceof Product) { 26 | throw new ValidationError('Basket items must be instance of Product'); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/Payu/Validator/Validator/ValidatorAbstract.php: -------------------------------------------------------------------------------- 1 | request = $request; 19 | } 20 | 21 | /** 22 | * @return void 23 | * @throws \Payu\Exception\ValidationError 24 | */ 25 | abstract protected function validateObject(); 26 | 27 | /** 28 | * @return void 29 | * @throws \Payu\Exception\ValidationError 30 | */ 31 | public function validate() 32 | { 33 | $this->validateObject(); 34 | } 35 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP İçin Payu İstemcisi 2 | 3 | # Nedir ? 4 | PHP geliştiricilerinin Payu üzerinden ödeme ve puan sorgulama işlemlerini kolayca gerçekleştirebilmesini sağlayan bir PHP kütüphanesidir. 5 | 6 | # Neden ? 7 | Entegrasyon detaylarıyla uğraşmadan mevcut uygulamaya kolayca entegrasyonu sağlanarak geliştirme maliyetini düşürür. 8 | 9 | # Nasıl ? 10 | Payu istemci kütüphanesi composer desteklidir. Mevcut uygulamanızın gereksinimler (requirements) alanına "ibrahimgunduz34/payuclient" bileşenini ekleyebilir veya aşağıdaki komutu çalıştırarak kurulumu gerçekleştirebilirsiniz. 11 | 12 | ```shell 13 | $ composer require ibrahimgunduz34/payuclient:dev-master 14 | ``` 15 | 16 | Entegrasyon detayları ile ilgili dökümanları [buraya tıklayarak](/docs/index.md) inceleyebilirsiniz. 17 | 18 | Katkıda bulunan geliştiriciler için [buraya tıklayınız](/docs/contributors.md) 19 | -------------------------------------------------------------------------------- /src/Payu/Validator/PaymentRequestValidator.php: -------------------------------------------------------------------------------- 1 | validators as $class) { 20 | /** @var $instance \Payu\Validator\Validator\ValidatorAbstract */ 21 | $instance = new $class($this->request); 22 | $instance->validate(); 23 | unset($instance); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /tests/CurrencyTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($cur, $expected); 19 | } 20 | 21 | public function goodCurrencyProvider() 22 | { 23 | return array( 24 | array('TRY', 'TRY'), 25 | array('EUR', 'EUR'), 26 | array('GBP', 'GBP'), 27 | array('USD', 'USD'), 28 | // Lowercase 29 | array('usd', 'USD'), 30 | array('gbp', 'GBP'), 31 | array('eur', 'EUR'), 32 | array('try', 'TRY'), 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Payu/Serializer/LoyaltyInquiryRequestSerializer.php: -------------------------------------------------------------------------------- 1 | $this->configuration->getMerchantId(), 20 | 'CURRENCY' => $this->request->getCurrency()->getCode(), 21 | 'DATE' => $this->request->getDate(), 22 | ), 23 | $this->serializeCard() 24 | ); 25 | $filteredData = array_filter($concatenatedData); 26 | $filteredData['HASH'] = $this->calculateHash($filteredData); 27 | 28 | return $filteredData; 29 | } 30 | } -------------------------------------------------------------------------------- /docs/birim_testlerin_calistirilmasi.md: -------------------------------------------------------------------------------- 1 | # Birim Testlerin Çalıştırılması 2 | Birim testleri çalıştırmak için sisteminizde [PHPUnit](https://phpunit.de) kurulu olmalıdır. 3 | 4 | PHPUnit'i çalıştırılabilir PHP Arşiv Paketi (PHAR) halinde kurmak için: 5 | 6 | ``` 7 | $ wget https://phar.phpunit.de/phpunit.phar 8 | $ chmod +x phpunit.phar 9 | $ mv phpunit.phar /usr/local/bin/phpunit 10 | ``` 11 | 12 | veya Mac OS X kullanıcısı iseniz [Homebrew](http://brew.sh/) yardımıyla kurmak için: 13 | 14 | ``` 15 | $ brew update 16 | $ brew install phpunit 17 | ``` 18 | 19 | komutlarını vermeniz yeterlidir. Kurulum sonrası unit testleri çalıştırmak için aşağıdaki komutu verebilirsiniz: 20 | 21 | ``` 22 | $ cd /path/to/payuclient 23 | $ phpunit -c tests/phpunit.xml 24 | 25 | PHPUnit 3.7.38 by Sebastian Bergmann. 26 | Configuration read from payuclient/tests/phpunit.xml 27 | 28 | ........................ 29 | 30 | Time: 1.58 seconds, Memory: 6.75Mb 31 | 32 | OK (24 tests, 27 assertions) 33 | ``` 34 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) İbrahim Gündüz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /src/Payu/Builder/BuilderAbstract.php: -------------------------------------------------------------------------------- 1 | card = new Card($number, $cvv, $month, $year, $owner); 30 | return $this; 31 | } 32 | 33 | /** 34 | * @param Card $card 35 | * @return $this 36 | */ 37 | public function setCard(Card $card) 38 | { 39 | $this->card = $card; 40 | return $this; 41 | } 42 | 43 | public function __construct(Configuration $configuration) 44 | { 45 | $this->configuration = $configuration; 46 | } 47 | 48 | /** 49 | * @return \Payu\Response\ResponseAbstract 50 | */ 51 | abstract public function build(); 52 | } -------------------------------------------------------------------------------- /src/Payu/Validator/Validator/BasketValidator.php: -------------------------------------------------------------------------------- 1 | request->getBasket(); 16 | if(!$object || !$object instanceof Basket) { 17 | throw new ValidationError('Basket is not set.'); 18 | } 19 | } 20 | 21 | private function validateProducts() 22 | { 23 | /** 24 | * @var $collection \Payu\Component\Basket 25 | */ 26 | $collection = $this->request->getBasket(); 27 | if(!$collection->count()) { 28 | throw new ValidationError('Basket does not be empty.'); 29 | } 30 | 31 | /** @var $product \Payu\Component\Product */ 32 | foreach($collection as $product) { 33 | $validator = new ProductValidator($product); 34 | $validator->validate(); 35 | unset($validator); 36 | } 37 | } 38 | 39 | public function validate() 40 | { 41 | parent::validate(); 42 | $this->validateProducts(); 43 | } 44 | } -------------------------------------------------------------------------------- /src/Payu/Component/Currency.php: -------------------------------------------------------------------------------- 1 | setCode($code); 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getCode() 31 | { 32 | return $this->code; 33 | } 34 | 35 | /** 36 | * Sets currency code. 37 | * 38 | * @param string $code 39 | */ 40 | public function setCode($code) 41 | { 42 | // Always use uppercase currency codes internally 43 | $this->code = strtoupper(preg_replace('/[^a-zA-Z]/', '', $code)); 44 | 45 | return $this; 46 | } 47 | 48 | /** 49 | * Returns string representation of the currency 50 | * instance in case of casting a currency instance to string. 51 | * 52 | * @return string 53 | */ 54 | public function __toString() 55 | { 56 | return $this->code; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Payu/Parser/LoyaltyInquiryResponseParser.php: -------------------------------------------------------------------------------- 1 | STATUS; 21 | $message = (string) $xml->MESSAGE; 22 | $points = ($xml->POINTS) ? (integer) $xml->POINTS : false; 23 | $amount = ($xml->AMOUNT) ? (float) $xml->AMOUNT : false; 24 | $currency = ($xml->CURRENCY) ? (string) $xml->CURRENCY : false; 25 | $bank = ($xml->BANK) ? (string) $xml->BANK : false; 26 | $cardProgramName = ($xml->CARD_PROGRAM_NAME) ? (string) $xml->CARD_PROGRAM_NAME : false; 27 | 28 | $status = ($status == 'SUCCESS') ? ResponseAbstract::STATUS_APPROVED : ResponseAbstract::STATUS_DECLINED; 29 | 30 | return new LoyaltyInquiryResponse($status, $status, $message, $points, $amount, $currency, $bank, $cardProgramName); 31 | } 32 | } -------------------------------------------------------------------------------- /src/Payu/Request/LoyaltyInquiryRequest.php: -------------------------------------------------------------------------------- 1 | card; 27 | } 28 | 29 | /** 30 | * @param \Payu\Component\Card $card 31 | */ 32 | public function setCard($card) 33 | { 34 | $this->card = $card; 35 | } 36 | 37 | /** 38 | * @return \Payu\Component\Currency 39 | */ 40 | public function getCurrency() 41 | { 42 | return $this->currency; 43 | } 44 | 45 | /** 46 | * @param \Payu\Component\Currency $currency 47 | */ 48 | public function setCurrency($currency) 49 | { 50 | $this->currency = $currency; 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getDate() 57 | { 58 | return $this->date; 59 | } 60 | 61 | public function __construct($card = null, $currency = null) 62 | { 63 | $this->date = gmdate('Y-m-d H:i:s'); 64 | $this->setCard($card); 65 | $this->setCurrency($currency); 66 | } 67 | } -------------------------------------------------------------------------------- /src/Payu/Builder/LoyaltyInquiryRequestBuilder.php: -------------------------------------------------------------------------------- 1 | currency; 23 | } 24 | 25 | /** 26 | * @param Currency $currency 27 | */ 28 | public function setCurrency(Currency $currency) 29 | { 30 | $this->currency = $currency; 31 | } 32 | 33 | public function buildCurrency($currency) { 34 | $this->currency = new Currency($currency); 35 | return $this; 36 | } 37 | 38 | public function __construct(Configuration $configuration) 39 | { 40 | parent::__construct($configuration); 41 | } 42 | 43 | public function build() 44 | { 45 | $request = new LoyaltyInquiryRequest($this->card, $this->currency); 46 | 47 | $validator = new LoyaltyInquiryRequestValidator($request); 48 | $validator->validate(); 49 | 50 | $serializer = new LoyaltyInquiryRequestSerializer($request, $this->configuration); 51 | $rawData = $serializer->serialize(); 52 | 53 | $request->setRawData($rawData); 54 | 55 | return $request; 56 | } 57 | } -------------------------------------------------------------------------------- /docs/3d-secure-ile-satis.md: -------------------------------------------------------------------------------- 1 | # 3D Secure ile Satış İşlemi 2 | 3 | 3D secure bir işlem yapmak için konfigürasyon sınıfımıza bir geri dönüş adresi eklememiz gerekli. Böylelikle PayU; 4 | gönderdiğimiz işlemin sonucu bize bildirebilir. 5 | 6 | ## Örnek akış 7 | 8 | ```php 9 | use Payu\Client; 10 | use Payu\Configuration; 11 | 12 | $configuration = new Configuration(); 13 | 14 | $configuration->setMerchantId('MY_MERCHANT_01') 15 | ->setSecretKey('SECRET_KEY') 16 | ->setPaymentEndpointUrl('https://secure.payu.com.tr/order/alu/v3') 17 | ->setPaymentReturnPointUrl('http://localhost:8001/callback.php'); //İşlemin sonucunu almak istediğim url 18 | 19 | ... 20 | 21 | $response = $client->makePayment($request); 22 | 23 | if ($response->getStatus() == ResponseAbstract::STATUS_UNAUTHORIZED) { 24 | header("Location: " . $response->getUrl3DS()); 25 | die(); 26 | } elseif ($response->getStatus() == ResponseAbstract::STATUS_APPROVED) { 27 | echo $response->getTransactionId(); 28 | } else { 29 | /* 30 | // Odeme islemi hatali oldu 31 | 32 | echo $response->getCode(); 33 | echo $response->getMessage(); 34 | */ 35 | } 36 | 37 | 38 | ``` 39 | 40 | ## Callback.php 41 | 42 | ```php 43 | use Payu\Response\ResponseAbstract; 44 | use Payu\Parser\PaymentResponseParser; 45 | 46 | 47 | $response = (new PaymentResponseParser())->parse($_POST); 48 | 49 | if ($response->getStatus() == ResponseAbstract::STATUS_APPROVED) { 50 | echo $response->getTransactionId(); 51 | } else { 52 | /* 53 | // Odeme islemi hatali oldu 54 | 55 | echo $response->getCode(); 56 | echo $response->getMessage(); 57 | */ 58 | } 59 | ``` 60 | 61 | -------------------------------------------------------------------------------- /src/Payu/Serializer/SerializerAbstract.php: -------------------------------------------------------------------------------- 1 | request = $request; 26 | $this->configuration = $configuration; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | protected function serializeCard() 33 | { 34 | /** @var $card \Payu\Component\Card */ 35 | $card = $this->request->getCard(); 36 | 37 | return array( 38 | 'CC_NUMBER' => $card->getNumber(), 39 | 'EXP_MONTH' => sprintf('%02d', $card->getMonth()), 40 | 'EXP_YEAR' => $card->getYear(), 41 | 'CC_CVV' => $card->getCvv(), 42 | 'CC_OWNER' => $card->getOwner() 43 | ); 44 | } 45 | 46 | protected function calculateHash($rawData) 47 | { 48 | ksort($rawData); 49 | $buffer = ''; 50 | foreach($rawData as $key => $value) { 51 | $buffer .= strlen($value) . $value; 52 | } 53 | 54 | return hash_hmac('md5', $buffer, $this->configuration->getSecretKey()); 55 | } 56 | 57 | /** 58 | * @return array 59 | */ 60 | abstract public function serialize(); 61 | } -------------------------------------------------------------------------------- /src/Payu/Response/PaymentResponse.php: -------------------------------------------------------------------------------- 1 | setTransactionId($transactionId); 33 | $this->setHash($hash); 34 | $this->setUrl3DS($url3DS); 35 | } 36 | 37 | /** 38 | * @param string $transactionId 39 | * @return $this; 40 | */ 41 | public function setTransactionId($transactionId) 42 | { 43 | $this->transactionId = $transactionId; 44 | } 45 | 46 | /** 47 | * @return string 48 | */ 49 | public function getTransactionId() 50 | { 51 | return $this->transactionId; 52 | } 53 | 54 | /** 55 | * @return string 56 | */ 57 | public function getHash() 58 | { 59 | return $this->hash; 60 | } 61 | 62 | /** 63 | * @param string $hash 64 | */ 65 | public function setHash($hash) 66 | { 67 | $this->hash = $hash; 68 | } 69 | 70 | /** 71 | * @return string 72 | */ 73 | public function getUrl3DS() 74 | { 75 | return $this->url3DS; 76 | } 77 | 78 | /** 79 | * @param string $url3DS 80 | */ 81 | public function setUrl3DS($url3DS) 82 | { 83 | $this->url3DS = $url3DS; 84 | } 85 | } -------------------------------------------------------------------------------- /tests/ConfigurationTest.php: -------------------------------------------------------------------------------- 1 | configuration = new Configuration('TestMerchantId', 'TestSecretKey', 'TestPaymentEndpointUrl', 14 | 'TestLoyaltyInquiryEndPointUrl'); 15 | } 16 | 17 | public function testConstructor() { 18 | $this->assertEquals('TestMerchantId', $this->configuration->getMerchantId()); 19 | $this->assertEquals('TestSecretKey', $this->configuration->getSecretKey()); 20 | $this->assertEquals('TestPaymentEndpointUrl', $this->configuration->getPaymentEndpointUrl()); 21 | $this->assertEquals('TestLoyaltyInquiryEndPointUrl', $this->configuration->getLoyaltyInquiryEndPointUrl()); 22 | } 23 | 24 | public function testSetMerchantId() { 25 | $this->configuration->setMerchantId('TestMerchantIdSetter'); 26 | $this->assertEquals('TestMerchantIdSetter', $this->configuration->getMerchantId()); 27 | } 28 | 29 | public function testSetSecretKey() { 30 | $this->configuration->setSecretKey('TestSecretKeySetter'); 31 | $this->assertEquals('TestSecretKeySetter', $this->configuration->getSecretKey()); 32 | } 33 | 34 | public function testSetPaymentEndpointUrl() { 35 | $this->configuration->setPaymentEndpointUrl('TestPaymentEndpointUrlSetter'); 36 | $this->assertEquals('TestPaymentEndpointUrlSetter', $this->configuration->getPaymentEndpointUrl()); 37 | } 38 | 39 | public function testSetLoyaltyInquiryEndPointUrl() { 40 | $this->configuration->setLoyaltyInquiryEndPointUrl('TestLoyaltyInquiryEndPointUrlSetter'); 41 | $this->assertEquals('TestLoyaltyInquiryEndPointUrlSetter', $this->configuration->getLoyaltyInquiryEndPointUrl()); 42 | } 43 | } -------------------------------------------------------------------------------- /src/Payu/Response/LoyaltyInquiryResponse.php: -------------------------------------------------------------------------------- 1 | points; 37 | } 38 | 39 | /** 40 | * @return float 41 | */ 42 | public function getAmount() 43 | { 44 | return $this->amount; 45 | } 46 | 47 | /** 48 | * @return string 49 | */ 50 | public function getCurrency() 51 | { 52 | return $this->currency; 53 | } 54 | 55 | /** 56 | * @return string 57 | */ 58 | public function getBank() 59 | { 60 | return $this->bank; 61 | } 62 | 63 | /** 64 | * @return string 65 | */ 66 | public function getCardProgramName() 67 | { 68 | return $this->cardProgramName; 69 | } 70 | 71 | /** 72 | * @param integer $status 73 | * @param string $code 74 | * @param string $message 75 | */ 76 | public function __construct 77 | ( 78 | $status, 79 | $code, 80 | $message, 81 | $points, 82 | $amount, 83 | $currency, 84 | $bank, 85 | $cardProgramName 86 | ) 87 | { 88 | parent::__construct($status, $code, $message); 89 | $this->points = $points; 90 | $this->amount = $amount; 91 | $this->currency = $currency; 92 | $this->bank = $bank; 93 | $this->cardProgramName = $cardProgramName; 94 | } 95 | } -------------------------------------------------------------------------------- /docs/puan_kullanimi.md: -------------------------------------------------------------------------------- 1 | # Puan Kullanım İşlemi 2 | Puan ile satış işlemi (satışta puan kullanımı), normal satış işleminden farklı olarak, istek nesnesinin yaratılması sırasında sipariş bölümü oluşturulurken puan bilgisinin eklenmesi ile gerçekleşir. 3 | 4 | ```php 5 | ... 6 | ->buildOrder('ORDERNO123456', '127.0.0.1', 3, 'TRY', 10.50) 7 | ... 8 | ``` 9 | 10 | veya 11 | 12 | 13 | ```php 14 | $order = new Order(); 15 | $order->setLoyaltyAmount(10.50) 16 | ... 17 | ``` 18 | 19 | Puan sorgulama işlemini incelemek için [buraya tıklayınız.](/docs/puan_sorgulama.md) 20 | 21 | ## Banka listesi ve puan ile ödeme seçenekleri 22 | 23 | | Banka Adı | Puan ile Ödeme | Nakit + Puan ile ödeme | Puan İadesi | 24 | |------------|:-------------------:|:-----------------------:|:------------------:| 25 | |Yapı Kredi | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | 26 | |Garanti | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | 27 | |Akbank | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | 28 | |Finansbank | :heavy_check_mark: | * Uygun Değil | :heavy_check_mark: | 29 | |İş Bankası | :heavy_check_mark: | * Uygun Değil | :heavy_check_mark: | 30 | |Denizbank | :heavy_check_mark: | * Uygun Değil | :heavy_check_mark: | 31 | |Halkbank | :heavy_check_mark: | * Uygun Değil | :heavy_check_mark: | 32 | |HSBC | :heavy_check_mark: | * Uygun Değil | :heavy_check_mark: | 33 | 34 | * Belirtilen bankaların uygulamaları sebebiyle, Nakit+Puanla Ödeme özelliği kullanılamamaktadır. 35 | 36 | ![PayU Bankalar](http://www.payu.com.tr/sites/turkey/files/pictures/bankalar2.png "PayU Bankalar") 37 | 38 | ## Kaynaklar 39 | - [http://www.payu.com.tr/katma-degerli-servisler/puan-kullanimi](http://www.payu.com.tr/katma-degerli-servisler/puan-kullanimi) 40 | - [https://secure.payu.com.tr/docs/loyalty-points](https://secure.payu.com.tr/docs/loyalty-points/) 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/Payu/Parser/PaymentResponseParser.php: -------------------------------------------------------------------------------- 1 | STATUS; 28 | $code = (string) $xml->RETURN_CODE; 29 | $message = (string) $xml->RETURN_MESSAGE; 30 | $statusCode = $this->parseStatusCode($status, $code); 31 | $transactionId = $this->parseTransactionId($xml->REFNO, $statusCode); 32 | $hash = isset($xml->HASH) ? (string) $xml->HASH : null; 33 | $url3DS = isset($xml->URL_3DS) ? (string) $xml->URL_3DS : null; 34 | 35 | return new PaymentResponse($statusCode, $code, $message, $transactionId, $hash, $url3DS); 36 | } 37 | 38 | private function parseStatusCode($status, $code) 39 | { 40 | $statusCode = $status; 41 | 42 | if ($status == 'SUCCESS' && in_array($code, ResponseAbstract::getStatusCodeList())) { 43 | $statusCode = $code; 44 | } 45 | 46 | return $statusCode; 47 | } 48 | 49 | private function parseTransactionId($refNo, $statusCode) 50 | { 51 | return in_array($statusCode, array(ResponseAbstract::STATUS_APPROVED, ResponseAbstract::STATUS_UNAUTHORIZED)) ? 52 | (string) $refNo : null; 53 | } 54 | } -------------------------------------------------------------------------------- /src/Payu/Response/ResponseAbstract.php: -------------------------------------------------------------------------------- 1 | code = $code; 31 | return $this; 32 | } 33 | 34 | /** 35 | * @return string 36 | */ 37 | public function getCode() 38 | { 39 | return $this->code; 40 | } 41 | 42 | /** 43 | * @param string $message 44 | * @return $this 45 | */ 46 | public function setMessage($message) 47 | { 48 | $this->message = $message; 49 | return $this; 50 | } 51 | 52 | /** 53 | * @return string 54 | */ 55 | public function getMessage() 56 | { 57 | return $this->message; 58 | } 59 | 60 | /** 61 | * @param int $status 62 | * @return $this 63 | */ 64 | public function setStatus($status) 65 | { 66 | $this->status = $status; 67 | return $this; 68 | } 69 | 70 | /** 71 | * @return int 72 | */ 73 | public function getStatus() 74 | { 75 | return $this->status; 76 | } 77 | 78 | /** 79 | * @return array 80 | */ 81 | public static function getStatusCodeList() 82 | { 83 | return array( 84 | self::STATUS_APPROVED, 85 | self::STATUS_UNAUTHORIZED 86 | ); 87 | } 88 | 89 | /** 90 | * @param integer $status 91 | * @param string $code 92 | * @param string $message 93 | */ 94 | public function __construct($status, $code, $message) 95 | { 96 | $this->setStatus($status); 97 | $this->setCode($code); 98 | $this->setMessage($message); 99 | } 100 | } -------------------------------------------------------------------------------- /src/Payu/Validator/Validator/CardValidator.php: -------------------------------------------------------------------------------- 1 | request->getCard(); 19 | if(!$object || !$object instanceof Card) { 20 | throw new ValidationError('Card number does not be empty.'); 21 | } 22 | } 23 | 24 | /** 25 | * @return void 26 | * @throws \Payu\Exception\ValidationError 27 | */ 28 | private function validateLuhn() 29 | { 30 | /** 31 | * @var $card \Payu\Component\Card 32 | */ 33 | $card = $this->request->getCard(); 34 | 35 | $sum = 0; 36 | $weight = 2; 37 | $number = $card->getNumber(); 38 | $length = strlen($number); 39 | 40 | for($i = $length -2; $i >= 0; $i--) { 41 | $digit = $weight * $number[$i]; 42 | $sum += floor($digit / 10) + $digit % 10; 43 | $weight = $weight % 2 + 1; 44 | } 45 | 46 | if ((10 - $sum % 10) % 10 != $number[$length - 1]) { 47 | throw new ValidationError('Bad card number.'); 48 | } 49 | } 50 | 51 | private function validateExpireDate() 52 | { 53 | /** 54 | * @var $card \Payu\Component\Card 55 | */ 56 | $card = $this->request->getCard(); 57 | $cardExpireTime = strtotime( 58 | date('Y-m-t', strtotime(sprintf('%d-%02d-1', $card->getYear(), $card->getMonth())) 59 | )); 60 | 61 | if(strtotime(date('Y-m-d')) > $cardExpireTime) { 62 | throw new ValidationError('Card is expired'); 63 | } 64 | 65 | 66 | 67 | } 68 | 69 | /** 70 | * @return void 71 | * @throws \Payu\Exception\ValidationError 72 | */ 73 | public function validate() 74 | { 75 | parent::validate(); 76 | $this->validateLuhn(); 77 | $this->validateExpireDate(); 78 | } 79 | } -------------------------------------------------------------------------------- /tests/ClientTest.php: -------------------------------------------------------------------------------- 1 | setMerchantId('MY_MERCHANT_01') 25 | ->setSecretKey('SECRET_KEY') 26 | ->setPaymentEndpointUrl('https://secure.payu.com.tr/order/alu/v3') 27 | ->setLoyaltyInquiryEndPointUrl('https://secure.payu.com.tr/api/loyalty-points/check'); 28 | $this->configuration = $configuration; 29 | $this->client = new Client($configuration); 30 | } 31 | 32 | public function testCreatePaymentRequestBuilder() 33 | { 34 | $this->assertTrue($this->client->createPaymentRequestBuilder() instanceof PaymentRequestBuilder); 35 | } 36 | 37 | public function testCreateLoyaltyInquiryRequestBuilder() 38 | { 39 | $this->assertTrue($this->client->createLoyaltyInquiryRequestBuilder() instanceof LoyaltyInquiryRequestBuilder); 40 | } 41 | 42 | public function testMakePayment() 43 | { 44 | $request = $this->client->createPaymentRequestBuilder() 45 | ->buildCard('4282209027132016', '123', 5, 2019) 46 | ->buildOrder('ORDERNO123456', '127.0.0.1') 47 | ->buildBilling('John', 'Smith', 'test@test.net', '05321231212') 48 | ->buildAndAddProduct('The Product', 'PR1', 1, 10) 49 | ->build(); 50 | $result = $this->client->makePayment($request); 51 | $this->assertTrue($result instanceof PaymentResponse); 52 | } 53 | 54 | public function testMakeLoyaltyInquiry() 55 | { 56 | $request = $this->client->createLoyaltyInquiryRequestBuilder() 57 | ->buildCard('4282209027132016', '123', '5', '2019') 58 | ->buildCurrency('TRY') 59 | ->build(); 60 | $result = $this->client->makeLoyaltyInquiry($request); 61 | $this->assertTrue($result instanceof LoyaltyInquiryResponse); 62 | } 63 | } -------------------------------------------------------------------------------- /src/Payu/Component/Card.php: -------------------------------------------------------------------------------- 1 | cvv = $cvv; 38 | return $this; 39 | } 40 | 41 | /** 42 | * @return int 43 | */ 44 | public function getCvv() 45 | { 46 | return $this->cvv; 47 | } 48 | 49 | /** 50 | * @param int $month 51 | * @return $this 52 | */ 53 | public function setMonth($month) 54 | { 55 | $this->month = $month; 56 | return $this; 57 | } 58 | 59 | /** 60 | * @return int 61 | */ 62 | public function getMonth() 63 | { 64 | return $this->month; 65 | } 66 | 67 | /** 68 | * @param string $number 69 | * @return $this 70 | */ 71 | public function setNumber($number) 72 | { 73 | $this->number = $number; 74 | return $this; 75 | } 76 | 77 | /** 78 | * @return string 79 | */ 80 | public function getNumber() 81 | { 82 | return $this->number; 83 | } 84 | 85 | /** 86 | * @param int $year 87 | * @return $this 88 | */ 89 | public function setYear($year) 90 | { 91 | $this->year = $year; 92 | return $this; 93 | } 94 | 95 | /** 96 | * @return int 97 | */ 98 | public function getYear() 99 | { 100 | return $this->year; 101 | } 102 | 103 | 104 | /** 105 | * @param string $owner 106 | * @return $this 107 | */ 108 | public function setOwner($owner) 109 | { 110 | $this->owner = $owner; 111 | return $this; 112 | } 113 | 114 | /** 115 | * @return string 116 | */ 117 | public function getOwner() 118 | { 119 | return $this->owner; 120 | } 121 | 122 | /** 123 | * @param string $number 124 | * @param integer $cvv 125 | * @param integer $month 126 | * @param integer $year 127 | * @param integer $owner 128 | */ 129 | public function __construct($number = null, $cvv = null, $month = null, $year = null, $owner = null) 130 | { 131 | $this->setNumber($number); 132 | $this->setCvv($cvv); 133 | $this->setMonth($month); 134 | $this->setYear($year); 135 | $this->setOwner($owner); 136 | } 137 | } -------------------------------------------------------------------------------- /src/Payu/Client.php: -------------------------------------------------------------------------------- 1 | configuration = $configuration; 30 | } 31 | 32 | /** 33 | * @return PaymentRequestBuilder 34 | */ 35 | public function createPaymentRequestBuilder() 36 | { 37 | return new PaymentRequestBuilder($this->configuration); 38 | } 39 | 40 | /** 41 | * @return LoyaltyInquiryRequestBuilder 42 | */ 43 | public function createLoyaltyInquiryRequestBuilder() 44 | { 45 | return new LoyaltyInquiryRequestBuilder($this->configuration); 46 | } 47 | 48 | /** 49 | * @param RequestAbstract $request 50 | * @param string $endpointUrl 51 | * @return \Guzzle\Http\EntityBodyInterface|string 52 | * @throws Exception\ConnectionError 53 | */ 54 | private function sendRequest(RequestAbstract $request, $endpointUrl) 55 | { 56 | $client = new HttpClient(); 57 | $client->setConfig(array( 58 | 'curl.options' => array( 59 | CURLOPT_SSL_VERIFYPEER => false, 60 | CURLOPT_SSL_VERIFYHOST => false, 61 | ) 62 | )); 63 | $httpRequest = $client->post($endpointUrl, null, $request->getRawData()); 64 | try { 65 | return $httpRequest->send()->getBody(); 66 | } catch(RequestException $e) { 67 | throw new ConnectionError($e->getMessage()); 68 | } 69 | } 70 | 71 | /** 72 | * @param PaymentRequest $request 73 | * @return Response\PaymentResponse 74 | */ 75 | public function makePayment(PaymentRequest $request) 76 | { 77 | $rawResponse = $this->sendRequest($request, $this->configuration->getPaymentEndpointUrl()); 78 | $parser = new ResponseParser(new PaymentResponseParser(), $rawResponse); 79 | return $parser->parse(); 80 | } 81 | 82 | /** 83 | * @param LoyaltyInquiryRequest $request 84 | * @return Response\LoyaltyInquiryResponse 85 | */ 86 | public function makeLoyaltyInquiry(LoyaltyInquiryRequest $request) 87 | { 88 | $rawResponse = $this->sendRequest($request, $this->configuration->getLoyaltyInquiryEndPointUrl()); 89 | $parser = new ResponseParser(new LoyaltyInquiryResponseParser(), $rawResponse); 90 | return $parser->parse(); 91 | } 92 | } -------------------------------------------------------------------------------- /src/Payu/Request/PaymentRequest.php: -------------------------------------------------------------------------------- 1 | basket = $basket; 38 | return $this; 39 | } 40 | 41 | /** 42 | * @return \Payu\Component\Basket 43 | */ 44 | public function getBasket() 45 | { 46 | return $this->basket; 47 | } 48 | 49 | /** 50 | * @param \Payu\Component\Billing $billing 51 | * @return $this 52 | */ 53 | public function setBilling($billing) 54 | { 55 | $this->billing = $billing; 56 | return $this; 57 | } 58 | 59 | /** 60 | * @return \Payu\Component\Billing 61 | */ 62 | public function getBilling() 63 | { 64 | return $this->billing; 65 | } 66 | 67 | /** 68 | * @param \Payu\Component\Card $card 69 | * @return $this 70 | */ 71 | public function setCard($card) 72 | { 73 | $this->card = $card; 74 | return $this; 75 | } 76 | 77 | /** 78 | * @return \Payu\Component\Card 79 | */ 80 | public function getCard() 81 | { 82 | return $this->card; 83 | } 84 | 85 | /** 86 | * @param \Payu\Component\Delivery $delivery 87 | * @return $this 88 | */ 89 | public function setDelivery($delivery) 90 | { 91 | $this->delivery = $delivery; 92 | return $this; 93 | } 94 | 95 | /** 96 | * @return \Payu\Component\Delivery 97 | */ 98 | public function getDelivery() 99 | { 100 | return $this->delivery; 101 | } 102 | 103 | /** 104 | * @param \Payu\Component\Order $order 105 | * @return $this 106 | */ 107 | public function setOrder($order) 108 | { 109 | $this->order = $order; 110 | return $this; 111 | } 112 | 113 | /** 114 | * @return \Payu\Component\Order 115 | */ 116 | public function getOrder() 117 | { 118 | return $this->order; 119 | } 120 | 121 | public function __construct($card = null, $order = null, $billing = null, $delivery = null, $basket = null) 122 | { 123 | $this->setCard($card); 124 | $this->setOrder($order); 125 | $this->setBilling($billing); 126 | $this->setDelivery($delivery); 127 | $this->setBasket($basket); 128 | } 129 | } -------------------------------------------------------------------------------- /src/Payu/Configuration.php: -------------------------------------------------------------------------------- 1 | merchantId = $merchantId; 35 | $this->secretKey = $secretKey; 36 | $this->paymentEndpointUrl = $paymentEndpointUrl; 37 | $this->loyaltyInquiryEndPointUrl = $loyaltyInquiryEndPointUrl; 38 | $this->paymentReturnPointUrl = $paymentReturnPointUrl; 39 | } 40 | 41 | /** 42 | * @param string $loyaltyInquiryEndPointUrl 43 | * @return $this 44 | */ 45 | public function setLoyaltyInquiryEndPointUrl($loyaltyInquiryEndPointUrl) 46 | { 47 | $this->loyaltyInquiryEndPointUrl = $loyaltyInquiryEndPointUrl; 48 | return $this; 49 | } 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function getLoyaltyInquiryEndPointUrl() 55 | { 56 | return $this->loyaltyInquiryEndPointUrl; 57 | } 58 | 59 | /** 60 | * @param string $merchantId 61 | * @return $this 62 | */ 63 | public function setMerchantId($merchantId) 64 | { 65 | $this->merchantId = $merchantId; 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return string 71 | */ 72 | public function getMerchantId() 73 | { 74 | return $this->merchantId; 75 | } 76 | 77 | /** 78 | * @param string $paymentEndpointUrl 79 | * @return $this 80 | */ 81 | public function setPaymentEndpointUrl($paymentEndpointUrl) 82 | { 83 | $this->paymentEndpointUrl = $paymentEndpointUrl; 84 | return $this; 85 | } 86 | 87 | /** 88 | * @return string 89 | */ 90 | public function getPaymentEndpointUrl() 91 | { 92 | return $this->paymentEndpointUrl; 93 | } 94 | 95 | /** 96 | * @param string $secretKey 97 | * @return $this 98 | */ 99 | public function setSecretKey($secretKey) 100 | { 101 | $this->secretKey = $secretKey; 102 | return $this; 103 | } 104 | 105 | /** 106 | * @return string 107 | */ 108 | public function getSecretKey() 109 | { 110 | return $this->secretKey; 111 | } 112 | 113 | /** 114 | * @return string 115 | */ 116 | public function getPaymentReturnPointUrl() 117 | { 118 | return $this->paymentReturnPointUrl; 119 | } 120 | 121 | /** 122 | * @param string $paymentReturnPointUrl 123 | */ 124 | public function setPaymentReturnPointUrl($paymentReturnPointUrl) 125 | { 126 | $this->paymentReturnPointUrl = $paymentReturnPointUrl; 127 | } 128 | } -------------------------------------------------------------------------------- /src/Payu/Component/Basket.php: -------------------------------------------------------------------------------- 1 | collection = array(); 14 | } 15 | 16 | /** 17 | * Add new product to basket 18 | * 19 | * @param Product $product 20 | */ 21 | public function add(Product $product) 22 | { 23 | $this->collection[$product->getCode()] = $product; 24 | } 25 | 26 | /** 27 | * Remove product from basket with code 28 | * 29 | * @param string $code 30 | */ 31 | public function remove($code) 32 | { 33 | unset($this->collection[$code]); 34 | } 35 | 36 | /** 37 | * (PHP 5 >= 5.0.0)
38 | * Return the current element 39 | * @link http://php.net/manual/en/iterator.current.php 40 | * @return mixed Can return any type. 41 | */ 42 | public function current() 43 | { 44 | return current($this->collection); 45 | } 46 | 47 | /** 48 | * (PHP 5 >= 5.0.0)
49 | * Move forward to next element 50 | * @link http://php.net/manual/en/iterator.next.php 51 | * @return void Any returned value is ignored. 52 | */ 53 | public function next() 54 | { 55 | return next($this->collection); 56 | } 57 | 58 | /** 59 | * (PHP 5 >= 5.0.0)
60 | * Return the key of the current element 61 | * @link http://php.net/manual/en/iterator.key.php 62 | * @return mixed scalar on success, or null on failure. 63 | */ 64 | public function key() 65 | { 66 | return key($this->collection); 67 | } 68 | 69 | /** 70 | * (PHP 5 >= 5.0.0)
71 | * Checks if current position is valid 72 | * @link http://php.net/manual/en/iterator.valid.php 73 | * @return boolean The return value will be casted to boolean and then evaluated. 74 | * Returns true on success or false on failure. 75 | */ 76 | public function valid() 77 | { 78 | return isset($this->collection[$this->key()]); 79 | } 80 | 81 | /** 82 | * (PHP 5 >= 5.0.0)
83 | * Rewind the Iterator to the first element 84 | * @link http://php.net/manual/en/iterator.rewind.php 85 | * @return void Any returned value is ignored. 86 | */ 87 | public function rewind() 88 | { 89 | return reset($this->collection); 90 | } 91 | 92 | /** 93 | * (PHP 5 >= 5.1.0)
94 | * Count elements of an object 95 | * @link http://php.net/manual/en/countable.count.php 96 | * @return int The custom count as an integer. 97 | *

98 | *

99 | * The return value is cast to an integer. 100 | */ 101 | public function count() 102 | { 103 | return count($this->collection); 104 | } 105 | 106 | /** 107 | * Return Total Price of Basket 108 | * 109 | * @return double 110 | */ 111 | public function getTotalPrice() 112 | { 113 | $sum = 0.0; 114 | /** @var $product \Payu\Component\Product */ 115 | foreach ($this->collection as $product) { 116 | $sum += ((int) $product->getQuantity() * (float) $product->getPrice()); 117 | } 118 | 119 | return $sum; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /docs/puan_sorgulama.md: -------------------------------------------------------------------------------- 1 | # Puan Sorgulama İşlemi 2 | 3 | Puan sorgulama işlemi, kredi kartına ilişkin bilgilerle dolu bir istek nesnesinin istemci üzerinden servis sağlayıcıya iletilmesi şeklinde gerçekleştirilir. 4 | 5 | ## İstemcinin Hazırlanması 6 | 7 | ```php 8 | use Payu\Client; 9 | use Payu\Configuration; 10 | 11 | $configuration = new Configuration(); 12 | 13 | $configuration 14 | ->setMerchantId('MY_MERCHANT_01') 15 | ->setSecretKey('SECRET_KEY') 16 | ->setLoyaltyInquiryEndPointUrl('https://secure.payu.com.tr/api/loyalty-points/check'); 17 | ; 18 | 19 | $client = new Client($configuration); 20 | ``` 21 | 22 | ## Puan Sorgulama İsteğinin Oluşturulması 23 | Puan Sorgulama İsteği, *Client* nesnesi üstündeki kurucu metodlar vasıtasyıla veya isteği oluşturan bileşenlerin ayrı ayrı oluşturulması ile kolayca oluşturulabilir. 24 | 25 | Aşağıdaki kod örneği ödeme isteğini *Client* nesnesi üzerindeki kurucu metodlarla gerçekleştirmektedir. 26 | 27 | ```php 28 | 29 | /** @var $request \Payu\Request\LoyaltyInquiryRequest */ 30 | $client = new Client($configuration); 31 | $request = $client->createLoyaltyInquiryRequestBuilder() 32 | ->buildCard('4282209027132016', '123', '5', '2019') 33 | ->buildCurrency('TRY') 34 | ->build(); 35 | ``` 36 | 37 | Aşağıdaki örnek kod ise istek nesnesini, kendisini oluşturan bileşenlerin manuel olarak oluşturulması ile yaratmaktadır. 38 | 39 | ```php 40 | use Payu\Component\Card; 41 | 42 | $card = new Card(); 43 | $card->setNumber('4282209027132016') 44 | ->setCvv('123') 45 | ->setMonth(5) 46 | ->setYear(2019); 47 | 48 | $currency = new Currency(); 49 | $currency->setCode('TRY'); 50 | 51 | /** @var $request \Payu\Request\LoyaltyInquiryRequest */ 52 | $request = $client->createLoyaltyInquiryRequestBuilder() 53 | ->setCard($card) 54 | ->setCurrency($currency) 55 | ->build(); 56 | ``` 57 | 58 | ## Sorgulama İşleminin Gerçekleştirilmesi 59 | Sorgulama işlemi, client nesnesinin makeLoyaltyInquiry() metodunun çağırılması ile gerçekleştirilir. 60 | 61 | ```php 62 | $response = $client->makeLoyaltyInquiry($request) 63 | ``` 64 | 65 | ## İşlem Sonucunun Kontrol Edilmesi 66 | 67 | ```php 68 | if ($response->getStatus() == ResponseAbstract::STATUS_APPROVED) { 69 | // Puan sorgulama işlemi başarılı bir şekilde gerçekleşti 70 | print_r($response); 71 | } else { 72 | // Puan sorgulama işleminde bir hata oluştu. 73 | echo $response->getMessage(); 74 | } 75 | 76 | ``` 77 | 78 | Son olarak herşeyi bir araya getirelim. 79 | ```php 80 | 81 | 82 | use Payu\Client; 83 | use Payu\Configuration; 84 | use Payu\Component\Card; 85 | use Payu\Component\Currency; 86 | 87 | $configuration = new Configuration(); 88 | $configuration->setMerchantId('MY_MERCHANT_01') 89 | ->setSecretKey('SECRET_KEY') 90 | ->setLoyaltyInquiryEndPointUrl('https://secure.payu.com.tr/api/loyalty-points/check'); 91 | 92 | $client = new Client($configuration); 93 | $request = $client->createLoyaltyInquiryRequestBuilder() 94 | ->buildCard('4282209027132016', '123', '5', '2019') 95 | ->buildCurrency('TRY') 96 | ->build(); 97 | 98 | $curreny = new Currency(); 99 | $curreny->setCode('TRY'); 100 | 101 | $response = $client->makeLoyaltyInquiry($request); 102 | 103 | if ($response->getStatus() == ResponseAbstract::STATUS_APPROVED) { 104 | // Puan sorgulama işlemi başarılı bir şekilde gerçekleşti 105 | print_r($response); 106 | } else { 107 | // Puan sorgulama işleminde bir hata oluştu. 108 | echo $response->getMessage(); 109 | } 110 | ``` 111 | -------------------------------------------------------------------------------- /src/Payu/Component/Product.php: -------------------------------------------------------------------------------- 1 | setName($name); 54 | $this->setCode($code); 55 | $this->setQuantity($quantity); 56 | $this->setInfo($info); 57 | $this->setPrice($price); 58 | $this->setVersion($version); 59 | $this->setVat($vat); 60 | } 61 | 62 | 63 | /** 64 | * @param string $code 65 | * @return $this 66 | */ 67 | public function setCode($code) 68 | { 69 | $this->code = $code; 70 | 71 | return $this; 72 | } 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function getCode() 78 | { 79 | return $this->code; 80 | } 81 | 82 | /** 83 | * @param string $info 84 | * @return $this 85 | */ 86 | public function setInfo($info) 87 | { 88 | $this->info = $info; 89 | 90 | return $this; 91 | } 92 | 93 | /** 94 | * @return string 95 | */ 96 | public function getInfo() 97 | { 98 | return $this->info; 99 | } 100 | 101 | /** 102 | * @param string $name 103 | * @return $this 104 | */ 105 | public function setName($name) 106 | { 107 | $this->name = $name; 108 | 109 | return $this; 110 | } 111 | 112 | /** 113 | * @return string 114 | */ 115 | public function getName() 116 | { 117 | return $this->name; 118 | } 119 | 120 | /** 121 | * @param float $price 122 | * @return $this 123 | */ 124 | public function setPrice($price) 125 | { 126 | $this->price = $price; 127 | 128 | return $this; 129 | } 130 | 131 | /** 132 | * @return float 133 | */ 134 | public function getPrice() 135 | { 136 | return $this->price; 137 | } 138 | 139 | /** 140 | * @param integer $quantity 141 | * @return $this 142 | */ 143 | public function setQuantity($quantity) 144 | { 145 | $this->quantity = $quantity; 146 | 147 | return $this; 148 | } 149 | 150 | /** 151 | * @return integer 152 | */ 153 | public function getQuantity() 154 | { 155 | return $this->quantity; 156 | } 157 | 158 | /** 159 | * @param string $version 160 | * @return $this 161 | */ 162 | public function setVersion($version) 163 | { 164 | $this->version = $version; 165 | 166 | return $this; 167 | } 168 | 169 | /** 170 | * @return string 171 | */ 172 | public function getVersion() 173 | { 174 | return $this->version; 175 | } 176 | 177 | /** 178 | * Gets the value of vat. 179 | * 180 | * @return integer 181 | */ 182 | public function getVat() 183 | { 184 | return $this->vat; 185 | } 186 | 187 | /** 188 | * Sets the value of vat. 189 | * 190 | * @param integer $vat 191 | * 192 | * @return self 193 | */ 194 | public function setVat($vat) 195 | { 196 | $this->vat = $vat; 197 | 198 | return $this; 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /src/Payu/Serializer/PaymentRequestSerializer.php: -------------------------------------------------------------------------------- 1 | request->getOrder(); 18 | 19 | $data = array( 20 | 'ORDER_REF' => $order->getCode(), 21 | 'ORDER_DATE' => $order->getDate(), 22 | 'PAY_METHOD' => $order->getPaymentMethod(), 23 | 'PRICES_CURRENCY' => $order->getCurrency(), 24 | 'SELECTED_INSTALLMENTS_NUMBER' => $order->getInstallment(), 25 | 'ORDER_TIMEOUT' => $order->getTimeout(), 26 | 'BACK_REF' => $this->configuration->getPaymentReturnPointUrl(), 27 | 'CLIENT_IP' => $order->getClientIp() 28 | ); 29 | 30 | if ((float) $order->getLoyaltyAmount() != 0) { 31 | $data['USE_LOYALTY_POINTS'] = 'YES'; 32 | if ((float) $order->getLoyaltyAmount() != (float) $this->request->getBasket()->getTotalPrice()) { 33 | $data['LOYALTY_POINTS_AMOUNT'] = (float) $order->getLoyaltyAmount(); 34 | } 35 | } 36 | 37 | if ($order->isRecurringPayment() === true) { 38 | $data['LU_ENABLE_TOKEN'] = 1; 39 | } 40 | 41 | return $data; 42 | } 43 | 44 | /** 45 | * @return array 46 | */ 47 | private function serializeBilling() 48 | { 49 | /** @var $billing \Payu\Component\Billing */ 50 | $billing = $this->request->getBilling(); 51 | 52 | return array( 53 | 'BILL_LNAME' => $billing->getLastName(), 54 | 'BILL_FNAME' => $billing->getFirstName(), 55 | 'BILL_EMAIL' => $billing->getEmail(), 56 | 'BILL_PHONE' => $billing->getPhone(), 57 | 'BILL_COUNTRYCODE' => $billing->getCountryCode(), 58 | 'BILL_FAX' => $billing->getFax(), 59 | 'BILL_ADDRESS' => $billing->getAddress(), 60 | 'BILL_ZIPCODE' => $billing->getZipCode(), 61 | 'BILL_CITY' => $billing->getCity(), 62 | 'BILL_STATE' => $billing->getState() 63 | ); 64 | } 65 | 66 | /** 67 | * @return array 68 | */ 69 | private function serializeDelivery() 70 | { 71 | /** @var $delivery \Payu\Component\Delivery */ 72 | $delivery = $this->request->getDelivery(); 73 | if (!$delivery) { 74 | return array(); 75 | } 76 | 77 | return array( 78 | 'DELIVERY_FNAME' => $delivery->getFirstName(), 79 | 'DELIVERY_LNAME' => $delivery->getLastName(), 80 | 'DELIVERY_EMAIL' => $delivery->getEmail(), 81 | 'DELIVERY_PHONE' => $delivery->getPhone(), 82 | 'DELIVERY_COMPANY' => $delivery->getCompany(), 83 | 'DELIVERY_ADDRESS' => $delivery->getAddress(), 84 | 'DELIVERY_ZIPCODE' => $delivery->getZipCode(), 85 | 'DELIVERY_CITY' => $delivery->getCity(), 86 | 'DELIVERY_STATE' => $delivery->getState(), 87 | 'DELIVERY_COUNTRYCODE' => $delivery->getCountryCode() 88 | ); 89 | } 90 | 91 | /** 92 | * @return array 93 | */ 94 | private function serializeBasket() 95 | { 96 | $i = 0; 97 | $data = array(); 98 | /** @var $product \Payu\Component\Product */ 99 | foreach ($this->request->getBasket() as $product) { 100 | $data['ORDER_PNAME[' . $i . ']'] = $product->getName(); 101 | $data['ORDER_PCODE[' . $i . ']'] = $product->getCode(); 102 | $data['ORDER_PRICE[' . $i . ']'] = $product->getPrice(); 103 | $data['ORDER_QTY[' . $i . ']'] = $product->getQuantity(); 104 | $data['ORDER_PINFO[' . $i . ']'] = $product->getInfo(); 105 | $data['ORDER_VER[' . $i . ']'] = $product->getVersion(); 106 | $data['ORDER_VAT[' . $i . ']'] = $product->getVat();; 107 | $i++; 108 | } 109 | 110 | return $data; 111 | } 112 | 113 | /** 114 | * @return array 115 | */ 116 | public function serialize() 117 | { 118 | $concatenatedData = array_merge( 119 | $this->serializeCard(), 120 | $this->serializeOrder(), 121 | $this->serializeBilling(), 122 | $this->serializeDelivery(), 123 | $this->serializeBasket() 124 | ); 125 | 126 | $filteredData = array_filter($concatenatedData); 127 | $filteredData['MERCHANT'] = $this->configuration->getMerchantId(); 128 | $filteredData['ORDER_HASH'] = $this->calculateHash($filteredData); 129 | 130 | return $filteredData; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/Payu/Component/Billing.php: -------------------------------------------------------------------------------- 1 | address = $address; 63 | return $this; 64 | } 65 | 66 | /** 67 | * @return string 68 | */ 69 | public function getAddress() 70 | { 71 | return $this->address; 72 | } 73 | 74 | /** 75 | * @param string $city 76 | * @return $this 77 | */ 78 | public function setCity($city) 79 | { 80 | $this->city = $city; 81 | return $this; 82 | } 83 | 84 | /** 85 | * @return string 86 | */ 87 | public function getCity() 88 | { 89 | return $this->city; 90 | } 91 | 92 | /** 93 | * @param string $countryCode 94 | * @return $this 95 | */ 96 | public function setCountryCode($countryCode) 97 | { 98 | $this->countryCode = $countryCode; 99 | return $this; 100 | } 101 | 102 | /** 103 | * @return string 104 | */ 105 | public function getCountryCode() 106 | { 107 | return $this->countryCode; 108 | } 109 | 110 | /** 111 | * @param string $email 112 | * @return $this 113 | */ 114 | public function setEmail($email) 115 | { 116 | $this->email = $email; 117 | return $this; 118 | } 119 | 120 | /** 121 | * @return string 122 | */ 123 | public function getEmail() 124 | { 125 | return $this->email; 126 | } 127 | 128 | /** 129 | * @param string $fax 130 | * @return $this 131 | */ 132 | public function setFax($fax) 133 | { 134 | $this->fax = $fax; 135 | return $this; 136 | } 137 | 138 | /** 139 | * @return string 140 | */ 141 | public function getFax() 142 | { 143 | return $this->fax; 144 | } 145 | 146 | /** 147 | * @param string $firstName 148 | * @return $this 149 | */ 150 | public function setFirstName($firstName) 151 | { 152 | $this->firstName = $firstName; 153 | return $this; 154 | } 155 | 156 | /** 157 | * @return string 158 | */ 159 | public function getFirstName() 160 | { 161 | return $this->firstName; 162 | } 163 | 164 | /** 165 | * @param string $lastName 166 | * @return $this 167 | */ 168 | public function setLastName($lastName) 169 | { 170 | $this->lastName = $lastName; 171 | return $this; 172 | } 173 | 174 | /** 175 | * @return string 176 | */ 177 | public function getLastName() 178 | { 179 | return $this->lastName; 180 | } 181 | 182 | /** 183 | * @param string $phone 184 | * @return $this 185 | */ 186 | public function setPhone($phone) 187 | { 188 | $this->phone = $phone; 189 | return $this; 190 | } 191 | 192 | /** 193 | * @return string 194 | */ 195 | public function getPhone() 196 | { 197 | return $this->phone; 198 | } 199 | 200 | /** 201 | * @param string $state 202 | * @return $this 203 | */ 204 | public function setState($state) 205 | { 206 | $this->state = $state; 207 | return $this; 208 | } 209 | 210 | /** 211 | * @return string 212 | */ 213 | public function getState() 214 | { 215 | return $this->state; 216 | } 217 | 218 | /** 219 | * @param string $zipCode 220 | * @return $this 221 | */ 222 | public function setZipCode($zipCode) 223 | { 224 | $this->zipCode = $zipCode; 225 | return $this; 226 | } 227 | 228 | /** 229 | * @return string 230 | */ 231 | public function getZipCode() 232 | { 233 | return $this->zipCode; 234 | } 235 | 236 | public function __construct( 237 | $firstName = null, 238 | $lastName = null, 239 | $email = null, 240 | $phone = null, 241 | $fax = null, 242 | $address = null, 243 | $zipCode = null, 244 | $city = null, 245 | $state = null, 246 | $countryCode = 'TR' 247 | ) { 248 | $this->setFirstName($firstName); 249 | $this->setLastName($lastName); 250 | $this->setEmail($email); 251 | $this->setPhone($phone); 252 | $this->setFax($fax); 253 | $this->setAddress($address); 254 | $this->setZipCode($zipCode); 255 | $this->setCity($city); 256 | $this->setState($state); 257 | $this->setCountryCode($countryCode); 258 | } 259 | } -------------------------------------------------------------------------------- /src/Payu/Component/Delivery.php: -------------------------------------------------------------------------------- 1 | address = $address; 63 | return $this; 64 | } 65 | 66 | /** 67 | * @return string 68 | */ 69 | public function getAddress() 70 | { 71 | return $this->address; 72 | } 73 | 74 | /** 75 | * @param string $city 76 | * @return $this 77 | */ 78 | public function setCity($city) 79 | { 80 | $this->city = $city; 81 | return $this; 82 | } 83 | 84 | /** 85 | * @return string 86 | */ 87 | public function getCity() 88 | { 89 | return $this->city; 90 | } 91 | 92 | /** 93 | * @param string $company 94 | * @return $this 95 | */ 96 | public function setCompany($company) 97 | { 98 | $this->company = $company; 99 | return $this; 100 | } 101 | 102 | /** 103 | * @return string 104 | */ 105 | public function getCompany() 106 | { 107 | return $this->company; 108 | } 109 | 110 | /** 111 | * @param string $countryCode 112 | * @return $this 113 | */ 114 | public function setCountryCode($countryCode) 115 | { 116 | $this->countryCode = $countryCode; 117 | return $this; 118 | } 119 | 120 | /** 121 | * @return string 122 | */ 123 | public function getCountryCode() 124 | { 125 | return $this->countryCode; 126 | } 127 | 128 | /** 129 | * @param string $email 130 | * @return $this 131 | */ 132 | public function setEmail($email) 133 | { 134 | $this->email = $email; 135 | return $this; 136 | } 137 | 138 | /** 139 | * @return string 140 | */ 141 | public function getEmail() 142 | { 143 | return $this->email; 144 | } 145 | 146 | /** 147 | * @param string $firstName 148 | * @return $this 149 | */ 150 | public function setFirstName($firstName) 151 | { 152 | $this->firstName = $firstName; 153 | return $this; 154 | } 155 | 156 | /** 157 | * @return string 158 | */ 159 | public function getFirstName() 160 | { 161 | return $this->firstName; 162 | } 163 | 164 | /** 165 | * @param string $lastName 166 | * @return $this 167 | */ 168 | public function setLastName($lastName) 169 | { 170 | $this->lastName = $lastName; 171 | return $this; 172 | } 173 | 174 | /** 175 | * @return string 176 | */ 177 | public function getLastName() 178 | { 179 | return $this->lastName; 180 | } 181 | 182 | /** 183 | * @param string $phone 184 | * @return $this 185 | */ 186 | public function setPhone($phone) 187 | { 188 | $this->phone = $phone; 189 | return $this; 190 | } 191 | 192 | /** 193 | * @return string 194 | */ 195 | public function getPhone() 196 | { 197 | return $this->phone; 198 | } 199 | 200 | /** 201 | * @param string $state 202 | * @return $this 203 | */ 204 | public function setState($state) 205 | { 206 | $this->state = $state; 207 | return $this; 208 | } 209 | 210 | /** 211 | * @return string 212 | */ 213 | public function getState() 214 | { 215 | return $this->state; 216 | } 217 | 218 | /** 219 | * @param string $zipCode 220 | * @return $this 221 | */ 222 | public function setZipCode($zipCode) 223 | { 224 | $this->zipCode = $zipCode; 225 | return $this; 226 | } 227 | 228 | /** 229 | * @return string 230 | */ 231 | public function getZipCode() 232 | { 233 | return $this->zipCode; 234 | } 235 | 236 | public function __construct( 237 | $firstName = null, 238 | $lastName = null, 239 | $email = null, 240 | $phone = null, 241 | $company = null, 242 | $address = null, 243 | $zipCode = null, 244 | $city = null, 245 | $state = null, 246 | $countryCode = null 247 | ) { 248 | $this->setFirstName($firstName); 249 | $this->setLastName($lastName); 250 | $this->setEmail($email); 251 | $this->setPhone($phone); 252 | $this->setCompany($company); 253 | $this->setAddress($address); 254 | $this->setZipCode($zipCode); 255 | $this->setCity($city); 256 | $this->setState($state); 257 | $this->setCountryCode($countryCode); 258 | } 259 | } -------------------------------------------------------------------------------- /src/Payu/Component/Order.php: -------------------------------------------------------------------------------- 1 | setCode($code); 64 | $this->setClientIp($clientIp); 65 | $this->setInstallment($installment); 66 | $this->setCurrency($currency); 67 | $this->setLoyaltyAmount($loyaltyAmount); 68 | $this->setPaymentMethod($paymentMethod); 69 | $this->setDate($date); 70 | $this->setTimeout($timeout); 71 | $this->setRecurringPayment($recurringPayment); 72 | } 73 | 74 | /** 75 | * @param string $clientIp 76 | * @return $this 77 | */ 78 | public function setClientIp($clientIp) 79 | { 80 | $this->clientIp = $clientIp; 81 | 82 | return $this; 83 | } 84 | 85 | /** 86 | * @return string 87 | */ 88 | public function getClientIp() 89 | { 90 | return $this->clientIp; 91 | } 92 | 93 | /** 94 | * @param string $code 95 | * @return $this 96 | */ 97 | public function setCode($code) 98 | { 99 | $this->code = $code; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * @return string 106 | */ 107 | public function getCode() 108 | { 109 | return $this->code; 110 | } 111 | 112 | /** 113 | * @param string $currency 114 | * @return $this 115 | */ 116 | public function setCurrency($currency) 117 | { 118 | $this->currency = $currency; 119 | 120 | return $this; 121 | } 122 | 123 | /** 124 | * @return string 125 | */ 126 | public function getCurrency() 127 | { 128 | return $this->currency; 129 | } 130 | 131 | /** 132 | * @param string $date 133 | * @return $this 134 | */ 135 | public function setDate($date) 136 | { 137 | $this->date = $date != null ? $date : gmdate('Y-m-d H:i:s'); 138 | 139 | return $this; 140 | } 141 | 142 | /** 143 | * @return string 144 | */ 145 | public function getDate() 146 | { 147 | return $this->date; 148 | } 149 | 150 | /** 151 | * @param int $installment 152 | * @return $this 153 | */ 154 | public function setInstallment($installment) 155 | { 156 | $this->installment = $installment; 157 | 158 | return $this; 159 | } 160 | 161 | /** 162 | * @return int 163 | */ 164 | public function getInstallment() 165 | { 166 | return $this->installment; 167 | } 168 | 169 | /** 170 | * @param float $loyaltyAmount 171 | * @return $this 172 | */ 173 | public function setLoyaltyAmount($loyaltyAmount) 174 | { 175 | $this->loyaltyAmount = $loyaltyAmount; 176 | 177 | return $this; 178 | } 179 | 180 | /** 181 | * @return float 182 | */ 183 | public function getLoyaltyAmount() 184 | { 185 | return $this->loyaltyAmount; 186 | } 187 | 188 | /** 189 | * @param string $paymentMethod 190 | * @return $this 191 | */ 192 | public function setPaymentMethod($paymentMethod) 193 | { 194 | $this->paymentMethod = $paymentMethod; 195 | 196 | return $this; 197 | } 198 | 199 | /** 200 | * @return string 201 | */ 202 | public function getPaymentMethod() 203 | { 204 | return $this->paymentMethod; 205 | } 206 | 207 | /** 208 | * @param int $timeout 209 | * @return $this 210 | */ 211 | public function setTimeout($timeout) 212 | { 213 | $this->timeout = $timeout; 214 | 215 | return $this; 216 | } 217 | 218 | /** 219 | * @return int 220 | */ 221 | public function getTimeout() 222 | { 223 | return $this->timeout; 224 | } 225 | 226 | 227 | /** 228 | * Gets the value of recurringPayment. 229 | * 230 | * @return bool 231 | */ 232 | public function isRecurringPayment() 233 | { 234 | return $this->recurringPayment; 235 | } 236 | 237 | /** 238 | * Sets the value of recurringPayment. 239 | * 240 | * @param bool $recurringPayment the recurring payment 241 | * 242 | * @return self 243 | */ 244 | public function setRecurringPayment($recurringPayment) 245 | { 246 | $this->recurringPayment = (bool)$recurringPayment; 247 | 248 | return $this; 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /src/Payu/Builder/PaymentRequestBuilder.php: -------------------------------------------------------------------------------- 1 | order = new Order( 59 | $code, 60 | $clientIp, 61 | $installment, 62 | $currency, 63 | $loyaltyAmount, 64 | $paymentMethod, 65 | $date, 66 | $timeout, 67 | $recurringPayment 68 | ); 69 | return $this; 70 | } 71 | 72 | /** 73 | * @param Order $order 74 | * @return $this 75 | */ 76 | public function setOrder(Order $order) 77 | { 78 | $this->order = $order; 79 | return $this; 80 | } 81 | 82 | /** 83 | * @param null $firstName 84 | * @param null $lastName 85 | * @param null $email 86 | * @param null $phone 87 | * @param null $fax 88 | * @param null $address 89 | * @param null $zipCode 90 | * @param null $city 91 | * @param null $state 92 | * @param null $countryCode 93 | * @return $this 94 | */ 95 | public function buildBilling( 96 | $firstName = null, 97 | $lastName = null, 98 | $email = null, 99 | $phone = null, 100 | $fax = null, 101 | $address = null, 102 | $zipCode = null, 103 | $city = null, 104 | $state = null, 105 | $countryCode = null 106 | ) 107 | { 108 | $this->billing = new Billing( 109 | $firstName, 110 | $lastName, 111 | $email, 112 | $phone, 113 | $fax, 114 | $address, 115 | $zipCode, 116 | $city, 117 | $state, 118 | $countryCode 119 | ); 120 | return $this; 121 | } 122 | 123 | /** 124 | * @param Billing $billing 125 | * @return $this 126 | */ 127 | public function setBilling(Billing $billing) 128 | { 129 | $this->billing = $billing; 130 | return $this; 131 | } 132 | 133 | /** 134 | * @param null $firstName 135 | * @param null $lastName 136 | * @param null $email 137 | * @param null $phone 138 | * @param null $company 139 | * @param null $address 140 | * @param null $zipCode 141 | * @param null $city 142 | * @param null $state 143 | * @param null $countryCode 144 | * @return $this 145 | */ 146 | public function buildDeliverys( 147 | $firstName = null, 148 | $lastName = null, 149 | $email = null, 150 | $phone = null, 151 | $company = null, 152 | $address = null, 153 | $zipCode = null, 154 | $city = null, 155 | $state = null, 156 | $countryCode = null 157 | ) 158 | { 159 | $this->delivery = new Delivery( 160 | $firstName, 161 | $lastName, 162 | $email, 163 | $phone, 164 | $company, 165 | $address, 166 | $zipCode, 167 | $city, 168 | $state, 169 | $countryCode 170 | ); 171 | return $this; 172 | } 173 | 174 | /** 175 | * @param Delivery $delivery 176 | * @return $this 177 | */ 178 | public function setDelivery(Delivery $delivery) 179 | { 180 | $this->delivery = $delivery; 181 | return $this; 182 | } 183 | 184 | /** 185 | * @param null $name 186 | * @param null $code 187 | * @param null $quantity 188 | * @param null $info 189 | * @param null $price 190 | * @param null $version 191 | * @return $this 192 | */ 193 | public function buildAndAddProduct( 194 | $name = null, 195 | $code = null, 196 | $quantity = null, 197 | $info = null, 198 | $price = null, 199 | $version = null, 200 | $vat = null 201 | ) { 202 | 203 | $this->basket->add(new Product($name, $code, $quantity, $info, $price, $version, $vat)); 204 | return $this; 205 | } 206 | 207 | /** 208 | * @param Product $product 209 | * @return $this 210 | */ 211 | public function addProduct(Product $product) 212 | { 213 | $this->basket->add($product); 214 | return $this; 215 | } 216 | 217 | public function __construct(Configuration $configuration) 218 | { 219 | parent::__construct($configuration); 220 | $this->basket = new Basket(); 221 | } 222 | 223 | public function build() 224 | { 225 | $request = new PaymentRequest($this->card, $this->order, $this->billing, $this->delivery, $this->basket); 226 | 227 | $validator = new PaymentRequestValidator($request); 228 | $validator->validate(); 229 | 230 | $serializer = new PaymentRequestSerializer($request, $this->configuration); 231 | $rawData = $serializer->serialize(); 232 | 233 | $request->setRawData($rawData); 234 | 235 | return $request; 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /docs/satis.md: -------------------------------------------------------------------------------- 1 | # Satış 2 | 3 | Satılan mal ya da hizmet karşılığında kullanıcının ödeme aracından (Kredi kartı vb.) para tahsilatı yapmak için gerçekleştirilen işlemdir. PayuClient ile satış işlemini gerçekleştirmek için aşağıdaki yönergeleri takip edebilirsiniz. 4 | 5 | ## Konfigürasyon ve İstemciyi Hazırlamak 6 | 7 | PayuClient kullanarak satış işlemi gerçekleştirmek için, payu tarafından sağlanan erişim bilgilerinin kütüphaneye bildirilmesini sağlayacak **Payu\Configuration** tipinde bir nesne oluşturarak istemciye kurulum sırasında argüman olarak göndermelisiniz. 8 | 9 | ```php 10 | use Payu\Client; 11 | use Payu\Configuration; 12 | 13 | $configuration = new Configuration(); 14 | 15 | $configuration->setMerchantId('MY_MERCHANT_01') 16 | ->setSecretKey('SECRET_KEY') 17 | ->setPaymentEndpointUrl('https://secure.payu.com.tr/order/alu/v3'); 18 | 19 | $client = new Client($configuration); 20 | ``` 21 | 22 | ## Satış İsteği Oluşturma 23 | 24 | İstek oluşturma işlemini gerçekleştirmeki için kütüphane ile sağlanan kurucu metodları kullanabilirsiniz. Kurucu metodlar, istekle ilgil bileşenleri doğrudan veya yardımcı kurucu metodlarla alabilirler. 25 | 26 | ### Yardımcı Kurucu Metodlarla Satış İsteğinin Oluşturması 27 | 28 | ```php 29 | /** @var $request \Payu\Request\PaymentRequest */ 30 | $request = $client->createPaymentRequestBuilder() 31 | ->buildCard('4282209027132016', '123', 5, 2019) 32 | ->buildOrder('ORDERNO123456', '127.0.0.1') 33 | ->buildBilling('John', 'Smith', 'test@test.net', '05321231212') 34 | ->buildAndAddProduct('The Product', 'PR1', 1, 10) 35 | ->build(); 36 | ``` 37 | 38 | ### Bileşenlerle Satış İsteğinin Oluşturulması 39 | 40 | ```php 41 | use Payu\Component\Card; 42 | use Payu\Component\Order; 43 | use Payu\Component\Billing; 44 | use Payu\Component\Product; 45 | 46 | $card = new Card(); 47 | $card->setNumber('4282209027132016') 48 | ->setCvv('123') 49 | ->setMonth(5) 50 | ->setYear(2019); 51 | 52 | $order = new Order(); 53 | $order->setCode('ORDERNO123456') 54 | ->setClientIp('127.0.0.1'); 55 | 56 | $billing = new Billing(); 57 | $billing->setFirstName('John') 58 | ->setLastName('Smith') 59 | ->setPhone('05321231212') 60 | ->setEmail('test@test.net'); 61 | 62 | 63 | $product = new Product(); 64 | $product->setCode('PR1') 65 | ->setName('The Product') 66 | ->setQuantity(1) 67 | ->setPrice(10); 68 | 69 | /** @var $request \Payu\Request\PaymentRequest */ 70 | $request = $client->createPaymentRequestBuilder() 71 | ->setCard($card) 72 | ->setOrder($order) 73 | ->setBilling($billing) 74 | ->addProduct($product) 75 | ->build(); 76 | ``` 77 | 78 | ## Satış İşleminin Gerçekleştirilmesi 79 | 80 | ```php 81 | /** 82 | * @var $request \Payu\Request\PaymentRequest 83 | * @var $response \Payu\Response\PaymentResponse 84 | */ 85 | $response = $client->makePayment($request) 86 | 87 | if($response->getStatus() == ResponseAbstract::STATUS_APPROVED) { 88 | /* 89 | // Odeme islemi basariyla gerceklesti. 90 | echo $response->getTransactionId() 91 | */ 92 | } else { 93 | /* 94 | // Odeme islemi hatali oldu 95 | 96 | echo $response->getCode(); 97 | echo $response->getMessage(); 98 | */ 99 | } 100 | ``` 101 | 102 | ## [Peşin Satış İşlemi](#pesin-satis) 103 | ```php 104 | use Payu\Client; 105 | use Payu\Configuration; 106 | use Payu\Component\Card; 107 | use Payu\Component\Order; 108 | use Payu\Component\Billing; 109 | use Payu\Component\Product; 110 | 111 | // Satis islemi icin istemciyi hazirliyoruz. 112 | $configuration = new Configuration(); 113 | 114 | $configuration->setMerchantId('MY_MERCHANT_01') 115 | ->setSecretKey('SECRET_KEY') 116 | ->setPaymentEndpointUrl('https://secure.payu.com.tr/order/alu/v3'); 117 | 118 | $client = new Client($configuration); 119 | 120 | $card = new Card(); 121 | $card->setNumber('4282209027132016') 122 | ->setCvv('123') 123 | ->setMonth(5) 124 | ->setYear(2019); 125 | 126 | $order = new Order(); 127 | $order->setCode('ORDERNO123456') 128 | ->setClientIp('127.0.0.1'); 129 | 130 | $billing = new Billing(); 131 | $billing->setFirstName('John') 132 | ->setLastName('Smith') 133 | ->setPhone('05321231212') 134 | ->setEmail('test@test.net'); 135 | 136 | 137 | $product = new Product(); 138 | $product->setCode('PR1') 139 | ->setName('The Product') 140 | ->setQuantity(1) 141 | ->setPrice(10); 142 | 143 | /** @var $request \Payu\Request\PaymentRequest */ 144 | $request = $client->createPaymentRequestBuilder() 145 | ->setCard($card) 146 | ->setOrder($order) 147 | ->setBilling($billing) 148 | ->addProduct($product) 149 | ->build(); 150 | 151 | /** 152 | * @var $request \Payu\Request\PaymentRequest 153 | * @var $response \Payu\Response\PaymentResponse 154 | */ 155 | $response = $client->makePayment($request) 156 | 157 | if($response->getStatus() == ResponseAbstract::STATUS_APPROVED) { 158 | /* 159 | // Odeme islemi basariyla gerceklesti. 160 | echo $response->getTransactionId() 161 | */ 162 | } else { 163 | /* 164 | // Odeme islemi hatali oldu 165 | 166 | echo $response->getCode(); 167 | echo $response->getMessage(); 168 | */ 169 | } 170 | 171 | ``` 172 | 173 | ## [Taksitli Satış İşlemi](#taksitli-satis) 174 | 175 | Taksitli satış işlemi gerçekleştirilirken, taksit bilgisi, **buildOrder** yardımcı kurucu metodunun 3. parametresi olan $installment parametresi ile veya **Payu\Component\Order** sınıfının **setInstallment** metodu ile gönderileiblir. 176 | 177 | ```php 178 | //... 179 | ->buildOrder('ORDERNO123456', '127.0.0.1', 3) 180 | //... 181 | ``` 182 | veya 183 | ```php 184 | $order = new Order(); 185 | $order->setCode('ORDERNO123456') 186 | ->setClientIp('127.0.0.1') 187 | //... 188 | ->setInstallment(3); 189 | 190 | ``` 191 | 192 | ## [Tekrarlayan Ödeme İşlemi](#tekrarlayan-odeme) 193 | 194 | Tekrarlayan ödeme işlemi gerçekleştirilirken, işlemin tekrarlayan ödeme olup olmadığı bilgisi, **buildOrder** yardımcı kurucu metodununa 9. parametresi olan $recurringPayment parametresi ile veya **Payu\Component\Order** sınıfının **setRecurringPayment** metodu ile gönderileiblir. 195 | 196 | ```php 197 | //... 198 | ->buildOrder('ORDERNO123456', '127.0.0.1', ..., true) 199 | //... 200 | ``` 201 | veya 202 | ```php 203 | $order = new Order(); 204 | $order->setCode('ORDERNO123456') 205 | ->setClientIp('127.0.0.1') 206 | //... 207 | ->setRecurringPayment(true); 208 | ``` 209 | -------------------------------------------------------------------------------- /src/Payu/Validator/Validator/OrderValidator.php: -------------------------------------------------------------------------------- 1 | request->getOrder(); 21 | 22 | // Get currency from order instance 23 | try { 24 | static::filterAndValidateCurrencyCode($object->getCurrency()); 25 | } catch (\Exception $e) { 26 | throw new ValidationError($e->getMessage()); 27 | } 28 | } 29 | 30 | /** 31 | * @return void 32 | * @throws \Payu\Exception\ValidationError 33 | */ 34 | protected function validateObject() 35 | { 36 | /** 37 | * @var $object \Payu\Component\Order 38 | */ 39 | $object = $this->request->getOrder(); 40 | 41 | if (!$object || !$object instanceof Order) { 42 | throw new ValidationError('Order does not be empty.'); 43 | } 44 | } 45 | 46 | /** 47 | * Filters and validates given currency code. 48 | * 49 | * @param string $code Currency code to filter and validate. 50 | * @throws \InvalidArgumentException 51 | * @return string Three letter currency code. 52 | */ 53 | public static function filterAndValidateCurrencyCode($code) 54 | { 55 | $code = strtoupper(preg_replace('/[^a-zA-Z]/', '', $code)); 56 | 57 | if (array_key_exists($code, static::getAvailableCurrencies()) === false) { 58 | throw new \InvalidArgumentException('Currency code "'.$code.'" is not a valid ISO 4217 symbol'); 59 | } 60 | 61 | return $code; 62 | } 63 | 64 | /** 65 | * Returns official list of ISO 4217 currency codes. 66 | * 67 | * @link http://www.iso.org/iso/home/standards/currency_codes.htm 68 | * 69 | * @return array 70 | */ 71 | public static function getAvailableCurrencies() 72 | { 73 | return array( 74 | 'AFN' => 'Afghani', 75 | 'EUR' => 'Euro', 76 | 'ALL' => 'Lek', 77 | 'DZD' => 'Algerian Dinar', 78 | 'USD' => 'US Dollar', 79 | 'AOA' => 'Kwanza', 80 | 'XCD' => 'East Caribbean Dollar', 81 | 'ARS' => 'Argentine Peso', 82 | 'AMD' => 'Armenian Dram', 83 | 'AWG' => 'Aruban Florin', 84 | 'AUD' => 'Australian Dollar', 85 | 'AZN' => 'Azerbaijanian Manat', 86 | 'BSD' => 'Bahamian Dollar', 87 | 'BHD' => 'Bahraini Dinar', 88 | 'BDT' => 'Taka', 89 | 'BBD' => 'Barbados Dollar', 90 | 'BYR' => 'Belarussian Ruble', 91 | 'BZD' => 'Belize Dollar', 92 | 'XOF' => 'CFA Franc BCEAO', 93 | 'BMD' => 'Bermudian Dollar', 94 | 'BTN' => 'Ngultrum', 95 | 'INR' => 'Indian Rupee', 96 | 'BOB' => 'Boliviano', 97 | 'BOV' => 'Mvdol', 98 | 'BAM' => 'Convertible Mark', 99 | 'BWP' => 'Pula', 100 | 'NOK' => 'Norwegian Krone', 101 | 'BRL' => 'Brazilian Real', 102 | 'BND' => 'Brunei Dollar', 103 | 'BGN' => 'Bulgarian Lev', 104 | 'BIF' => 'Burundi Franc', 105 | 'CVE' => 'Cabo Verde Escudo', 106 | 'KHR' => 'Riel', 107 | 'XAF' => 'CFA Franc BEAC', 108 | 'CAD' => 'Canadian Dollar', 109 | 'KYD' => 'Cayman Islands Dollar', 110 | 'CLF' => 'Unidad de Fomento', 111 | 'CLP' => 'Chilean Peso', 112 | 'CNY' => 'Yuan Renminbi', 113 | 'COP' => 'Colombian Peso', 114 | 'COU' => 'Unidad de Valor Real', 115 | 'KMF' => 'Comoro Franc', 116 | 'CDF' => 'Congolese Franc', 117 | 'NZD' => 'New Zealand Dollar', 118 | 'CRC' => 'Costa Rican Colon', 119 | 'HRK' => 'Kuna', 120 | 'CUC' => 'Peso Convertible', 121 | 'CUP' => 'Cuban Peso', 122 | 'ANG' => 'Netherlands Antillean Guilder', 123 | 'CZK' => 'Czech Koruna', 124 | 'DKK' => 'Danish Krone', 125 | 'DJF' => 'Djibouti Franc', 126 | 'DOP' => 'Dominican Peso', 127 | 'EGP' => 'Egyptian Pound', 128 | 'SVC' => 'El Salvador Colon', 129 | 'ERN' => 'Nakfa', 130 | 'ETB' => 'Ethiopian Birr', 131 | 'FKP' => 'Falkland Islands Pound', 132 | 'FJD' => 'Fiji Dollar', 133 | 'XPF' => 'CFP Franc', 134 | 'GMD' => 'Dalasi', 135 | 'GEL' => 'Lari', 136 | 'GHS' => 'Ghana Cedi', 137 | 'GIP' => 'Gibraltar Pound', 138 | 'GTQ' => 'Quetzal', 139 | 'GBP' => 'Pound Sterling', 140 | 'GNF' => 'Guinea Franc', 141 | 'GYD' => 'Guyana Dollar', 142 | 'HTG' => 'Gourde', 143 | 'HNL' => 'Lempira', 144 | 'HKD' => 'Hong Kong Dollar', 145 | 'HUF' => 'Forint', 146 | 'ISK' => 'Iceland Krona', 147 | 'IDR' => 'Rupiah', 148 | 'XDR' => 'SDR Special Drawing Right', 149 | 'IRR' => 'Iranian Rial', 150 | 'IQD' => 'Iraqi Dinar', 151 | 'ILS' => 'New Israeli Sheqel', 152 | 'JMD' => 'Jamaican Dollar', 153 | 'JPY' => 'Yen', 154 | 'JOD' => 'Jordanian Dinar', 155 | 'KZT' => 'Tenge', 156 | 'KES' => 'Kenyan Shilling', 157 | 'KPW' => 'North Korean Won', 158 | 'KRW' => 'Won', 159 | 'KWD' => 'Kuwaiti Dinar', 160 | 'KGS' => 'Som', 161 | 'LAK' => 'Kip', 162 | 'LBP' => 'Lebanese Pound', 163 | 'LSL' => 'Loti', 164 | 'ZAR' => 'Rand', 165 | 'LRD' => 'Liberian Dollar', 166 | 'LYD' => 'Libyan Dinar', 167 | 'CHF' => 'Swiss Franc', 168 | 'MOP' => 'Pataca', 169 | 'MKD' => 'Denar', 170 | 'MGA' => 'Malagasy Ariary', 171 | 'MWK' => 'Kwacha', 172 | 'MYR' => 'Malaysian Ringgit', 173 | 'MVR' => 'Rufiyaa', 174 | 'MRO' => 'Ouguiya', 175 | 'MUR' => 'Mauritius Rupee', 176 | 'XUA' => 'ADB Unit of Account', 177 | 'MXN' => 'Mexican Peso', 178 | 'MXV' => 'Mexican Unidad de Inversion UDI', 179 | 'MDL' => 'Moldovan Leu', 180 | 'MNT' => 'Tugrik', 181 | 'MAD' => 'Moroccan Dirham', 182 | 'MZN' => 'Mozambique Metical', 183 | 'MMK' => 'Kyat', 184 | 'NAD' => 'Namibia Dollar', 185 | 'NPR' => 'Nepalese Rupee', 186 | 'NIO' => 'Cordoba Oro', 187 | 'NGN' => 'Naira', 188 | 'OMR' => 'Rial Omani', 189 | 'PKR' => 'Pakistan Rupee', 190 | 'PAB' => 'Balboa', 191 | 'PGK' => 'Kina', 192 | 'PYG' => 'Guarani', 193 | 'PEN' => 'Nuevo Sol', 194 | 'PHP' => 'Philippine Peso', 195 | 'PLN' => 'Zloty', 196 | 'QAR' => 'Qatari Rial', 197 | 'RON' => 'Romanian Leu', 198 | 'RUB' => 'Russian Ruble', 199 | 'RWF' => 'Rwanda Franc', 200 | 'SHP' => 'Saint Helena Pound', 201 | 'WST' => 'Tala', 202 | 'STD' => 'Dobra', 203 | 'SAR' => 'Saudi Riyal', 204 | 'RSD' => 'Serbian Dinar', 205 | 'SCR' => 'Seychelles Rupee', 206 | 'SLL' => 'Leone', 207 | 'SGD' => 'Singapore Dollar', 208 | 'XSU' => 'Sucre', 209 | 'SBD' => 'Solomon Islands Dollar', 210 | 'SOS' => 'Somali Shilling', 211 | 'SSP' => 'South Sudanese Pound', 212 | 'LKR' => 'Sri Lanka Rupee', 213 | 'SDG' => 'Sudanese Pound', 214 | 'SRD' => 'Surinam Dollar', 215 | 'SZL' => 'Lilangeni', 216 | 'SEK' => 'Swedish Krona', 217 | 'CHE' => 'WIR Euro', 218 | 'CHW' => 'WIR Franc', 219 | 'SYP' => 'Syrian Pound', 220 | 'TWD' => 'New Taiwan Dollar', 221 | 'TJS' => 'Somoni', 222 | 'TZS' => 'Tanzanian Shilling', 223 | 'THB' => 'Baht', 224 | 'TOP' => 'Paanga', 225 | 'TTD' => 'Trinidad and Tobago Dollar', 226 | 'TND' => 'Tunisian Dinar', 227 | 'TRY' => 'Turkish Lira', 228 | 'TMT' => 'Turkmenistan New Manat', 229 | 'UGX' => 'Uganda Shilling', 230 | 'UAH' => 'Hryvnia', 231 | 'AED' => 'UAE Dirham', 232 | 'USN' => 'US Dollar Next day', 233 | 'UYI' => 'Uruguay Peso en Unidades Indexadas URUIURUI', 234 | 'UYU' => 'Peso Uruguayo', 235 | 'UZS' => 'Uzbekistan Sum', 236 | 'VUV' => 'Vatu', 237 | 'VEF' => 'Bolivar', 238 | 'VND' => 'Dong', 239 | 'YER' => 'Yemeni Rial', 240 | 'ZMW' => 'Zambian Kwacha', 241 | 'ZWL' => 'Zimbabwe Dollar', 242 | 'XBA' => 'Bond Markets Unit European Composite Unit EURCO', 243 | 'XBB' => 'Bond Markets Unit European Monetary Unit EMU6', 244 | 'XBC' => 'Bond Markets Unit European Unit of Account 9 EUA9', 245 | 'XBD' => 'Bond Markets Unit European Unit of Account 17 EUA17', 246 | 'XTS' => 'Codes specifically reserved for testing purposes', 247 | 'XAU' => 'Gold', 248 | 'XPD' => 'Palladium', 249 | 'XPT' => 'Platinum', 250 | 'XAG' => 'Silver', 251 | ); 252 | } 253 | } 254 | --------------------------------------------------------------------------------