在购买前发布到端点以获取重定向url

问题描述:

我正在尝试为名为creditguard的本地网关创建自定义的omnipay驱动程序。 对于此网关,您需要将数据发布到端点并获取付款表单的重定向网址。在购买前发布到端点以获取重定向url

我的问题是如何在购买前发布并获得响应?

编辑:

Gateway.php

class Gateway extends AbstractGateway 
{ 
    public function getName() 
    { 
     return 'Creditguard'; 
    } 

    public function getDefaultParameters() 
    { 
     return array(); 

    } 

    public function getEndpoint() 
    { 
     return 'https://verifonetest.creditguard.co.il/xpo/Relay'; 
    } 



    public function purchase(array $parameters = array()) 
    { 
     return $this->createRequest('\Nirz\Creditguard\Message\PurchaseRequest', $parameters); 

    } 

    public function completePurchase(array $parameters = array()) 
    { 
     return $this->createRequest('\Nirz\Creditguard\Message\CompletePurchaseRequest', $parameters); 
    } 

} 

PurchaseRequest.php

class PurchaseRequest extends AbstractRequest 
{ 
    protected $liveEndpoint = 'https://verifonetest.creditguard.co.il/xpo/Relay'; 
    protected $testEndpoint = 'https://verifonetest.creditguard.co.il/xpo/Relay'; 


    public function getData() 
    { 
     $this->validate('amount'); 

     // Either the nodifyUrl or the returnUrl can be provided. 
     // The returnUrl is deprecated, as strictly this is a notifyUrl. 
     if (!$this->getNotifyUrl()) { 
      $this->validate('returnUrl'); 
     } 

     $data = array(); 
     $data['user'] = 'user'; 
     $data['password'] = 'password'; 
     $data['tid'] = '11111111'; 
     $data['mid'] = '111111'; 
     $data['amount'] = '20000'; 
     $data['int_in'] = '<ashrait> 
          <request> 
          <version>1000</version> 
          <language>HEB</language> 
          <dateTime></dateTime> 
          <command>doDeal</command> 
          <doDeal> 
           <terminalNumber>'.$data['tid'].'</terminalNumber> 
           <mainTerminalNumber/> 
           <cardNo>CGMPI</cardNo> 
           <total>'.$data['amount'].'</total> 
           <transactionType>Debit</transactionType> 
           <creditType>RegularCredit</creditType> 
           <currency>ILS</currency> 
           <transactionCode>Phone</transactionCode> 
           <authNumber/> 
           <numberOfPayments/> 
           <firstPayment/> 
           <periodicalPayment/> 
           <validation>TxnSetup</validation> 
           <dealerNumber/> 
           <user>'. $data['user'] .'</user> 
           <mid>'.$data['mid'].'</mid> 
           <uniqueid>'.time().rand(100,1000).'</uniqueid> 
           <mpiValidation>autoComm</mpiValidation> 
           <email>[email protected]</email> 
           <clientIP/> 
           <customerData> 
            <userData1/> 
            <userData2/> 
            <userData3/> 
            <userData4/> 
            <userData5/> 
            <userData6/> 
            <userData7/> 
            <userData8/> 
            <userData9/> 
            <userData10/> 
           </customerData> 
          </doDeal> 
          </request> 
          </ashrait>'; 

     return $data; 
    } 

    public function sendData($data) 
    { 
     // $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data); 
     return $this->response = new PurchaseResponse($this, $data); 
    } 

    public function getEndpoint() 
    { 
     return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; 
    } 
} 

PurchaseResponse.php

class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface 
{ 
    public function isSuccessful() 
    { 
     return false; 
    } 

    public function isRedirect() 
    { 
     return true; 
    } 

    public function getRedirectUrl() 
    { 
     // return $this->getRequest()->getEndpoint().'?'.http_build_query($this->data); 
     return $this->getRequest()->data['mpiHostedPageUrl']; 
     // return isset($this->data['mpiHostedPageUrl']) ? $this->data['mpiHostedPageUrl'] : null; 
    } 

    public function getRedirectMethod() 
    { 
     return 'GET'; 
    } 

    public function getRedirectData() 
    { 
     return []; 

    } 
} 

不知道如何得到响应的mpiHostedPageU所以我可以重定向到正确的网址。

+0

你的问题不是很清楚,你能否多描述一下? – 16ctt1x

+0

我想了解的是如何发出无重定向的发布请求,获取响应数据,然后重定向到付款表单。我正在尝试使用Omnipay - http://omnipay.thephpleague.com/。 – nirz

HATEOAS(超媒体作为应用程序状态引擎)是一种组织REST应用程序响应的方法。 在HATEOAS世界中,响应JSON可能包含客户端可能需要的所有URL。例如,在github API中,响应包含用于访问存储库,用户,请求的URL ...

因此,我建议您使用第一个POST请求调用网关,然后根据JSON响应提供将代表重定向的URL。

+0

谢谢,但我特别要求与omnipay做这个 - http://omnipay.thephpleague.com/ – nirz

另一种解决方案可能是使用ZUUL网关(在Spring-Boot中),它将为您执行重定向。

您可以在这里找到一个描述:https://spring.io/guides/gs/routing-and-filtering/

假设this是有问题的支付网关的文档。

您只需继续并提交交易请求,客户将不会被收费,因为他们必须输入付款详细信息才能在下一页上对其进行授权。

该事务请求的响应包含一个元素mpiHostedPageUrl,您可以在该文档的第13页上看到该元素,其中包含您需要从响应中获取以提供重定向的URL。

+0

谢谢亚当,这是正确的文档。 mpiHostedPageUrl确实是我在购买请求后试图找到的东西,我只是不明白如何获得它以及在自定义omnipay驱动程序的哪个阶段 – nirz

+0

在这种情况下,您需要提供代码以显示在消费者的反应方面。 –

+0

在原始文章中添加了代码 – nirz