*  other liability, whether in an action of contract, tort or otherwise,
 *  arising from, out of or in connection with the software or the use
 *  of other dealings in the software.
 *
 */
/*  Define your ICEPAY Merchant ID and Secret code. The values below are sample values and will not work, Change them to your own merchant settings. */
define('MERCHANTID', 12345);
//<--- Change this into your own merchant ID
define('SECRETCODE', "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
//<--- Change this into your own merchant ID
define('PAYMENTID', 1234567);
// <--- Change this into the payment ID
// Include the API into your project
require_once '../api/icepay_api_webservice.php';
$payment = Icepay_Api_Webservice::getInstance()->paymentService();
$logger = Icepay_Api_Logger::getInstance();
try {
    // Merchant Settings
    $payment->setMerchantID(MERCHANTID)->setSecretCode(SECRETCODE);
    /* Apply logging rules */
    $logger->enableLogging()->setLoggingLevel(Icepay_Api_Logger::LEVEL_ALL)->logToFile()->setLoggingDirectory(realpath("../logs"))->setLoggingFile("getpayment.txt")->logToScreen()->log('Sample log entry for sample_webservice_getpayment.php', Icepay_Api_Logger::NOTICE);
} catch (Exception $e) {
    echo $e->getMessage();
}
?>

<pre>
<?php 
try {
    var_dump($payment->getPayment(PAYMENTID));
} catch (Exception $e) {
Exemplo n.º 2
0
 /**
  * Handler when cart/icepay_result is callback
  *
  * @return string
  */
 public function runPageCartResult()
 {
     $logger = \Icepay_Api_Logger::getInstance();
     $logger->enableLogging()->setLoggingLevel(\Icepay_Api_Logger::LEVEL_ERRORS_AND_TRANSACTION)->logToFunction("logWrapper", "log");
     $config = \Drupal::config("uc_icepay.settings");
     /* postback */
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $icepay = \Icepay_Project_Helper::getInstance()->postback();
         $icepay->setMerchantID($config->get("merchant_id"))->setSecretCode($config->get("secret_code"))->doIPCheck(true);
         if ($config->get("ipcheck") && $config->get("ipcheck_list") != '') {
             $ipRanges = explode(",", $config->get("ipcheck_list"));
             foreach ($ipRanges as $ipRange) {
                 $ip = explode("-", $ipRange);
                 $icepay->setIPRange($ip[0], $ip[1]);
             }
         }
         if ($icepay->validate()) {
             $data = $icepay->GetPostback();
             $orderID = $data->reference;
             $order = uc_order_load($orderID);
             if (!$order) {
                 return t("Order not exists");
             }
             $firstPostback = Database::getConnection()->select('uc_payment_icepay', 'i')->fields('i', array('transaction_id'))->condition('transaction_id', $data->transactionID, '=')->execute()->fetchAssoc();
             $paymentDetails = IcepayApi::getPaymentDetailsByOrderId($orderID);
             if ($icepay->canUpdateStatus($paymentDetails->icepay_status)) {
                 $order->icepay_status = $data->status;
                 $order->transaction_id = $data->transactionID;
                 IcepayApi::enterPayment($order);
                 // updating order status, this one is deprecated
                 //uc_order_update_status($orderID, IcepayApi::getUbercartStatusCode($data->status));
                 // updating order status, using direct save into order
                 $order->setStatusId(IcepayApi::getUbercartStatusCode($data->status))->save();
             }
             // adding new comment order
             uc_order_comment_save($orderID, 1, t($data->statusCode), 'order', IcepayApi::getUbercartStatusCode($data->status), true);
             // need to save into order payment if postback from Icepay is confirming payment received
             // @see Drupal/uc_payment/Form/OrderPaymentsForm::submitForm()
             if (strtoupper($data->status) == "OK" || strtoupper($data->status) == "REFUND") {
                 $orderTotal = $order->getTotal();
                 // when refund, means order total is requested back
                 if (strtoupper($data->status) == "REFUND") {
                     $orderTotal *= -1;
                 }
                 uc_payment_enter($orderID, $paymentDetails->payment_method, $orderTotal, \Drupal::currentUser()->id(), '', $data->statusCode, REQUEST_TIME);
             }
             // best to record this into watch log
             // https://drupalize.me/blog/201510/how-log-messages-drupal-8
             \Drupal::logger('uc_icepay')->info('Icepay Postback :: ' . $data->statusCode);
             // need to send notification due to order status update
             if (isset($firstPostback['transaction_id'])) {
                 // this rules invoke to send order status update by email is deprecated
                 //rules_invoke_event('uc_order_status_email_update', $order);
             }
         } else {
             if ($icepay->isVersionCheck()) {
                 $dump = array("module" => sprintf(t("Version %s using PHP API 2 version %s"), ICEPAY_VERSION, Icepay_Project_Helper::getInstance()->getReleaseVersion()), "notice" => "Checksum validation passed!");
                 if ($icepay->validateVersion()) {
                     $name = "uc_cart";
                     $path = drupal_get_path('module', $name) . '/' . $name . '.info';
                     $data = drupal_parse_info_file($path);
                     $dump["additional"] = array("Drupal" => VERSION, "Ubercart" => $data["version"]);
                 } else {
                     $dump["notice"] = "Checksum failed! Merchant ID and Secret code probably incorrect.";
                 }
                 var_dump($dump);
                 exit;
             }
         }
         return t("Postback script functions properly");
     } else {
         $icepay = \Icepay_Project_Helper::getInstance()->result();
         $icepay->setMerchantID($config->get("merchant_id"))->setSecretCode($config->get("secret_code"));
         if (!$icepay->validate()) {
             $data = $icepay->getResultData();
             //$output = $data->statusCode;
             //return $output;
             drupal_set_message($data->statusCode, 'error');
             $response = new RedirectResponse(\Drupal::url('uc_cart.checkout'));
             $response->send();
         } else {
             $data = $icepay->getResultData();
             if ($data->status == 'ERR') {
                 //$output = $data->statusCode;
                 //return $output;
                 drupal_set_message($data->statusCode, 'error');
                 return new RedirectResponse(\Drupal::url('uc_cart.checkout'));
             }
             $order = uc_order_load($data->reference);
             if (!$order) {
                 return t("Order with id :orderId not exist", array(":orderId" => $data->reference));
             }
             $session = \Drupal::service('session');
             if (!$session->get('cart_order')) {
                 drupal_set_message(t("Cart is currently empty."), 'error');
                 return new RedirectResponse(\Drupal::url('uc_cart.checkout'));
             }
             //$order->icepay_status = \ICEPAY_STATUSCODE::SUCCESS;
             $order->icepay_status = $data->status;
             $order->transaction_id = $data->transactionID;
             IcepayApi::enterPayment($order);
             // update order status
             $order->setStatusId(IcepayApi::getUbercartStatusCode($data->status))->save();
             $_SESSION['uc_checkout'][$session->get('cart_order')]['do_complete'] = TRUE;
             //        $response = new RedirectResponse(Url::fromRoute('uc_cart.checkout_complete')->toString());
             //        $response->send();
             return new RedirectResponse(\Drupal::url('uc_cart.checkout_complete'));
         }
     }
 }
Exemplo n.º 3
0
 public function __construct()
 {
     $this->_logger = Icepay_Api_Logger::getInstance();
     $this->data = new stdClass();
 }
Exemplo n.º 4
0
 public function setupFileLogger($dir, $file)
 {
     /** @var \Icepay_Api_Logger $logger */
     $logger = \Icepay_Api_Logger::getInstance();
     $logger->enableLogging()->logToFile()->setLoggingDirectory($dir)->setLoggingFile($file);
 }