0

I want to get payment request in Test\Testpayment\Gateway\Request

Request.php

 namespace Test\Testpayment\Gateway\Request;
 use Magento\Payment\Gateway\ConfigInterface;
 use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
 use Magento\Payment\Gateway\Request\BuilderInterface;

  class PaymentDataBuilder implements BuilderInterface
  {
/**
 * @inheritdoc
 */
public function build(array $buildSubject)
{
    $paymentDO = $this->subjectReader->readPayment($buildSubject);
    $payment = $paymentDO->getPayment();
    $order = $paymentDO->getOrder();

    $result = [
        self::AMOUNT => $this->formatPrice($this->subjectReader->readAmount($buildSubject)),
        self::PAYMENT_METHOD_NONCE => $payment->getAdditionalInformation(
            DataAssignObserver::PAYMENT_METHOD_NONCE
        ),
        self::ORDER_ID => $order->getOrderIncrementId()
    ];

    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/nitesh.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);
    $logger->info('data'.print_r($result, true));

    return $result;
 }
}

DataAssignObserver.php

 namespace Test\Testpayment\Observer;
 use Magento\Framework\Event\Observer;
 use Magento\Payment\Observer\AbstractDataAssignObserver;

 class DataAssignObserver extends AbstractDataAssignObserver
 {
  const PAYMENT_METHOD_NONCE = 'testpayment';

/**
 * @var array
 */
protected $additionalInformationList = [
    self::PAYMENT_METHOD_NONCE,
];

/**
 * @param Observer $observer
 * @return void
 */
public function execute(Observer $observer)
{
    $data = $this->readDataArgument($observer);

    $method = $this->readMethodArgument($observer);

    $paymentInfo = $method->getInfoInstance();

    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/nitesh.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);
    $logger->info('data'.print_r($data, true));
    $logger->info('method'.print_r($data->getData(PaymentInterface::KEY_ADDITIONAL_DATA), true));
    die();

    $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
    if (!is_array($additionalData)) {
        return;
    }

    $paymentInfo = $this->readPaymentModelArgument($observer);

    foreach ($this->additionalInformationList as $additionalInformationKey) {
        if (isset($additionalData[$additionalInformationKey])) {
            $paymentInfo->setAdditionalInformation(
                $additionalInformationKey,
                $additionalData[$additionalInformationKey]
            );
        }
    }
} 

getting error on $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA)

Observer/DataAssignObserver.php' on line 34","trace":"Trace is not available."

events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="payment_method_assign_data_testpayment">
    <observer name="testpayment_gateway_data_assign" instance="Test\Testpayment\Observer\DataAssignObserver" />
</event>
</config>

I want to use PhonePe API

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://apps-uat.phonepe.com/v3/transaction/initiate");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-VERIFY: ' . $xVerify,
    'X-CLIENT-ID: ' . $payload['merchantId'],
    'Content-Type: application/json',
    'X-CALLBACK-URL: https://localhost/tnm/status.php'
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
$data = curl_exec($ch);
curl_close($ch);
3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.