Skip to content

Commit

Permalink
Increment id fix
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ddly committed Apr 25, 2024
1 parent aa952b9 commit 80973fc
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 15 deletions.
25 changes: 10 additions & 15 deletions Model/Resolver/CreateTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,21 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value
return null;
}

$args = $args['input'] ?? [];

if (!empty($args['real_order_id'])) {
$orderId = $args['real_order_id'];
} else {
if (!isset($value['order_number'])) {
return null;
}
if (!isset($value['order_number'])) {
return null;
}

$orderId = $this->checkoutSession->getLastRealOrderId();
$orderId = $this->checkoutSession->getLastOrderId();

if (!$orderId) {
return null;
}
if (!$orderId) {
return null;
}

try {
$order = $this->orderRepository->getByIncrementId($orderId);
$order = $this->orderRepository->get($orderId);
/** @var Payment $payment */
$payment = $order->getPayment();

if (TpayInterface::CODE !== $payment->getMethod()) {
return null;
}
Expand All @@ -88,13 +83,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value
if (isset($transaction['transactionId'])) {
$paymentData['additional_information']['transaction_id'] = $transaction['transactionId'];
}
$this->tpayService->addCommentToHistory($orderId, 'Transaction title '.$transaction['title']);
$this->tpayService->addCommentToHistory($order->getIncrementId(), 'Transaction title '.$transaction['title']);

if (true === $this->tpayConfig->redirectToChannel()) {
$transactionUrl = str_replace('gtitle', 'title', $transactionUrl);
}

$this->tpayService->addCommentToHistory($orderId, 'Transaction link '.$transactionUrl);
$this->tpayService->addCommentToHistory($order->getIncrementId(), 'Transaction link '.$transactionUrl);
$paymentData['additional_information']['transaction_url'] = $transactionUrl;
$payment->setData($paymentData);
$this->tpayService->saveOrderPayment($payment);
Expand Down
37 changes: 37 additions & 0 deletions Plugin/UrlOverride.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Tpay\Magento2GraphQl\Plugin;

use Tpay\Magento2\Provider\ConfigurationProvider;
use Tpay\Magento2\Model\TpayPayment;

class UrlOverride
{
private ConfigurationProvider $tpayConfig;

public function __construct(ConfigurationProvider $tpayConfig)
{
$this->tpayConfig = $tpayConfig;
}

public function afterGetTpayFormData(TpayPayment $subject, $result, $name, $storeId = 0)
{
$successUrl = $this->tpayConfig->getConfigData('graphql_url_override/success_url', $storeId);
$errorUrl = $this->tpayConfig->getConfigData('graphql_url_override/error_url', $storeId);
$notificationUrl = $this->tpayConfig->getConfigData('graphql_url_override/notification_url', $storeId);

if(!empty($successUrl)){
$result['return_url'] = $successUrl;
}

if(!empty($errorUrl)){
$result['return_error_url'] = $errorUrl;
}

if(!empty($notificationUrl)){
$result['result_url'] = $notificationUrl;
}

return $result;
}
}
31 changes: 31 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!--
/**
*
* @category payment gateway
* @package Tpaycom_Magento2.3
* @author Tpay.com
* @copyright (https://tpay.com)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="payment">
<group id="tpaycom_magento2basic" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="graphql_url_override" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>GraphQL Settings</label>
<attribute type="expanded">1</attribute>
<field id="success_url" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Success URL</label>
</field>
<field id="error_url" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Error URL</label>
</field>
<field id="notification_url" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Notification URL</label>
</field>
</group>
</group>
</section>
</system>
</config>
7 changes: 7 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Tpay\Magento2\Model\TpayPayment">
<plugin name="tpay_magento2graphql_plugin_override_urls"
type="Tpay\Magento2GraphQl\Plugin\UrlOverride" sortOrder="10" />
</type>
</config>

0 comments on commit 80973fc

Please sign in to comment.