示例#1
0
 /**
  * @param IpnEntity $ipn
  * @return bool
  */
 public function forwardIpn(IpnEntity $ipn)
 {
     $urls = $ipn->getForwardUrls();
     if (!empty($urls)) {
         $requests = [];
         foreach ($urls as $url) {
             $request = $this->guzzle->createRequest('post', $url);
             $request->setHeader($this->customHeader, $this->getKey());
             if (in_array($url, $this->disabledJsonFormatting)) {
                 $request->getQuery()->merge($ipn->toArray());
             } else {
                 $request->setHeader('content-type', 'application/json');
                 if ($this->formatter) {
                     $response = $this->formatter->formatJsonResponse($ipn);
                 } else {
                     $response = ['ipn' => $ipn->toArray()];
                 }
                 $request->setBody(Stream::factory(json_encode($response)));
             }
             $requests[] = $request;
         }
         $this->guzzle->sendAll($requests, ['parallel' => $this->maxRequests]);
         return true;
     }
     return false;
 }
 public function formatJsonResponse(IpnEntity $ipn)
 {
     $response = ['status' => 'ok', 'code' => 200, 'data' => ['transaction_id' => $ipn->txn_id, 'transaction_type' => $ipn->txn_type, 'matches' => $ipn->getInvoiceMatches(), 'ipn' => $ipn->jsonSerialize(), 'timestamp' => date('Y-m-d h:i:s', time())]];
     if ($this->httpRequest) {
         $response['data'] = $this->setRequestData($response['data']);
     }
     return $response;
 }
示例#3
0
 /**
  * @param IpnEntity $ipn
  * @return array|bool
  */
 protected function respondToValidIpn(IpnEntity $ipn)
 {
     $urls = $this->urlCollection->findListeners($ipn->invoice);
     $ipn->setInvoiceMatches($this->urlCollection->getMatchedParts());
     if ($urls) {
         $ipn->setForwardUrls($urls);
         foreach ($this->subscribers as $subscriber) {
             $subscriber->onValidIpn($ipn);
         }
     }
     return $urls;
 }
示例#4
0
 /**
  * @param IpnEntity $ipn
  * @param $logData
  * @return array
  */
 protected function makeForwardedResponse($logData, $ipn)
 {
     $msg = 'Notified ' . count($ipn->getForwardUrls()) . ' urls.';
     $response = ['status' => 'ok', 'msg' => $msg];
     $this->log($msg, $logData);
     return $response;
 }