From 3cac46f3ca0be397bc856e9addaabbd751af36c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9?=
{l s='Оплатите заказ ниже' d='Modules.Yadpay.Shop'}
-
";
+ } else {
+ $this->module->sendToVk($shop_name.' - Ошибка оплаты картой: '. $res->error);
+ Tools::redirect('index.php?controller=order&step=3');
+ }
}
- echo $total . '
';
- echo $this->module->yadWallet . '
';
- echo $this->module->yadRedirectUrl . '
';
- echo $this->module->yadClientId . '
';
- echo $this->module->yadSecret . '
';
- echo $customer->secure_key . '
';
+ //Tools::redirect('index.php?controller=order&step=3');
}
}
diff --git a/controllers/front/validation.php b/controllers/front/validation.php
index 898ab46..a579ade 100644
--- a/controllers/front/validation.php
+++ b/controllers/front/validation.php
@@ -10,7 +10,6 @@ public function postProcess()
Tools::redirect('index.php?controller=order&step=1');
}
- // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process
$authorized = false;
foreach (Module::getPaymentModules() as $module) {
if ($module['name'] == 'yadpay') {
@@ -32,12 +31,57 @@ public function postProcess()
$currency = $this->context->currency;
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
- $mailVars = array(
- '{YAD_DESCRIPTION}' => Configuration::get('YAD_DESCRIPTION'),
- '{yadpay_html}' => str_replace("\n", '
', Configuration::get('yadpay_description')));
+ $mailVars = array();
- $this->module->validateOrder((int)$cart->id, Configuration::get('PS_OS_CHEQUE'), $total, $this->module->displayName, null, $mailVars, (int)$currency->id, false, $customer->secure_key);
+ if ($total) {
+ $this->module->validateOrder((int)$cart->id, Configuration::get('YAD_STATEMENT_ID'), $total, $this->module->displayName, null, $mailVars, (int)$currency->id, false, $customer->secure_key);
+ $this->module->sendToVk(Configuration::get('PS_SHOP_NAME').': '.'Оплачено Картой ' . $total .' руб. (3D secure). Корзина №'.$cart->id);
- Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)$cart->id.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);
+ Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)$cart->id
+ .'&id_module='.(int)$this->module->id
+ .'&id_order='.$this->module->currentOrder
+ .'&key='.$customer->secure_key);
+
+ }else{
+
+ $ord = new Order((int)Order::getOrderByCartId(Tools::getValue('cart_id')));
+
+ Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)Tools::getValue('cart_id')
+ .'&id_module='.(int)$this->module->id
+ .'&id_order='.$ord->id
+ .'&key='.$customer->secure_key);
+
+ }
+
+ /*if (Tools::getValue('cart_id')) {
+
+ if ($total) {
+ $this->module->validateOrder((int)$cart->id, Configuration::get('YAD_STATEMENT_ID'), $total, $this->module->displayName, null, $mailVars, (int)$currency->id, false, $customer->secure_key);
+ $this->module->sendToVk(Configuration::get('PS_SHOP_NAME').': '.'Оплачено Картой ' . $total .' руб. (3D secure). Корзина №'.$cart->id);
+
+ Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)$cart->id
+ .'&id_module='.(int)$this->module->id
+ .'&id_order='.$this->module->currentOrder
+ .'&key='.$customer->secure_key);
+
+ }else{
+
+ $ord = new Order((int)Order::getOrderByCartId(Tools::getValue('cart_id')));
+
+ Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)Tools::getValue('cart_id')
+ .'&id_module='.(int)$this->module->id
+ .'&id_order='.$ord->id
+ .'&key='.$customer->secure_key);
+ }
+
+ }else{
+
+ $this->module->validateOrder((int)$cart->id, Configuration::get('YAD_STATEMENT_ID'), $total, $this->module->displayName, null, $mailVars, (int)$currency->id, false, $customer->secure_key);
+
+ Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)$cart->id
+ .'&id_module='.(int)$this->module->id
+ .'&id_order='.$this->module->currentOrder
+ .'&key='.$customer->secure_key);
+ }*/
}
}
diff --git a/lib/api.php b/lib/api.php
new file mode 100644
index 0000000..c36af0c
--- /dev/null
+++ b/lib/api.php
@@ -0,0 +1,236 @@
+access_token = $access_token;
+ }
+ function sendAuthenticatedRequest($url, $options=array()) {
+ $this->checkToken();
+ return self::sendRequest($url, $options, $this->access_token);
+ }
+ function checkToken() {
+ if($this->access_token == NULL) {
+ throw new \Exception("obtain access_token first");
+ }
+ }
+
+ /**
+ * Returns information about a user's wallet
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/account-info.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/account-info-docpage/
+ * @throws Exceptions/YandexFormatError If authorization header is missing or
+ * has an invalid value
+ * @throws Exceptions/TokenError If a token is nonexistent, expired or revoked
+ * @throws Exceptions/ScopeError If a token does not have permissions for the
+ * requested operation
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ function accountInfo() {
+ return $this->sendAuthenticatedRequest("/api/account-info");
+ }
+
+ function getAuxToken($scope) {
+ return $this->sendAuthenticatedRequest("/api/token-aux", array(
+ "scope" => implode(" ", $scope)
+ ));
+ }
+
+ /**
+ * Returns operation history of a user's wallet.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/operation-history.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/operation-history-docpage/
+ * @param array[] $options Key-value parameters collection
+ * @throws Exceptions/YandexFormatError If authorization header is missing or
+ * has an invalid value
+ * @throws Exceptions/TokenError If a token is nonexistent, expired or revoked
+ * @throws Exceptions/ScopeError If a token does not have permissions for the
+ * requested operation
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ function operationHistory($options=NULL) {
+ return $this->sendAuthenticatedRequest("/api/operation-history", $options);
+ }
+
+ /**
+ * Returns details of operation specified by operation_id.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/operation-details.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/operation-details-docpage/
+ * @param string $operation_id
+ * @throws Exceptions/YandexFormatError If authorization header is missing or
+ * has an invalid value
+ * @throws Exceptions/TokenError If a token is nonexistent, expired or revoked
+ * @throws Exceptions/ScopeError If a token does not have permissions for the
+ * requested operation
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ function operationDetails($operation_id) {
+ return $this->sendAuthenticatedRequest("/api/operation-details",
+ array("operation_id" => $operation_id)
+ );
+ }
+
+ /**
+ * Requests a payment.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/request-payment.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/request-payment-docpage/
+ * @param array[] $options Key-value parameters collection
+ * @throws Exceptions/YandexFormatError If authorization header is missing or
+ * has an invalid value
+ * @throws Exceptions/TokenError If a token is nonexistent, expired or revoked
+ * @throws Exceptions/ScopeError If a token does not have permissions for the
+ * requested operation
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ function requestPayment($options) {
+ return $this->sendAuthenticatedRequest("/api/request-payment", $options);
+ }
+
+ /**
+ * Confirms a payment that was created using the request-payment method.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/process-payment.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/process-payment-docpage/
+ * @param array[] $options Key-value parameters collection
+ * @throws Exceptions/YandexFormatError If authorization header is missing or
+ * has an invalid value
+ * @throws Exceptions/TokenError If a token is nonexistent, expired or revoked
+ * @throws Exceptions/ScopeError If a token does not have permissions for the
+ * requested operation
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ function processPayment($options) {
+ return $this->sendAuthenticatedRequest("/api/process-payment", $options);
+ }
+
+ /**
+ * Accepts incoming transfer with a protection code or deferred transfer.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/incoming-transfer-accept.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/incoming-transfer-accept-docpage/
+ * @param string $operation_id
+ * @param string $protection_code Used in case of protected transfer.
+ * Omitted for deffered transfers
+ * @throws Exceptions/YandexFormatError If authorization header is missing or
+ * has an invalid value
+ * @throws Exceptions/TokenError If a token is nonexistent, expired or revoked
+ * @throws Exceptions/ScopeError If a token does not have permissions for the
+ * requested operation
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ function incomingTransferAccept($operation_id, $protection_code=NULL) {
+ return $this->sendAuthenticatedRequest("/api/incoming-transfer-accept",
+ array(
+ "operation_id" => $operation_id,
+ "protection_code" => $protection_code
+ ));
+ }
+
+ /**
+ * Rejects incoming transfer with a protection code or deferred trasfer.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/incoming-transfer-reject.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/incoming-transfer-reject-docpage/
+ * @param string $operation_id
+ * @throws Exceptions/YandexFormatError If authorization header is missing or
+ * has an invalid value
+ * @throws Exceptions/TokenError If a token is nonexistent, expired or revoked
+ * @throws Exceptions/ScopeError If a token does not have permissions for the
+ * requested operation
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ function incomingTransferReject($operation_id) {
+ return $this->sendAuthenticatedRequest("/api/incoming-transfer-reject",
+ array(
+ "operation_id" => $operation_id,
+ ));
+ }
+
+ /**
+ * Builds authorization url for user's browser
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/request-access-token.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/request-access-token-docpage/
+ * @param string $client_id The client_id that was assigned to the application.
+ * @param string $redirect_uri URI that the OAuth server sends the
+ * authorization result to. Must have a string value that exactly matches
+ * the redirect_uri parameter specified in the application registration
+ * data. Any additional parameters required for the application can beadded
+ * at the end of the string.
+ * @param string $scope A string of requested permissions(joined list of
+ * strings)
+ * @return response object
+ */
+ public static function buildObtainTokenUrl($client_id, $redirect_uri,
+ $scope) {
+ $params = sprintf(
+ "client_id=%s&response_type=%s&redirect_uri=%s&scope=%s",
+ $client_id, "code", $redirect_uri, implode(" ", $scope)
+ );
+ return sprintf("%s/oauth/authorize?%s", Config::$SP_MONEY_URL, $params);
+ }
+
+ /**
+ * Exchanges temporary authorization code for an access_token.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/obtain-access-token.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/obtain-access-token-docpage/
+ * @param string $client_id The client_id that was assigned to the application.
+ * @param string $code Temporary token.
+ * @param string $redirect_uri URI that the OAuth server sends the
+ * authorization result to. The value must exactly match the `redirect_uri` value
+ * from the previous "authorize" call.
+ * @param string $client_secret A secret word for verifying the application's
+ * authenticity. Specified if the service is registered with the option to
+ * verify authenticity.
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ public static function getAccessToken($client_id, $code, $redirect_uri,
+ $client_secret=NULL) {
+ $full_url = Config::$SP_MONEY_URL . "/oauth/token";
+ return self::sendRequest($full_url, array(
+ "code" => $code,
+ "client_id" => $client_id,
+ "grant_type" => "authorization_code",
+ "redirect_uri" => $redirect_uri,
+ "client_secret" => $client_secret
+ ));
+ }
+
+ /**
+ * Revokes a token.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/incoming-transfer-reject-xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/incoming-transfer-reject-docpage/
+ * @param string $token A token to be revoked
+ * @param string $revoke_all
+ * @throws Exceptions/YandexFormatError If authorization header is missing or
+ * has an invalid value
+ * @throws Exceptions/TokenError If a token is nonexistent, expired or revoked
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ public static function revokeToken($token, $revoke_all=false) {
+ return self::sendRequest("/api/revoke", array(
+ "revoke-all" => $revoke_all,
+ ), $token);
+ }
+}
diff --git a/lib/base.php b/lib/base.php
new file mode 100644
index 0000000..7768066
--- /dev/null
+++ b/lib/base.php
@@ -0,0 +1,65 @@
+status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+ $result->body = $body;
+ curl_close ($curl);
+
+ return self::processResult($result);
+ }
+ protected static function processResult($result) {
+ switch ($result->status_code) {
+ case 400:
+ throw new Exceptions\YandexFormatError;
+ break;
+ case 401:
+ throw new Exceptions\YandexTokenError;
+ break;
+ case 403:
+ throw new Exceptions\YandexScopeError;
+ break;
+ default:
+ if($result->status_code >= 500) {
+ throw new Exceptions\YandexServerError($result->status_code);
+ }
+ else {
+ return json_decode($result->body);
+ }
+ }
+ }
+}
diff --git a/lib/exceptions.php b/lib/exceptions.php
new file mode 100644
index 0000000..d1e3af8
--- /dev/null
+++ b/lib/exceptions.php
@@ -0,0 +1,34 @@
+instance_id = $instance_id;
+ }
+
+ /**
+ * Registers an instance of an application
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/instance-id.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/instance-id-docpage/
+ * @param string $client_id The client_id that was assigned to the application.
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ public static function getInstanceId($client_id) {
+ return self::sendRequest("/api/instance-id",
+ array("client_id" => $client_id));
+ }
+
+ /**
+ * Requests an external payment.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/request-external-payment.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/request-external-payment-docpage/
+ * @param array[] $payment_options Key-value parameters collection
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ public function request($payment_options) {
+ $payment_options['instance_id']= $this->instance_id;
+ return self::sendRequest("/api/request-external-payment",
+ $payment_options);
+ }
+
+ /**
+ * Requests an external payment.
+ *
+ * @see http://api.yandex.com/money/doc/dg/reference/request-external-payment.xml
+ * @see https://tech.yandex.ru/money/doc/dg/reference/request-external-payment-docpage/
+ * @param array[] $payment_options Key-value parameters collection
+ * @throws Exceptions/ServerError If status code >= 500
+ * @return response object
+ */
+ public function process($payment_options) {
+ $payment_options['instance_id']= $this->instance_id;
+ return self::sendRequest("/api/process-external-payment",
+ $payment_options);
+ }
+}
diff --git a/translations/index.php b/translations/index.php
new file mode 100644
index 0000000..a345193
--- /dev/null
+++ b/translations/index.php
@@ -0,0 +1,11 @@
+
-
-
-
{$yadDescription}
+ \ No newline at end of file diff --git a/views/templates/hook/info.tpl b/views/templates/hook/info.tpl index 319673e..451e6ed 100644 --- a/views/templates/hook/info.tpl +++ b/views/templates/hook/info.tpl @@ -1,7 +1,7 @@{l s="Оплата Яд-ом" d='Modules.Yadpay.Admin'}
-{l s="При оплате статус сменится на ожидание оплаты" d='Modules.Yadpay.Admin'}
-{l s="Нужно будет руками сменить статус заказа" d='Modules.Yadpay.Admin'}
+{l s="Оплата Картами или Яндекс.Деньгами" d='Modules.Yadpay.Admin'}
+{l s="После оплаты статус сменится на \"Заказ оплачен\"" d='Modules.Yadpay.Admin'}
+ID и секретное слово вы получите после регистрации приложения на сайте Яндекс.Денег
+При регистрации приложения нужно поставить галочку где будет надпись OAuth2