Skip to content

Commit

Permalink
0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Sep 3, 2017
1 parent 933e8a8 commit b92a6fb
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 45 deletions.
89 changes: 89 additions & 0 deletions API/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
namespace Dfe\Qiwi\API;
use Dfe\Qiwi\Settings as S;
// 2017-09-03
final class Client extends \Df\API\Client {
/**
* 2017-09-03
* @override
* @see \Df\API\Client::_construct()
* @used-by \Df\API\Client::__construct()
*/
protected function _construct() {
parent::_construct();
$this->resJson();
/**
* [QIWI Wallet] An example of a response to
* «PUT https://api.qiwi.com/api/v2/prv/{prv_id}/bills/{bill_id}»
* https://mage2.pro/t/4447
*/
$this->addFilterRes(function($v) {return $v['response'];});
}

/**
* 2017-09-03
* @override
* @see \Df\API\Client::headers()
* @used-by \Df\API\Client::__construct()
* @used-by \Df\API\Client::p()
* @return array(string => string)
*/
protected function headers() {/** @var S $s */$s = $this->s(); return [
/**
* 2017-09-03
* «Authentication data are transmitted using the standard rules of basic-authorization for HTTP-requests.
* The HTTP header "Authorization" is added to the request.
* The value of this parameter is composed of the word "Basic",
* blank character and encrypted BASE64 pair "API ID:API password"».
* «Авторизационные данные передаются по стандартным правилам basic-аутентификации при запросах по HTTP.
* К запросу добавляется HTTP-заголовок с параметром "Authorization".
* В заголовке указывается строка "Basic " (с пробелом на конце)
* и пара "API_ID:API_password", закодированная в BASE64.»
* `[QIWI Wallet] The REST API specification (v.2.12)`, page 7: https://mage2.pro/t/3745
* https://en.wikipedia.org/wiki/Basic_access_authentication
*/
'Authorization' => 'Basic ' . base64_encode("{$s->apiID()}:{$s->password1()}")
/**
* 2017-09-03
* «Requests from the merchants to QIWI
* are sent in the format of the HTTP-request parameters encoded by UTF-8.
* In response, the data is returned in one of two formats
* in accordance with the value of the "Accept" HTTP header, which is transmitted in the request:
*  XML (value of the "Accept" header: "application/xml", "text/xml");
*  JSON (value of the "Accept" header: "application/json", "text/json").»
* «Данные при запросах на сервер Visa QIWI Wallet
* передаются в формате параметров HTTP-запроса в кодировке UTF-8.
* В ответ данные возвращаются в одном из двух форматов
* в соответствии со значением HTTP-заголовка "Accept", передаваемого в запросе:
*  XML (значения заголовка "Accept": "application/xml", "text/xml");
*  JSON (значения заголовка "Accept": "application/json", "text/json").»
*/
,'Accept' => 'application/json'
];}

/**
* 2017-09-03
* @see \Df\API\Client::responseValidatorC()
* @used-by \Df\API\Client::p()
* @return string
*/
final protected function responseValidatorC() {return \Dfe\Qiwi\API\Validator::class;}

/**
* 2017-09-03
* @override
* @see \Df\API\Client::uriBase()
* @used-by \Df\API\Client::__construct()
* @used-by \Df\API\Client::_p()
* @return string
*/
protected function uriBase() {return "https://api.qiwi.com/api/v2/prv/{$this->s()->merchantID()}/bills";}

/**
* 2017-09-03
* @used-by headers()
* @used-by uriBase()
* @return S
*/
private function s() {return dfps($this);}
}
45 changes: 45 additions & 0 deletions API/Validator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
namespace Dfe\Qiwi\API;
/**
* 2017-09-03
* [QIWI Wallet] An example of a response to «PUT https://api.qiwi.com/api/v2/prv/{prv_id}/bills/{bill_id}»
* https://mage2.pro/t/4447
* @used-by \Dfe\Qiwi\API\Client::responseValidatorC()
*/
final class Validator extends \Df\API\Response\Validator {
/**
* 2017-09-03
* @override
* @see \Df\API\Exception::long()
* @used-by \Df\API\Client::p()
* @return string
*/
function long() {return '';}

/**
* 2017-09-03
* @override
* @see \Df\API\Exception::short()
* @used-by \Df\API\Client::p()
* @return string
*/
function short() {return '';}

/**
* 2017-09-03
* @override
* @see \Df\API\Response\Validator::valid()
* @used-by \Df\API\Response\Validator::validate()
* @return bool
*/
function valid() {return !$this->rCode();}

/**
* 2017-09-03 `[QIWI Wallet] API error codes`: https://mage2.pro/t/4448
* @used-by valid()
* @return int
*/
private function rCode() {return dfc($this, function() {return
intval(dfa($this->r(), 'result_code'))
;});}
}
52 changes: 11 additions & 41 deletions Charge.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,23 @@
<?php
namespace Dfe\Qiwi;
/**
* 2017-04-18
* 2017-09-03
* @method Method m()
* @method Settings s()
*/
final class Charge extends \Df\PaypalClone\Charge {
final class Charge extends \Df\Payment\Charge {
/**
* 2017-08-19
* @override
* @see \Df\PaypalClone\Charge::k_Amount()
* @used-by \Df\PaypalClone\Charge::p()
* @return string
*/
protected function k_Amount() {return '';}

/**
* 2017-08-19
* @override
* @see \Df\PaypalClone\Charge::k_MerchantId()
* @used-by \Df\PaypalClone\Charge::p()
* @return string
*/
protected function k_MerchantId() {return '';}

/**
* 2017-04-18
* @override
* @see \Df\PaypalClone\Charge::k_RequestId()
* @used-by \Df\PaypalClone\Charge::p()
* @return string
*/
protected function k_RequestId() {return '';}

/**
* 2017-04-18
* @override
* @see \Df\PaypalClone\Charge::k_Signature()
* @used-by \Df\PaypalClone\Charge::p()
* @return string
* 2017-09-03
* @used-by p()
* @return array(string => mixed)
*/
protected function k_Signature() {return '';}
private function pCharge() {$s = $this->s(); return [];}

/**
* 2017-04-18
* @override
* @see \Df\PaypalClone\Charge::pCharge()
* @used-by \Df\PaypalClone\Charge::p()
* @return array(string => mixed)
* 2017-09-03
* @used-by \Dfe\Qiwi\Init\Action::req()
* @param Method $m
* @return array(string, array(string => mixed))
*/
protected function pCharge() {$s = $this->s(); return [];}
static function p(Method $m) {return (new self($m))->pCharge();}
}
35 changes: 34 additions & 1 deletion Init/Action.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php
namespace Dfe\Qiwi\Init;
use Dfe\Qiwi\Charge;
use Dfe\Qiwi\Method as M;
use Dfe\Qiwi\W\Event as Ev;
// 2017-09-02
/** @method \Dfe\Qiwi\Method m() */
final class Action extends \Df\PaypalClone\Init\Action {
final class Action extends \Df\Payment\Init\Action {
/**
* 2017-09-02
* «[QIWI Wallet] The REST API specification (v.2.12)»: https://mage2.pro/t/3745
Expand All @@ -18,4 +21,34 @@ final class Action extends \Df\PaypalClone\Init\Action {
* @return string
*/
protected function redirectUrl() {return 'https://bill.qiwi.com/order/external/main.action';}

/**
* 2017-09-03
* @override
* @see \Df\Payment\Init\Action::transId()
* @used-by \Df\Payment\Init\Action::action()
* @used-by action()
* @return string|null
*/
protected function transId() {return $this->e2i('', Ev::T_INIT);}

/**
* 2017-09-03
* @used-by res()
* @return array(string => mixed)
*/
private function req() {return dfc($this, function() {
/** @var M $m */ /** @var array(string => mixed) $result */
df_sentry_extra($m = $this->m(), 'Request Params', $result = Charge::p($m));
$m->iiaSetTRR($result);
return $result;
});}

/**
* 2017-09-03
* @used-by redirectUrl()
* @used-by transId()
* @return array(string => mixed)
*/
private function res() {return [];}
}
2 changes: 1 addition & 1 deletion Method.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Dfe\Qiwi;
// 2017-04-18
final class Method extends \Df\PaypalClone\Method {
final class Method extends \Df\Payment\Method {
/**
* 2017-04-18
* @override
Expand Down
2 changes: 2 additions & 0 deletions Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
final class Settings extends \Df\Payment\Settings {
/**
* 2017-09-02 «API ID».
* @used-by \Dfe\Qiwi\API\Client::headers()
* @return string
*/
function apiID() {return $this->v();}

/**
* 2017-09-02 «API password».
* @used-by \Dfe\Qiwi\API\Client::headers()
* @return string
*/
function password1() {return $this->p();}
Expand Down
43 changes: 43 additions & 0 deletions W/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Dfe\Qiwi\W;
use Magento\Sales\Model\Order\Payment\Transaction as T;
/**
* 2017-09-03
*/
final class Event extends \Df\PaypalClone\W\Event {
/**
* 2017-09-03
* @override
* @see \Df\PaypalClone\W\Event::k_idE()
* @used-by \Df\PaypalClone\W\Event::idE()
* @return string
*/
protected function k_idE() {return '';}

/**
* 2017-09-03
* @override
* @see \Df\Payment\W\Event::k_pid()
* @used-by \Df\Payment\W\Event::pid()
* @return string
*/
protected function k_pid() {return '';}

/**
* 2017-09-03
* @override
* @see \Df\PaypalClone\W\Event::k_signature()
* @used-by \Df\PaypalClone\W\Event::signatureProvided()
* @return string
*/
protected function k_signature() {return '';}

/**
* 2017-09-03
* @override
* @see \Df\PaypalClone\W\Event::k_status()
* @used-by \Df\PaypalClone\W\Event::status()
* @return string
*/
protected function k_status() {return '';}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage2pro/qiwi"
,"version": "0.0.7"
,"version": "0.0.8"
,"description": "The «Visa QIWI Wallet» (QIWI Кошелёк) payment extension for Magento 2."
,"type": "magento2-module"
,"homepage": "https://mage2.pro/c/extensions/qiwi"
Expand All @@ -11,7 +11,7 @@
"homepage": "https://mage2.pro/users/dmitry_fedyuk",
"role": "Developer"
}]
,"require": {"mage2pro/core": ">=2.10.33"}
,"require": {"mage2pro/core": ">=2.11.7"}
,"autoload": {"files": ["registration.php"], "psr-4": {"Dfe\\Qiwi\\": ""}}
,"keywords": [
"API"
Expand Down
24 changes: 24 additions & 0 deletions etc/error-codes/en.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
0,"Success"
5,"Incorrect data in the request parameters"
13,"Server is busy, try again later"
78,"Operation is forbidden"
150,"Authorization error (e.g. invalid login/password)"
152,"Protocol is not enabled or protocol is disabled"
155,"This merchant’s identifier (API ID) is blocked"
210,"Invoice not found"
215,"Invoice with this bill_id already exists"
241,"Invoice amount is less than allowed"
242,"Invoice amount is greater than allowed. Also returns to refund request when the amount of refund exceeds the initial invoice amount or the amount left after the previous refunds"
298,"User not registered"
300,"Technical error"
303,"Wrong phone number"
316,"Authorization from the blocked merchant"
319,"No rights for the operation"
339,"IP-addresses blocked"
341,"Required parameter is incorrectly specified or absent in the request"
700,"Monthly limit on operations is exceeded"
774,"Visa QIWI Wallet user account temporarily blocked"
1001,"Currency is not allowed for the merchant"
1003,"No convert rate for these currencies"
1019,"Unable to determine wireless operator for MNO balance payment"
1419,"Bill was already payed"
24 changes: 24 additions & 0 deletions etc/error-codes/ru.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
0,"Успех"
5,"Неверные данные в параметрах запроса"
13,"Сервер занят, повторите запрос позже"
78,"Недопустимая операция"
150,"Ошибка авторизации"
152,"Не подключен или отключен протокол"
155,"Данный идентификатор провайдера (API ID) заблокирован"
210,"Счет не найден"
215,"Счет с таким bill_id уже существует"
241,"Сумма слишком мала"
242,"Сумма слишком велика, или сумма, переданная в запросе возврата средств, превышает сумму самого счета либо сумму счета, оставшуюся после предыдущих возвратов"
298,"Кошелек с таким номером не зарегистрирован"
300,"Техническая ошибка"
303,"Неверный номер телефона"
316,"Попытка авторизации заблокированным провайдером"
319,"Нет прав на данную операцию"
339,"Ваш IP-адрес или массив адресов заблокирован"
341,"Обязательный параметр указан неверно или отсутствует в запросе"
700,"Превышен месячный лимит на операции"
774,"Кошелек временно заблокирован"
1001,"Запрещенная валюта для провайдера"
1003,"Не удалось получить курс конвертации для данной пары валют"
1019,"Не удалось определить сотового оператора для мобильной коммерции"
1419,"Нельзя изменить данные счета – он уже оплачивается или оплачен"

0 comments on commit b92a6fb

Please sign in to comment.