コード例 #1
0
 /**
  * Process Pingback Request
  *
  * Validates the incoming POST/GET response from the gateway to ensure it is
  * legitimate and can be trusted.
  *
  * @param array $get The GET data for this request
  * @param array $post The POST data for this request
  * @return array An array of transaction data, sets any errors using Input if the data fails to validate
  *  - client_id The ID of the client that attempted the payment
  *  - amount The amount of the payment
  *  - currency The currency of the payment
  *  - invoices An array of invoices and the amount the payment should be applied to (if any) including:
  *    - id The ID of the invoice to apply to
  *    - amount The amount to apply to the invoice
  *    - status The status of the transaction (approved, declined, void, pending, reconciled, refunded, returned)
  *    - reference_id The reference ID for gateway-only use with this transaction (optional)
  *    - transaction_id The ID returned by the gateway to identify this transaction
  *    - parent_transaction_id The ID returned by the gateway to identify this transaction's original transaction (in the case of refunds)
  */
 public function validate(array $get, array $post)
 {
     $status = "error";
     $amount = 0;
     $currency = '';
     $this->initPaymentwallConfigs();
     $pingback = new Paymentwall_Pingback($_GET, $this->getRealClientIP());
     list($type, $client_id, $amount, $currency, $gateway_id, $company_id) = explode('|', $pingback->getProductId());
     if (!$amount or !$currency) {
         $this->Input->setErrors($this->getCommonError("invalid"));
     }
     if ($pingback->validate()) {
         if ($pingback->isDeliverable()) {
             $status = 'approved';
         } elseif ($pingback->isCancelable()) {
             $status = 'declined';
         }
     } else {
         $status = 'error';
     }
     // Log the response
     $this->log($this->ifSet($_SERVER['REQUEST_URI']), serialize($get), "output", true);
     // Clone function processNotification in class GatewayPayments
     // Process transaction after validate
     $this->processTransaction(array('client_id' => $pingback->getUserId(), 'amount' => $amount, 'currency' => $currency, 'status' => $status, 'reference_id' => null, 'transaction_id' => $pingback->getReferenceId(), 'parent_transaction_id' => null, 'invoices' => $this->unserializeInvoices($pingback->getParameter('invoice')), 'gateway_id' => $gateway_id, 'company_id' => $company_id));
 }
コード例 #2
0
 function check_ipn_response()
 {
     $_REQUEST['ipn'] = true;
     $signatureParams = $_GET;
     //These parameters are not necessary for calculating signature
     if (isset($signatureParams['wc-api']) && $signatureParams['wc-api'] != '') {
         unset($signatureParams['wc-api']);
     }
     if (isset($signatureParams['paymentwallListener']) && $signatureParams['paymentwallListener'] != '') {
         unset($signatureParams['paymentwallListener']);
     }
     $pingback = new Paymentwall_Pingback($signatureParams, $_SERVER['REMOTE_ADDR']);
     if ($pingback->validate()) {
         $goodsId = $pingback->getProduct()->getId();
         $reason = $pingback->getParameter('reason');
         $order = new WC_Order((int) $goodsId);
         global $woocommerce;
         if ($order->get_order($goodsId)) {
             if ($pingback->isCancelable()) {
                 $order->update_status('cancelled', __('Reason: ' . $reason, 'woocommerce'));
             } else {
                 $order->add_order_note(__('Paymentwall payment completed', 'woocommerce'));
                 $order->payment_complete();
                 $woocommerce->cart->empty_cart();
             }
             echo 'OK';
         } else {
             echo 'Paymentwall IPN Request Failure';
         }
     } else {
         echo $pingback->getErrorSummary();
     }
     return;
 }