Skip to content

Commit

Permalink
Исправлен баг со сменной статуса у p2p платежей.
Browse files Browse the repository at this point in the history
  • Loading branch information
Павел А. Молодовский committed Sep 2, 2019
1 parent 76b919c commit e21e954
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v1.0.21 от 02.09.2019
* Исправлен баг со сменной статуса у p2p платежей.

### v1.0.20 от 15.08.2019
* Исправление багов.

Expand Down
21 changes: 18 additions & 3 deletions transactions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*/
class YAMoneyApiTransaction extends stdClass {
const STATUS_IN_PROCESS = 'in_process';
const STATUS_PROCESSED = 'processed';
const STATUS_PAYED = 'payed';
const STATUS_FAILED = 'failed';
const STATUS_PROCESSED = 'processed';
const STATUS_PAYED = 'payed';
const STATUS_FAILED = 'failed';
const STATUS_COMPLETED = 'completed';

/**
* @var int Transaction id.
Expand Down Expand Up @@ -152,11 +153,25 @@ function yamoney_api_transaction_save(YAMoneyApiTransaction $transaction) {
$id = db_insert('yamoney_api_transaction')
->fields($fields)
->execute();

$transaction->ymid = $id;
return !!$id;
}
}

/**
* Simply set transaction payment_id.
* @param $ymid string Transaction id
* @param $payment_id string Payment id
* @return bool
*/
function yamoney_api_update_transaction_payment_id($ymid, $payment_id) {
return !!db_update('yamoney_api_transaction')
->fields(array('payment_id' => $payment_id))
->condition('ymid', $ymid)
->execute();
}

/**
* Simply set transaction status.
* @param $payment_id string Transaction id in Kassa
Expand Down
48 changes: 48 additions & 0 deletions ya_commerce/ya_commerce_api.module
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,20 @@ function ya_commerce_api_yamoney_api_process_payment_alter(&$payment)
/** @var YAMoneyApiTransaction $transaction */
$transaction = $payment['transaction'];
$order = commerce_order_load($transaction->order_id);

if ($order) {
$paymentId = $transaction->ymid;
yamoney_api_update_transaction_payment_id($transaction->ymid, $paymentId);
$transaction->status = yamoney_api_update_transaction_status($transaction->ymid, YAMoneyApiTransaction::STATUS_COMPLETED);
ya_commerce_create_commerce_transaction(
$transaction,
COMMERCE_PAYMENT_STATUS_SUCCESS,
'',
array(),
$payment['request']
);
commerce_order_status_update($order, YAMoneyApiTransaction::STATUS_COMPLETED);

$payment['success'] = true;
} else {
$payment['success'] = false;
Expand All @@ -604,6 +610,48 @@ function ya_commerce_api_get_checkout_url($order, $success = true)
);
}

/**
* @param YAMoneyTransaction $transaction
* @param string $status
* @param string $message
* @param array $message_params
* @param null $request
*
* @return bool
*/
function ya_commerce_create_commerce_transaction(
YAMoneyApiTransaction $transaction,
$status,
$message = '',
$message_params = array(),
$request = null
) {
$order = commerce_order_load($transaction->order_id);

$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$currency_code = $order_wrapper->commerce_order_total->currency_code->value();
$payment_method_instance_id = 'ya_commerce|commerce_payment_ya_commerce';

// Prepare a transaction object to log the API response.
$commerce_transaction = commerce_payment_transaction_new($payment_method_instance_id, $order->order_id);
$commerce_transaction->instance_id = $payment_method_instance_id;
$commerce_transaction->uid = $transaction->uid;
$commerce_transaction->remote_id = $transaction->ymid;
$commerce_transaction->message = $message;
$commerce_transaction->message_variables = $message_params;
$commerce_transaction->amount = $transaction->amount * 100;
$commerce_transaction->currency_code = $currency_code;
$commerce_transaction->status = $status;
$commerce_transaction->remote_status = $transaction->status;

if ($request) {
$commerce_transaction->payload[REQUEST_TIME] = $request;
}

// Save the transaction information.
return !!commerce_payment_transaction_save($commerce_transaction);
}

