diff --git a/src/CancelData.php b/src/CancelData.php new file mode 100644 index 0000000..c8e4b00 --- /dev/null +++ b/src/CancelData.php @@ -0,0 +1,24 @@ +data['Amount'] = $amount; - - return $this; - } - - /** - * @return mixed - */ - public function getAmount() - { - return $this->data['Amount']; - } - - /** - * @return $this - */ - public function removeAmount() - { - unset($this->data['Amount']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/BaseData.php b/src/Data/Traits/BaseData.php deleted file mode 100644 index e9c9e90..0000000 --- a/src/Data/Traits/BaseData.php +++ /dev/null @@ -1,35 +0,0 @@ -data; - } - - /** - * @return $this - */ - public function clear() - { - $this->data = []; - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/CustomerKey.php b/src/Data/Traits/CustomerKey.php deleted file mode 100644 index 96e90f6..0000000 --- a/src/Data/Traits/CustomerKey.php +++ /dev/null @@ -1,54 +0,0 @@ -data['CustomerKey'] = $customerKey; - - return $this; - } - - /** - * @return mixed - */ - public function getCustomerKey() - { - return $this->data['CustomerKey']; - } - - /** - * @return $this - */ - public function removeCustomerKey() - { - unset($this->data['CustomerKey']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/DATA.php b/src/Data/Traits/DATA.php deleted file mode 100644 index 5b20b3a..0000000 --- a/src/Data/Traits/DATA.php +++ /dev/null @@ -1,56 +0,0 @@ -data['DATA'] = $data; - - return $this; - } - - /** - * @return mixed - */ - public function getDATA() - { - return $this->data['DATA']; - } - - /** - * @return $this - */ - public function removeDATA() - { - unset($this->data['DATA']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Description.php b/src/Data/Traits/Description.php deleted file mode 100644 index 505cb68..0000000 --- a/src/Data/Traits/Description.php +++ /dev/null @@ -1,51 +0,0 @@ -data['Description'] = $description; - - return $this; - } - - /** - * @return mixed - */ - public function getDescription() - { - return $this->data['Description']; - } - - /** - * @return $this - */ - public function removeDescription() - { - unset($this->data['Description']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Ean13.php b/src/Data/Traits/Ean13.php deleted file mode 100644 index 6b5f023..0000000 --- a/src/Data/Traits/Ean13.php +++ /dev/null @@ -1,51 +0,0 @@ -data['Ean13'] = $ean13; - - return $this; - } - - /** - * @return mixed - */ - public function getEan13() - { - return $this->data['Ean13']; - } - - /** - * @return $this - */ - public function removeEan13() - { - unset($this->data['Ean13']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Email.php b/src/Data/Traits/Email.php deleted file mode 100644 index 43cecb7..0000000 --- a/src/Data/Traits/Email.php +++ /dev/null @@ -1,51 +0,0 @@ -data['Email'] = $email; - - return $this; - } - - /** - * @return mixed - */ - public function getEmail() - { - return $this->data['Email']; - } - - /** - * @return $this - */ - public function removeEmail() - { - unset($this->data['Email']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/EmailCompany.php b/src/Data/Traits/EmailCompany.php deleted file mode 100644 index 88ca66d..0000000 --- a/src/Data/Traits/EmailCompany.php +++ /dev/null @@ -1,51 +0,0 @@ -data['EmailCompany'] = $emailCompany; - - return $this; - } - - /** - * @return mixed - */ - public function getEmailCompany() - { - return $this->data['EmailCompany']; - } - - /** - * @return $this - */ - public function removeEmailCompany() - { - unset($this->data['EmailCompany']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/FailURL.php b/src/Data/Traits/FailURL.php deleted file mode 100644 index 09d941f..0000000 --- a/src/Data/Traits/FailURL.php +++ /dev/null @@ -1,54 +0,0 @@ -data['FailURL'] = $failURL; - - return $this; - } - - /** - * @return mixed - */ - public function getFailURL() - { - return $this->data['FailURL']; - } - - /** - * @return $this - */ - public function removeFailURL() - { - unset($this->data['FailURL']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/IP.php b/src/Data/Traits/IP.php deleted file mode 100644 index 82df157..0000000 --- a/src/Data/Traits/IP.php +++ /dev/null @@ -1,51 +0,0 @@ -data['IP'] = $ip; - - return $this; - } - - /** - * @return mixed - */ - public function getIP() - { - return $this->data['IP']; - } - - /** - * @return $this - */ - public function removeIP() - { - unset($this->data['IP']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Items.php b/src/Data/Traits/Items.php deleted file mode 100644 index 66ac1bf..0000000 --- a/src/Data/Traits/Items.php +++ /dev/null @@ -1,51 +0,0 @@ -data['Items'] = $items; - - return $this; - } - - /** - * @return mixed - */ - public function getItems() - { - return $this->data['Items']; - } - - /** - * @return $this - */ - public function removeItems() - { - unset($this->data['Items']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Language.php b/src/Data/Traits/Language.php deleted file mode 100644 index a3caced..0000000 --- a/src/Data/Traits/Language.php +++ /dev/null @@ -1,54 +0,0 @@ -data['Language'] = $language; - - return $this; - } - - /** - * @return mixed - */ - public function getLanguage() - { - return $this->data['Language']; - } - - /** - * @return $this - */ - public function removeLanguage() - { - unset($this->data['Language']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Name.php b/src/Data/Traits/Name.php deleted file mode 100644 index e8907a8..0000000 --- a/src/Data/Traits/Name.php +++ /dev/null @@ -1,51 +0,0 @@ -data['Name'] = $name; - - return $this; - } - - /** - * @return mixed - */ - public function getName() - { - return $this->data['Name']; - } - - /** - * @return $this - */ - public function removeName() - { - unset($this->data['Name']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/NotificationURL.php b/src/Data/Traits/NotificationURL.php deleted file mode 100644 index 59e50d3..0000000 --- a/src/Data/Traits/NotificationURL.php +++ /dev/null @@ -1,54 +0,0 @@ -data['NotificationURL'] = $notificationURL; - - return $this; - } - - /** - * @return mixed - */ - public function getNotificationURL() - { - return $this->data['NotificationURL']; - } - - /** - * @return $this - */ - public function removeNotificationURL() - { - unset($this->data['NotificationURL']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/OrderId.php b/src/Data/Traits/OrderId.php deleted file mode 100644 index 65b1627..0000000 --- a/src/Data/Traits/OrderId.php +++ /dev/null @@ -1,51 +0,0 @@ -data['OrderId'] = $orderId; - - return $this; - } - - /** - * @return mixed - */ - public function getOrderId() - { - return $this->data['OrderId']; - } - - /** - * @return $this - */ - public function removeOrderId() - { - unset($this->data['OrderId']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/PayType.php b/src/Data/Traits/PayType.php deleted file mode 100644 index c20d3f1..0000000 --- a/src/Data/Traits/PayType.php +++ /dev/null @@ -1,53 +0,0 @@ -data['PayType'] = $payType; - - return $this; - } - - /** - * @return mixed - */ - public function getPayType() - { - return $this->data['PayType']; - } - - /** - * @return $this - */ - public function removePayType() - { - unset($this->data['PayType']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/PaymentId.php b/src/Data/Traits/PaymentId.php deleted file mode 100644 index 41fcc2c..0000000 --- a/src/Data/Traits/PaymentId.php +++ /dev/null @@ -1,51 +0,0 @@ -data['PaymentId'] = $paymentId; - - return $this; - } - - /** - * @return mixed - */ - public function getPaymentId() - { - return $this->data['PaymentId']; - } - - /** - * @return $this - */ - public function removePaymentId() - { - unset($this->data['PaymentId']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/PaymentMethod.php b/src/Data/Traits/PaymentMethod.php deleted file mode 100644 index 50adba3..0000000 --- a/src/Data/Traits/PaymentMethod.php +++ /dev/null @@ -1,59 +0,0 @@ -data['PaymentMethod'] = $paymentMethod; - - return $this; - } - - /** - * @return mixed - */ - public function getPaymentMethod() - { - return $this->data['PaymentMethod']; - } - - /** - * @return $this - */ - public function removePaymentMethod() - { - unset($this->data['PaymentMethod']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/PaymentObject.php b/src/Data/Traits/PaymentObject.php deleted file mode 100644 index 4563ae7..0000000 --- a/src/Data/Traits/PaymentObject.php +++ /dev/null @@ -1,66 +0,0 @@ -data['PaymentObject'] = $paymentObject; - - return $this; - } - - /** - * @return mixed - */ - public function getPaymentObject() - { - return $this->data['PaymentObject']; - } - - /** - * @return $this - */ - public function removePaymentObject() - { - unset($this->data['PaymentObject']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Phone.php b/src/Data/Traits/Phone.php deleted file mode 100644 index e39f6df..0000000 --- a/src/Data/Traits/Phone.php +++ /dev/null @@ -1,51 +0,0 @@ -data['Phone'] = $phone; - - return $this; - } - - /** - * @return mixed - */ - public function getPhone() - { - return $this->data['Phone']; - } - - /** - * @return $this - */ - public function removePhone() - { - unset($this->data['Phone']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Price.php b/src/Data/Traits/Price.php deleted file mode 100644 index 80690cf..0000000 --- a/src/Data/Traits/Price.php +++ /dev/null @@ -1,51 +0,0 @@ -data['Price'] = $price; - - return $this; - } - - /** - * @return mixed - */ - public function getPrice() - { - return $this->data['Price']; - } - - /** - * @return $this - */ - public function removePrice() - { - unset($this->data['Price']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Quantity.php b/src/Data/Traits/Quantity.php deleted file mode 100644 index 16bab68..0000000 --- a/src/Data/Traits/Quantity.php +++ /dev/null @@ -1,53 +0,0 @@ -data['Quantity'] = $quantity; - - return $this; - } - - /** - * @return mixed - */ - public function getQuantity() - { - return $this->data['Quantity']; - } - - /** - * @return $this - */ - public function removeQuantity() - { - unset($this->data['Quantity']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Receipt.php b/src/Data/Traits/Receipt.php deleted file mode 100644 index cf887bd..0000000 --- a/src/Data/Traits/Receipt.php +++ /dev/null @@ -1,51 +0,0 @@ -data['Receipt'] = $receipt; - - return $this; - } - - /** - * @return mixed - */ - public function getReceipt() - { - return $this->data['Receipt']; - } - - /** - * @return $this - */ - public function removeReceipt() - { - unset($this->data['Receipt']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Recurrent.php b/src/Data/Traits/Recurrent.php deleted file mode 100644 index 8b05ce7..0000000 --- a/src/Data/Traits/Recurrent.php +++ /dev/null @@ -1,53 +0,0 @@ -data['Recurrent'] = $recurrent; - - return $this; - } - - /** - * @return mixed - */ - public function getRecurrent() - { - return $this->data['Recurrent']; - } - - /** - * @return $this - */ - public function removeRecurrent() - { - unset($this->data['Recurrent']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/RedirectDueDate.php b/src/Data/Traits/RedirectDueDate.php deleted file mode 100644 index 3b74dad..0000000 --- a/src/Data/Traits/RedirectDueDate.php +++ /dev/null @@ -1,55 +0,0 @@ -data['RedirectDueDate'] = $redirectDueDate; - - return $this; - } - - /** - * @return mixed - */ - public function getRedirectDueDate() - { - return $this->data['RedirectDueDate']; - } - - /** - * @return $this - */ - public function removeRedirectDueDate() - { - unset($this->data['RedirectDueDate']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/ShopCode.php b/src/Data/Traits/ShopCode.php deleted file mode 100644 index 83f4236..0000000 --- a/src/Data/Traits/ShopCode.php +++ /dev/null @@ -1,51 +0,0 @@ -data['ShopCode'] = $shopCode; - - return $this; - } - - /** - * @return mixed - */ - public function getShopCode() - { - return $this->data['ShopCode']; - } - - /** - * @return $this - */ - public function removeShopCode() - { - unset($this->data['ShopCode']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/SuccessURL.php b/src/Data/Traits/SuccessURL.php deleted file mode 100644 index f8e0fd6..0000000 --- a/src/Data/Traits/SuccessURL.php +++ /dev/null @@ -1,54 +0,0 @@ -data['SuccessURL'] = $successURL; - - return $this; - } - - /** - * @return mixed - */ - public function getSuccessURL() - { - return $this->data['SuccessURL']; - } - - /** - * @return $this - */ - public function removeSuccessURL() - { - unset($this->data['SuccessURL']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Tax.php b/src/Data/Traits/Tax.php deleted file mode 100644 index 4a259ef..0000000 --- a/src/Data/Traits/Tax.php +++ /dev/null @@ -1,57 +0,0 @@ -data['Tax'] = $tax; - - return $this; - } - - /** - * @return mixed - */ - public function getTax() - { - return $this->data['Tax']; - } - - /** - * @return $this - */ - public function removeTax() - { - unset($this->data['Tax']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Taxation.php b/src/Data/Traits/Taxation.php deleted file mode 100644 index 0c2d513..0000000 --- a/src/Data/Traits/Taxation.php +++ /dev/null @@ -1,57 +0,0 @@ -data['Taxation'] = $taxation; - - return $this; - } - - /** - * @return mixed - */ - public function getTaxation() - { - return $this->data['Taxation']; - } - - /** - * @return $this - */ - public function removeTaxation() - { - unset($this->data['Taxation']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/TerminalKey.php b/src/Data/Traits/TerminalKey.php deleted file mode 100644 index 5d9699e..0000000 --- a/src/Data/Traits/TerminalKey.php +++ /dev/null @@ -1,51 +0,0 @@ -data['TerminalKey'] = $terminalKey; - - return $this; - } - - /** - * @return mixed - */ - public function getTerminalKey() - { - return $this->data['TerminalKey']; - } - - /** - * @return $this - */ - public function removeTerminalKey() - { - unset($this->data['TerminalKey']); - - return $this; - } -} \ No newline at end of file diff --git a/src/Data/Traits/Token.php b/src/Data/Traits/Token.php deleted file mode 100644 index e3413b5..0000000 --- a/src/Data/Traits/Token.php +++ /dev/null @@ -1,62 +0,0 @@ -data; - unset($data['Receipt'], $data['DATA']); - $data['Password'] = $password; - ksort($data); - - $token = ''; - foreach ($data as $value) { - $token .= $value; - } - - $this->data['Token'] = hash('sha256', $token); - - return $this; - } - - /** - * @return mixed - */ - public function getToken() - { - return $this->data['Token']; - } - - /** - * @return $this - */ - public function removeToken() - { - unset($this->data['Token']); - - return $this; - } -} \ No newline at end of file diff --git a/src/GetStateData.php b/src/GetStateData.php new file mode 100644 index 0000000..6a4058a --- /dev/null +++ b/src/GetStateData.php @@ -0,0 +1,23 @@ +data; + } + + /** + * @return $this + */ + public function clear() + { + $this->data = []; + + return $this; + } + + /** + * @param $name + * @param $value + */ + public function __set($name, $value) + { + $this->data[ $name ] = $value; + } + + /** + * @param $name + * + * @return mixed + */ + public function __get($name) + { + return $this->data[ $name ]; + } + + /** + * @param $name + */ + public function __unset($name) + { + if (isset($this->data[ $name ])) { + unset($this->data[ $name ]); + } + } +} \ No newline at end of file diff --git a/src/Traits/BaseDataWithToken.php b/src/Traits/BaseDataWithToken.php new file mode 100644 index 0000000..0833646 --- /dev/null +++ b/src/Traits/BaseDataWithToken.php @@ -0,0 +1,34 @@ +toArray(); + + $data['Password'] = $password; + unset($data['Receipt'], $data['DATA']); + ksort($data); + + $token = ''; + foreach ($data as $value) { + $token .= $value; + } + + $this->Token = hash('sha256', $token); + } +} \ No newline at end of file diff --git a/tests/TestData.php b/tests/TestData.php new file mode 100644 index 0000000..2868d95 --- /dev/null +++ b/tests/TestData.php @@ -0,0 +1,181 @@ +TerminalKey = "TestB"; + $data->Amount = 140000; + $data->OrderId = "21050"; + $data->Description = "Подарочная карта на 1400.00 рублей"; + $data->DATA = [ + "Phone" => "+71234567890", + "Email" => "a@test.com", + ]; + + $item1 = new ItemData(); + $item1->Name = "Наименование товара 1"; + $item1->Price = 10000; + $item1->Quantity = 1.00; + $item1->Amount = 10000; + $item1->PaymentMethod = "full prepayment"; + $item1->PaymentObject = "commodity"; + $item1->Tax = "vat10"; + $item1->Ean13 = "0123456789"; + + $item2 = new ItemData(); + $item2->Name = "Наименование товара 2"; + $item2->Price = 20000; + $item2->Quantity = 2.00; + $item2->Amount = 40000; + $item2->PaymentMethod = "prepayment"; + $item2->PaymentObject = "service"; + $item2->Tax = "vat20"; + + $item3 = new ItemData(); + $item3->Name = "Наименование товара 3"; + $item3->Price = 30000; + $item3->Quantity = 3.00; + $item3->Amount = 90000; + $item3->Tax = "vat10"; + + $receipt = new ReceiptData(); + $receipt->Email = "a@test.ru"; + $receipt->Phone = "+79031234567"; + $receipt->EmailCompany = "b@test.ru"; + $receipt->Taxation = "osn"; + $receipt->Items = [ + $item1->toArray(), + $item2->toArray(), + $item3->toArray(), + ]; + $data->Receipt = $receipt->toArray(); + + $array = [ + "TerminalKey" => "TestB", + "Amount" => 140000, + "OrderId" => "21050", + "Description" => "Подарочная карта на 1400.00 рублей", + "DATA" => [ + + "Phone" => "+71234567890", + "Email" => "a@test.com", + ], + + "Receipt" => [ + "Email" => "a@test.ru", + "Phone" => "+79031234567", + "EmailCompany" => "b@test.ru", + "Taxation" => "osn", + "Items" => [ + [ + "Name" => "Наименование товара 1", + "Price" => 10000, + "Quantity" => 1.00, + "Amount" => 10000, + "PaymentMethod" => "full prepayment", + "PaymentObject" => "commodity", + "Tax" => "vat10", + "Ean13" => "0123456789", + ], + [ + "Name" => "Наименование товара 2", + "Price" => 20000, + "Quantity" => 2.00, + "Amount" => 40000, + "PaymentMethod" => "prepayment", + "PaymentObject" => "service", + "Tax" => "vat20", + ], + [ + "Name" => "Наименование товара 3", + "Price" => 30000, + "Quantity" => 3.00, + "Amount" => 90000, + "Tax" => "vat10", + ], + ], + ], + ]; + + $this->assertEquals($data->toArray(), $array); + } + + public function testConfirmData() + { + $data = new ConfirmData(); + + $data->TerminalKey = "TinkoffBankTest"; + $data->PaymentId = "2164657"; + $data->generateToken("password"); + + $array = [ + "TerminalKey" => "TinkoffBankTest", + "PaymentId" => "2164657", + "Token" => "3cb13992b28bc106867e32c9a1a9185f9715860c09d21f91b3ab5dcc5dfe211b", + ]; + + $this->assertEquals($data->toArray(), $array); + } + + public function testCancelData() + { + $data = new CancelData(); + + $data->TerminalKey = "TinkoffBankTest"; + $data->PaymentId = "2164657"; + $data->generateToken("password"); + + $array = [ + "TerminalKey" => "TinkoffBankTest", + "PaymentId" => "2164657", + "Token" => "3cb13992b28bc106867e32c9a1a9185f9715860c09d21f91b3ab5dcc5dfe211b", + ]; + + $this->assertEquals($data->toArray(), $array); + } + + public function testGetStateData() + { + $data = new GetStateData(); + + $data->TerminalKey = "TinkoffBankTest"; + $data->PaymentId = "2164657"; + $data->generateToken("password"); + + $array = [ + "TerminalKey" => "TinkoffBankTest", + "PaymentId" => "2164657", + "Token" => "3cb13992b28bc106867e32c9a1a9185f9715860c09d21f91b3ab5dcc5dfe211b", + ]; + + $this->assertEquals($data->toArray(), $array); + } + + public function testResendData() + { + $data = new ResendData(); + + $data->TerminalKey = "TinkoffBankTest"; + $data->generateToken("password"); + + $array = [ + "TerminalKey" => "TinkoffBankTest", + "Token" => "79e28c81bdd95b8a8a2d4778aa40978e54161a9ed261ac76de8f5d03f2fd78c0", + ]; + + $this->assertEquals($data->toArray(), $array); + } +}