Skip to content

Commit

Permalink
ЗФ-54 для Robokassa
Browse files Browse the repository at this point in the history
  • Loading branch information
kvalood committed May 5, 2019
1 parent 1876db6 commit 0bc19bc
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 63 deletions.
147 changes: 84 additions & 63 deletions payment/Robokassa/Robokassa.php
Original file line number Diff line number Diff line change
@@ -1,63 +1,84 @@
<?php

require_once('api/Simpla.php');

class Robokassa extends Simpla
{
public function checkout_form($order_id, $button_text = null)
{
if(empty($button_text))
$button_text = 'Перейти к оплате';

$order = $this->orders->get_order((int)$order_id);
$payment_method = $this->payment->get_payment_method($order->payment_method_id);
$payment_settings = $this->payment->get_payment_settings($payment_method->id);

$price = $this->money->convert($order->total_price, $payment_method->currency_id, false);

$success_url = $this->config->root_url.'/order/'.$order->url;

$fail_url = $this->config->root_url.'/order/'.$order->url;

// регистрационная информация (логин, пароль #1)
// registration info (login, password #1)
$mrh_login = $payment_settings['login'];
$mrh_pass1 = $payment_settings['password1'];

// номер заказа
// number of order
$inv_id = $order->id;

// описание заказа
// order description
$inv_desc = 'Оплата заказа №'.$inv_id;

// метод оплаты - текущий
$shp_item = $payment_method->id;

// предлагаемая валюта платежа
// default payment e-currency
$in_curr = "PCR";

// язык
// language
$culture = $payment_settings['language'];

// формирование подписи
// generate signature
$crc = md5("$mrh_login:$price:$inv_id:$mrh_pass1");

$button = "<form accept-charset='cp1251' action='https://merchant.roboxchange.com/Index.aspx' method=POST>".
"<input type=hidden name=MrchLogin value='$mrh_login'>".
"<input type=hidden name=OutSum value='$price'>".
"<input type=hidden name=InvId value='$inv_id'>".
"<input type=hidden name=Desc value='$inv_desc'>".
"<input type=hidden name=SignatureValue value='$crc'>".
"<input type=hidden name=IncCurrLabel value='$in_curr'>".
"<input type=hidden name=Culture value='$culture'>".
"<input type=submit class=checkout_button value='Перейти к оплате &#8594;'>".
"</form>";
return $button;
}

}
<?php

require_once('api/Simpla.php');

class Robokassa extends Simpla
{
public function checkout_form($order_id, $button_text = null)
{
if(empty($button_text)) {
$button_text = 'Перейти к оплате';
}

$order = $this->orders->get_order((int)$order_id);
$payment_method = $this->payment->get_payment_method($order->payment_method_id);
$payment_settings = $this->payment->get_payment_settings($payment_method->id);
$purchases = $this->orders->get_purchases(['order_id' => $order->id]);

$price = $this->money->convert($order->total_price, $payment_method->currency_id, false);

$success_url = $this->config->root_url.'/order/'.$order->url;

$fail_url = $this->config->root_url.'/order/'.$order->url;

// регистрационная информация (логин, пароль #1)
// registration info (login, password #1)
$mrh_login = $payment_settings['login'];
$mrh_pass1 = $payment_settings['password1'];

// номер заказа
// number of order
$inv_id = $order->id;

// описание заказа
// order description
$inv_desc = 'Оплата заказа №'.$inv_id;

// метод оплаты - текущий
$shp_item = $payment_method->id;

// предлагаемая валюта платежа
// default payment e-currency
$in_curr = "PCR";

// язык
// language
$culture = $payment_settings['language'];

// Информация о товарах для чека
$receipt = [
"sho" => $payment_settings['sno'],
];

foreach($purchases as $purchase) {
$receipt['items'][] = [
"name" => $purchase->product_name,
"quantity" => $purchase->amount,
"sum" => $purchase->price * $purchase->amount,
"payment_method" => "full_payment",
"payment_object" => "commodity",
"tax" => ($payment_settings['sno'] == 'osn') ? $payment_settings['tax'] : 'none'
];
}

$receipt = json_encode($receipt);

// формирование подписи
// generate signature
$crc = md5("$mrh_login:$price:$inv_id:$receipt:$mrh_pass1");

$button = "<form accept-charset='cp1251' action='https://merchant.roboxchange.com/Index.aspx' method=POST>".
"<input type=hidden name=MrchLogin value='$mrh_login'>".
"<input type=hidden name=OutSum value='$price'>".
"<input type=hidden name=InvId value='$inv_id'>".
"<input type=hidden name=Desc value='$inv_desc'>".
"<input type=hidden name=SignatureValue value='$crc'>".
"<input type=hidden name=IncCurrLabel value='$in_curr'>".
"<input type=hidden name=Culture value='$culture'>".
"<input type=hidden name=Receipt value='". urlencode($receipt) . "'>".
"<input type=submit class=checkout_button value='Перейти к оплате &#8594;'>".
"</form>";
return $button;
}

}
66 changes: 66 additions & 0 deletions payment/Robokassa/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,70 @@
<value>en</value>
</options>
</settings>

<settings>
<variable>sno</variable>
<name>Система налогообложения.</name>
<options>
<name>общая СН</name>
<value>osn</value>
</options>
<options>
<name>упрощенная СН (доходы)</name>
<value>usn_income</value>
</options>
<options>
<name>упрощенная СН (доходы минус расходы)</name>
<value>usn_income_outcome</value>
</options>
<options>
<name>единый налог на вмененный доход</name>
<value>envd</value>
</options>
<options>
<name>единый сельскохозяйственный налог</name>
<value>esn</value>
</options>
<options>
<name>патентная СН</name>
<value>patent</value>
</options>
</settings>

<settings>
<variable>tax</variable>
<name>НДС</name>
<options>
<name>без НДС</name>
<value>none</value>
</options>
<options>
<name>НДС по ставке 0%</name>
<value>vat0</value>
</options>
<options>
<name>НДС чека по ставке 10%</name>
<value>vat10</value>
</options>
<options>
<name>НДС чека по ставке 18%</name>
<value>vat18</value>
</options>
<options>
<name>НДС чека по расчетной ставке 10/110</name>
<value>vat110</value>
</options>
<options>
<name>НДС чека по расчетной ставке 18/118</name>
<value>vat118</value>
</options>
<options>
<name>НДС чека по ставке 20%</name>
<value>vat20</value>
</options>
<options>
<name>НДС чека по расчетной ставке 20/120</name>
<value>vat120</value>
</options>
</settings>
</module>

0 comments on commit 0bc19bc

Please sign in to comment.