function ya_commerce_api_get_return_url($order)
{
return url(
Expand Down
2 changes: 1 addition & 1 deletion ya_ubercart/ya_ubercart_api.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name = Yandex Ubercart Api
description = "Yandex.Money module for Ubercart."
package = Yandex.Money 2.0
core = 7.x
version = 1.0.20
version = 1.0.21
dependencies[] = yamoney_api
dependencies[] = uc_payment
2 changes: 1 addition & 1 deletion yamoney_api.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ function yamoney_api_admin_settings()
'#type' => 'textfield',
'#title' => t('RedirectURL'),
'#attributes' => array('disabled' => 'disabled'),
'#default_value' => url('yamoney/check_wallet', array('absolute' => true)),
'#default_value' => url('yamoney_api/check_wallet', array('absolute' => true)),
'#description' => t(
"Copy this link to the upper field at the <a href='https://sp-money.yandex.ru/myservices/online.xml' target='_blank'>HTTP notifications page</a>"
),
Expand Down
2 changes: 1 addition & 1 deletion yamoney_api.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name = Yandex.Money Core 2.0
description = Yandex.Money 2.0 core module.
package = Yandex.Money 2.0
core = 7.x
version = 1.0.20
version = 1.0.21
configure = admin/config/system/yamoney_api
36 changes: 24 additions & 12 deletions yamoney_api.module
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ define('YAMONEY_API_CHECK_RESULT_CODE_ERROR_MD5', 1);
define('YAMONEY_API_CHECK_RESULT_CODE_ERROR_CUSTOM', 100);
define('YAMONEY_API_CHECK_RESULT_CODE_ERROR_REQUEST', 200);
define('YAMONEY_API_DEFAULT_TAX_RATE_ID', 1);
define('YAMONEY_MODULE_VERSION', '1.0.20');
define('YAMONEY_MODULE_VERSION', '1.0.21');
define('YAMONEY_API_DEFAULT_PAYMENT_METHOD', \YandexCheckout\Model\PaymentMethodType::BANK_CARD);
define('QUICK_API_PAY_VERSION', 2);
define('INSTALLMENTS_MIN_AMOUNT', 3000);
Expand Down Expand Up @@ -64,8 +64,8 @@ function yamoney_api_menu()

// Secret transaction status url
$items['yamoney_api/check_wallet'] = array(
'page callback' => 'yamoney_check_wallet',
'access callback' => 'yamoney_check_server_ip',
'page callback' => 'yamoney_api_check_wallet',
'access callback' => 'yamoney_api_check_server_ip',
'type' => MENU_CALLBACK,
);
// Config page
Expand Down Expand Up @@ -584,22 +584,31 @@ function yamoney_api_create_md5($params = array())
function yamoney_api_check_wallet()
{

if (!isset($_POST['transaction_id'])) {
if (!isset($_POST['label'])) {
http_response_code(404);

return;
}

$string = $_POST['notification_type'].'&'.$_POST['operation_id'].'&'.$_POST['amount'].'&'.$_POST['currency'].
'&'.$_POST['datetime'].'&'.$_POST['sender'].'&'.$_POST['codepro'].'&'.
variable_get('yamoney_api_secret', '').'&'.$_POST['label'];
if (sha1($string) !== $_POST['sha1_hash']) {
http_response_code(401);
$secretWord = variable_get('yamoney_secret', '');

$string = $_POST['notification_type']
. '&' . $_POST['operation_id']
. '&' . $_POST['amount']
. '&' . $_POST['currency']
. '&' . $_POST['datetime']
. '&' . $_POST['sender']
. '&' . $_POST['codepro']
. '&' . $secretWord
. '&' . $_POST['label'];

if(sha1($string) !== $_POST['sha1_hash']){
http_response_code (401);
return;
}

$transaction = yamoney_api_transaction_load($_POST['transaction_id']);
$transaction = yamoney_api_transaction_load($_POST['label']);

if (!$transaction) {
http_response_code(404);

Expand All @@ -612,7 +621,9 @@ function yamoney_api_check_wallet()
return;
}

if ($transaction->status !== YAMoneyApiTransaction::STATUS_PROCESSED && $transaction->status !== YAMoneyApiTransaction::STATUS_PAYED) {
if ($transaction->status !== YAMoneyApiTransaction::STATUS_PROCESSED
&& $transaction->status !== YAMoneyApiTransaction::STATUS_PAYED
&& $transaction->status !== YAMoneyApiTransaction::STATUS_IN_PROCESS) {
http_response_code(401);

return;
Expand All @@ -623,6 +634,7 @@ function yamoney_api_check_wallet()
'transaction' => $transaction,
'request' => $_POST,
);

drupal_alter('yamoney_api_process_payment', $payment);
}

Expand Down Expand Up @@ -785,7 +797,7 @@ function yamoney_api_get_quick_params(YAMoneyApiTransaction $transaction)
$params['short-dest'] = t('Payments for order No').$transaction->order_id;
$params['writable-targets'] = false;
$params['comment-needed'] = false;
$params['label'] = $transaction->order_id;
$params['label'] = $transaction->ymid;
$params['order_id'] = (int)$transaction->order_id;
$params['successUrl'] = url('yamoney_api/complete', array('absolute' => true));
$params['targets'] = t('Payments for order No').$transaction->order_id;
Expand Down
Binary file modified yandex-money-cms-v2-drupal.zip
Binary file not shown.

0 comments on commit e21e954

Please sign in to comment.