public function getConvertAmount()
 {
     $Api = CheckoutApi_Api::getApi(array('mode' => $this->getConfigData('mode')));
     $currencyDesc = Mage::app()->getStore()->getCurrentCurrencyCode();
     $amount = $Api->valueToDecimal($this->_getQuote()->getGrandTotal(), $currencyDesc);
     return $amount;
 }
Ejemplo n.º 2
0
 /**
  * @param Varien_Object $payment
  * @param $amount
  * @param array $extraConfig
  * @return mixed
  */
 protected function _createCharge(Varien_Object $payment, $amount, $extraConfig = array())
 {
     $config = array();
     $scretKey = $this->getConfigData('privatekey');
     $order = $payment->getOrder();
     $billingAddress = $order->getBillingAddress();
     $shippingAddress = $order->getBillingAddress();
     $orderedItems = $order->getAllItems();
     $currencyDesc = $order->getBaseCurrencyCode();
     $orderId = $order->getIncrementId();
     $Api = CheckoutApi_Api::getApi(array('mode' => $this->getConfigData('mode')));
     $amountCents = $Api->valueToDecimal($amount, $currencyDesc);
     $street = Mage::helper('customer/address')->convertStreetLines($billingAddress->getStreet(), 2);
     $billingAddressConfig = array('addressLine1' => $street[0], 'addressLine2' => $street[1], 'postcode' => $billingAddress->getPostcode(), 'country' => $billingAddress->getCountry(), 'city' => $billingAddress->getCity(), 'phone' => array('number' => $billingAddress->getTelephone()));
     $street = Mage::helper('customer/address')->convertStreetLines($shippingAddress->getStreet(), 2);
     $shippingAddressConfig = array('addressLine1' => $street[0], 'addressLine2' => $street[1], 'postcode' => $shippingAddress->getPostcode(), 'country' => $shippingAddress->getCountry(), 'city' => $shippingAddress->getCity(), 'phone' => array('number' => $shippingAddress->getTelephone()), 'recipientName' => $shippingAddress->getFirstname() . ' ' . $shippingAddress->getLastname());
     $products = array();
     foreach ($orderedItems as $item) {
         $product = Mage::getModel('catalog/product')->load($item->getProductId());
         $products[] = array('name' => $item->getName(), 'sku' => $item->getSku(), 'price' => $item->getPrice(), 'quantity' => $item->getQtyOrdered(), 'image' => Mage::helper('catalog/image')->init($product, 'image')->__toString());
     }
     $config = array();
     $config['authorization'] = $scretKey;
     $config['mode'] = $this->getConfigData('mode');
     $config['timeout'] = $this->getConfigData('timeout');
     $config['postedParam'] = array('value' => $amountCents, 'currency' => $currencyDesc, 'shippingDetails' => $shippingAddressConfig, 'products' => $products, 'description' => "Order number::{$orderId}", 'metadata' => array("trackId" => $orderId), 'card' => array('billingDetails' => $billingAddressConfig));
     $config['postedParam'] = array_merge($config['postedParam'], $extraConfig);
     return $config;
 }
 function _process()
 {
     $config['chargeId'] = $_GET['chargeId'];
     $config['authorization'] = MODULE_PAYMENT_CHECKOUTAPIPAYMENT_SECRET_KEY;
     $Api = CheckoutApi_Api::getApi(array('mode' => MODULE_PAYMENT_CHECKOUTAPIPAYMENT_TRANSACTION_SERVER));
     $respondBody = $Api->getCharge($config);
     $json = $respondBody->getRawOutput();
     return $json;
 }
 /**
  * @param Varien_Object $payment
  * @param $amount
  * @param array $extraConfig
  * @return mixed
  */
 protected function _createCharge(Varien_Object $payment, $amount, $extraConfig = array())
 {
     /** @var CheckoutApi_Client_ClientGW3  $Api */
     $Api = CheckoutApi_Api::getApi(array('mode' => $this->getConfigData('mode')));
     $config = parent::_createCharge($payment, $amount, $extraConfig);
     $config['paymentToken'] = $payment->getAdditionalInformation('cko_cc_paymenToken');
     $config['authorization'] = $this->getConfigData('privatekey');
     return $Api->verifyChargePaymentToken($config);
 }
 /**
  * @param String $requestUri
  * @param String $authenticationKey
  * @param string|null $requestPayload
  */
 public static function deleteRequest($requestUri, $authenticationKey, $requestPayload = null)
 {
     $requestPayload['method'] = 'DELETE';
     $temp = \CheckoutApi_Api::getApi()->request($requestUri, $requestPayload, true);
     if ($temp && $temp->isValid()) {
         return $temp;
     } else {
         throw new \Exception($temp->getExceptionState()->getErrorMessage());
     }
 }
 public function _createCharge($config)
 {
     global $module_params;
     $config = array();
     $config['authorization'] = $module_params['param02'];
     $config['timeout'] = $module_params['param08'];
     $config['paymentToken'] = $_POST['cko-cc-paymenToken'];
     $Api = CheckoutApi_Api::getApi(array('mode' => $module_params['param01']));
     return $Api->verifyChargePaymentToken($config);
 }
 /**
  * @param Varien_Object $payment
  * @param $amount
  * @param array $extraConfig
  * @return mixed
  */
 protected function _createCharge(Varien_Object $payment, $amount, $extraConfig = array())
 {
     /** @var CheckoutApi_Client_ClientGW3  $Api */
     $Api = CheckoutApi_Api::getApi(array('mode' => $this->getConfigData('mode')));
     $order = $payment->getOrder();
     $billingAddress = $order->getBillingAddress();
     $config = parent::_createCharge($payment, $amount, $extraConfig);
     $config['postedParam']['email'] = $billingAddress->getData('email');
     $config['postedParam']['card'] = array_merge(array('phoneNumber' => $billingAddress->getData('telephone'), 'name' => $payment->getCcOwner(), 'number' => $payment->getCcNumber(), 'expiryMonth' => (int) $payment->getCcExpMonth(), 'expiryYear' => (int) $payment->getCcExpYear(), 'cvv' => $payment->getCcCid()), $config['postedParam']['card']);
     return $Api->createCharge($config);
 }
 public function after_process()
 {
     global $insert_id, $customer_id, $stripe_result;
     if ($this->_currentCharge) {
         $status_comment = array('Transaction ID: ' . $this->_currentCharge->getId(), 'Transaction has been process using "' . MODULE_PAYMENT_CHECKOUTAPIPAYMENT_TEXT_PUBLIC_TITLE . '" and paid with  card ' . $this->_currentCharge->getCard()->getPaymentMethod(), 'Response code:' . $this->_currentCharge->getResponseCode(), 'Response Message: ' . $this->_currentCharge->getResponseMessage());
         $sql_data_array = array('orders_id' => $insert_id, 'orders_status_id' => MODULE_PAYMENT_CHECKOUAPIPAYMENT_REVIEW_ORDER_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => '0', 'comments' => implode("\n", $status_comment));
         $Api = CheckoutApi_Api::getApi(array('mode' => MODULE_PAYMENT_CHECKOUTAPIPAYMENT_TRANSACTION_SERVER, 'authorization' => MODULE_PAYMENT_CHECKOUTAPIPAYMENT_SECRET_KEY));
         $chargeUpdated = $Api->updateTrackId($this->_currentCharge, $insert_id);
         zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
     }
     $this->_currentCharge = '';
 }
 public function getPaymentTokenResult()
 {
     $Api = CheckoutApi_Api::getApi(array('mode' => $this->getConfigData('mode')));
     $secretKey = $this->getConfigData('privatekey');
     $billingAddress = $this->_getQuote()->getBillingAddress();
     $shippingAddress = $this->_getQuote()->getBillingAddress();
     $orderedItems = $this->_getQuote()->getAllItems();
     $currencyDesc = Mage::app()->getStore()->getCurrentCurrencyCode();
     $amountCents = $this->getAmount();
     $street = Mage::helper('customer/address')->convertStreetLines($shippingAddress->getStreet(), 2);
     $shippingAddressConfig = array('addressLine1' => $street[0], 'addressLine2' => $street[1], 'postcode' => $shippingAddress->getPostcode(), 'country' => $shippingAddress->getCountry(), 'city' => $shippingAddress->getCity());
     $products = array();
     foreach ($orderedItems as $item) {
         $product = Mage::getModel('catalog/product')->load($item->getProductId());
         $products[] = array('name' => $item->getName(), 'sku' => $item->getSku(), 'price' => $item->getPrice(), 'quantity' => $item->getQty(), 'image' => Mage::helper('catalog/image')->init($product, 'image')->__toString());
     }
     $config = array();
     $config['authorization'] = $secretKey;
     $config['mode'] = $this->getConfigData('mode');
     $config['timeout'] = $this->getConfigData('timeout');
     $street = Mage::helper('customer/address')->convertStreetLines($billingAddress->getStreet(), 2);
     $billingAddressConfig = array('addressLine1' => $street[0], 'addressLine2' => $street[1], 'postcode' => $billingAddress->getPostcode(), 'country' => $billingAddress->getCountry(), 'city' => $billingAddress->getCity(), 'phone' => array('number' => $billingAddress->getTelephone()));
     $config['postedParam'] = array('value' => $amountCents, "chargeMode" => 1, 'currency' => $currencyDesc, 'shippingDetails' => $shippingAddressConfig, 'products' => $products, 'metadata' => array('server' => Mage::helper('core/http')->getHttpUserAgent(), 'quoteId' => $this->_getQuote()->getId()));
     if ($this->getConfigData('payment_action') == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE) {
         $config['postedParam']['autoCapture'] = CheckoutApi_Client_Constant::AUTOCAPUTURE_AUTH;
         $config['postedParam']['autoCapTime'] = 0;
     } else {
         $config['postedParam']['autoCapture'] = CheckoutApi_Client_Constant::AUTOCAPUTURE_CAPTURE;
         $config['postedParam']['autoCapTime'] = $this->getConfigData('auto_capture_time');
     }
     $paymentTokenCharge = $Api->getPaymentToken($config);
     $paymentTokenReturn = array('succes' => false, 'token' => '', 'message' => '');
     $paymentToken = '';
     if ($paymentTokenCharge->isValid()) {
         $paymentToken = $paymentTokenCharge->getId();
         $paymentTokenReturn['token'] = $paymentToken;
         $paymentTokenReturn['succes'] = true;
     } else {
         $paymentTokenCharge->printError();
     }
     if (!$paymentToken) {
         $paymentTokenReturn['succes'] = false;
         if ($paymentTokenCharge->getEventId()) {
             $eventCode = $paymentTokenCharge->getEventId();
         } else {
             $eventCode = $paymentTokenCharge->getErrorCode();
         }
         $paymentTokenReturn['message'] = Mage::helper('payment')->__($paymentTokenCharge->getExceptionState()->getErrorMessage() . ' ( ' . $eventCode . ')');
     }
     return $paymentTokenReturn;
 }
function generatePaymentToken()
{
    global $userinfo, $cart;
    $instance = getInstance();
    $payment_cc_data = cko_config();
    $config = array();
    $productsLoad = $cart['products'];
    $scretKey = $payment_cc_data['param02'];
    $amountCents = (int) (100 * $cart['total_cost']);
    $config['authorization'] = $scretKey;
    $config['mode'] = $payment_cc_data['param01'];
    $config['timeout'] = $payment_cc_data['param08'];
    if ($payment_cc_data['param06'] == 'Authorize and Capture') {
        $config = array_merge($instance->_captureConfig(), $config);
    } else {
        $config = array_merge($instance->_authorizeConfig(), $config);
    }
    $products = array();
    foreach ($productsLoad as $item) {
        $products[] = array('name' => $item['product'], 'sku' => $item['productcode'], 'price' => $item['price'], 'quantity' => $item['amount']);
    }
    $billPhoneLength = strlen($userinfo['b_phone']);
    $billingAddressConfig = array('addressLine1' => $userinfo['b_address'], 'addressLine2' => $userinfo['b_address_2'], 'postcode' => $userinfo['b_zipcode'], 'country' => $userinfo['b_country'], 'state' => $userinfo['b_statename'], 'city' => $userinfo['b_city']);
    if ($billPhoneLength > 6) {
        $bilPhoneArray = array('phone' => array('number' => $userinfo['b_phone']));
        $billingAddressConfig = array_merge_recursive($billingAddressConfig, $bilPhoneArray);
    }
    $shipPhoneLength = strlen($userinfo['s_phone']);
    $shippingAddressConfig = array('addressLine1' => $userinfo['s_address'], 'addressLine2' => $userinfo['s_address_2'], 'postcode' => $userinfo['s_zipcode'], 'country' => $userinfo['s_country'], 'state' => $userinfo['s_statename'], 'city' => $userinfo['s_city']);
    if ($shipPhoneLength > 6) {
        $shipPhoneArray = array('phone' => array('number' => $userinfo['s_phone']));
        $shippingAddressConfig = array_merge_recursive($shippingAddressConfig, $shipPhoneArray);
    }
    $config['postedParam'] = array_merge_recursive($config['postedParam'], array('email' => $userinfo['email'], 'value' => $amountCents, 'currency' => $payment_cc_data['param09'], 'shippingDetails' => $shippingAddressConfig, 'products' => $products, 'billingDetails' => $billingAddressConfig));
    $Api = CheckoutApi_Api::getApi(array('mode' => $payment_cc_data['param01']));
    $paymentTokenCharge = $Api->getPaymentToken($config);
    $paymentTokenArray = array('message' => '', 'success' => '', 'eventId' => '', 'token' => '');
    if ($paymentTokenCharge->isValid()) {
        $paymentTokenArray['token'] = $paymentTokenCharge->getId();
        $paymentTokenArray['success'] = true;
    } else {
        $paymentTokenArray['message'] = $paymentTokenCharge->getExceptionState()->getErrorMessage();
        $paymentTokenArray['success'] = false;
        $paymentTokenArray['eventId'] = $paymentTokenCharge->getEventId();
    }
    return $paymentTokenArray;
}
 /**
  * Get Payment Token from
  *
  * @param $params
  * @return mixed
  */
 public function getPaymentToken($params)
 {
     $Api = CheckoutApi_Api::getApi(array('mode' => $params['modetype']));
     $config = $this->createChargeConfig($params);
     /* Get payment Token */
     $paymentTokenCharge = $Api->getPaymentToken($config);
     $paymentTokenReturn = array('success' => false, 'token' => '', 'message' => '');
     if ($Api->getExceptionState()->hasError()) {
         logTransaction('checkoutjs', $Api->getExceptionState()->getErrorMessage(), "Unsuccessful");
     }
     if ($paymentTokenCharge->isValid()) {
         $paymentToken = $paymentTokenCharge->getId();
         $paymentTokenReturn['token'] = $paymentToken;
         $paymentTokenReturn['success'] = true;
     }
     return $paymentTokenReturn['token'];
 }
 /**
  * @param Varien_Object $payment
  * @param $amount
  * @param array $extraConfig
  * @return mixed
  */
 protected function _createCharge(Varien_Object $payment, $amount, $extraConfig = array())
 {
     /** @var CheckoutApi_Client_ClientGW3  $Api */
     $Api = CheckoutApi_Api::getApi(array('mode' => $this->getConfigData('mode')));
     $scretKey = $this->getConfigData('privatekey');
     $order = $payment->getOrder();
     $billingaddress = $order->getBillingAddress();
     $currencyDesc = $order->getBaseCurrencyCode();
     $orderId = $order->getIncrementId();
     $amountCents = $amount * 100;
     $config = array();
     $config['authorization'] = $scretKey;
     $config['mode'] = $this->getConfigData('mode');
     $config['timeout'] = $this->getConfigData('timeout');
     $config['postedParam'] = array('email' => $billingaddress->getData('email'), 'amount' => $amountCents, 'currency' => $currencyDesc, 'description' => "Order number::{$orderId}");
     $config['postedParam'] = array_merge($config['postedParam'], $extraConfig);
     $config['postedParam']['token'] = $payment->getCkoCcToken();
     return $Api->createCharge($config);
 }
Ejemplo n.º 13
0
 protected function _placeOrder(Varien_Object $payment, $amount, $messageSuccess, $extraConfig)
 {
     /** @var CheckoutApi_Lib_RespondObj $respondCharge */
     $respondCharge = $this->_createCharge($payment, $amount, $extraConfig);
     $this->_debug($respondCharge);
     if ($respondCharge->isValid()) {
         if (preg_match('/^1[0-9]+$/', $respondCharge->getResponseCode())) {
             /** @var Mage_Sales_Model_Order_Payment_Transaction $payment */
             /** @var Mage_Sales_Model_Order $order */
             $order = $payment->getOrder();
             $payment->setTransactionId($respondCharge->getId());
             $rawInfo = $respondCharge->toArray();
             $payment->setAdditionalInformation('rawrespond', $rawInfo);
             $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $rawInfo);
             $orderStatus = $this->getConfigData('order_status');
             $order->setStatus($orderStatus, false);
             $order->addStatusToHistory($orderStatus, $messageSuccess . $respondCharge->getId() . ' and respond code ' . $respondCharge->getResponseCode(), false);
             $order->save();
             $Api = CheckoutApi_Api::getApi(array('mode' => $this->getConfigData('mode')));
             $chargeUpdated = $Api->updateTrackId($respondCharge, $order->getIncrementId());
             if ($respondCharge->getCaptured()) {
                 $payment->capture(null);
             }
             $payment->save();
             return $respondCharge;
         } else {
             $errorDetails = '';
             if ($this->getDebugFlag()) {
                 $errorDetails = $respondCharge->getResponseMessage() . '---' . $respondCharge->getId();
             }
             Mage::throwException(Mage::helper('payment')->__('An error has occured. Please check you card
             details and try again. Thank you.') . ' ( ' . $errorDetails . ')');
             return false;
         }
     } else {
         $errorDetails = $respondCharge->getMessage();
         if ($this->getDebugFlag()) {
             Mage::log($respondCharge->getExceptionState()->getErrorMessage(), Zend_Log::DEBUG, 'cko.log');
         }
         Mage::throwException(Mage::helper('payment')->__($respondCharge->getExceptionState()->getErrorMessage() . ' ( ' . $errorDetails . ')'));
     }
     return false;
 }
 private function getPaymentToken()
 {
     global $order, $_POST, $messageStack;
     $config = array();
     $Api = CheckoutApi_Api::getApi(array('mode' => MODULE_PAYMENT_CHECKOUTAPIPAYMENT_TRANSACTION_SERVER));
     $amount = $order->info['total'];
     $amountCents = (int) ($amount * 100);
     $config['authorization'] = MODULE_PAYMENT_CHECKOUTAPIPAYMENT_SECRET_KEY;
     $config['mode'] = MODULE_PAYMENT_CHECKOUTAPIPAYMENT_TRANSACTION_SERVER;
     $products = array();
     $i = 1;
     foreach ($order->products as $product) {
         $products[] = array('name' => $product['name'], 'sku' => $product['id'], 'price' => $product['final_price'], 'quantity' => $product['qty']);
         $i++;
     }
     $billingAddress = array('addressLine1' => $order->billing['street_address'], 'addressLine2' => $order->billing['suburb'], 'postcode' => $order->billing['postcode'], 'country' => $order->billing['country']['iso_code_2'], 'city' => $order->billing['city'], 'state' => $order->billing['state'], 'phone' => array('number' => $order->customer['telephone']));
     $config['postedParam'] = array('email' => $order->customer['email_address'], 'name' => "{$order->customer['firstname']} {$order->customer['lastname']}", 'value' => $amountCents, 'currency' => $order->info['currency'], 'products' => $products, 'shippingDetails' => array('addressLine1' => $order->delivery['street_address'], 'addressLine2' => $order->delivery['suburb'], 'postcode' => $order->delivery['postcode'], 'country' => $order->delivery['country']['iso_code_2'], 'city' => $order->delivery['city'], 'phone' => array('number' => $order->customer['telephone'])));
     if (MODULE_PAYMENT_CHECKOUTAPIPAYMENT_TRANSACTION_METHOD == 'Authorize and Capture') {
         $config = array_merge_recursive($this->_captureConfig(), $config);
     } else {
         $config = array_merge_recursive($this->_authorizeConfig(), $config);
     }
     $paymentTokenCharge = $Api->getPaymentToken($config);
     $paymentToken = '';
     if ($paymentTokenCharge->isValid()) {
         $paymentToken = $paymentTokenCharge->getId();
     }
     if (!$paymentToken) {
         $error_message = $paymentTokenCharge->getExceptionState()->getErrorMessage() . ' ( ' . $paymentTokenCharge->getEventId() . ')';
         $messageStack->add_session('checkout_payment', $error_message . '<!-- [' . $this->code . '] -->', 'error');
         if (!isset($_GET['error'])) {
             zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'error=true', 'SSL', true, false));
         }
     }
     return $paymentToken;
 }
 protected function _createCharge($config)
 {
     $Api = CheckoutApi_Api::getApi(array('mode' => $config['mode']));
     return $Api->createCharge($config);
 }
 public function _createCharge($config)
 {
     global $module_params;
     $Api = CheckoutApi_Api::getApi(array('mode' => $module_params['param01']));
     return $Api->createCharge($config);
 }
 public function callbackAction()
 {
     $postedVal = $this->getRequest()->getParams();
     if (!empty($postedVal) && isset($postedVal['cko-payment-token'])) {
         if (isset($postedVal['responseCode']) && !preg_match('/^1[0-9]+$/', $postedVal['responseCode'])) {
             return $this->_redirect('checkout/onepage', array('_secure' => true));
         }
         $paymentToken = $postedVal['cko-payment-token'];
         $storeId = Mage::app()->getStore()->getId();
         $Api = CheckoutApi_Api::getApi(array('mode' => $this->_requesttConfigData('mode')));
         $config['paymentToken'] = $paymentToken;
         $config['authorization'] = $this->_requesttConfigData('privatekey');
         $chargeObject = $Api->verifyChargePaymentToken($config);
         if ($chargeObject->getTrackId()) {
             $order_id = $chargeObject->getTrackId();
         }
         $_order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
         $_payment = $_order->getPayment();
         $chargeUpdated = $Api->updateTrackId($chargeObject, $order_id);
         if ($chargeObject->isValid()) {
             $chargeId = $chargeObject->getId();
             if ($chargeObject->getStatus() == 'Authorised' || $chargeObject->getStatus() == 'Flagged') {
                 $_payment->setTransactionId($chargeId);
                 $_payment->setParentTransactionId($chargeId);
                 $_payment->authorize(true, $_order->getBaseTotalDue());
                 $orderStatus = $this->_requesttConfigData('order_status');
                 $_rawInfo = $chargeObject->toArray();
                 $_payment->setAdditionalInformation('rawrespond', $_rawInfo)->setShouldCloseParentTransaction('Completed' === $orderStatus)->setIsTransactionClosed(0)->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $_rawInfo);
                 $paymentMethod = $chargeObject->getCard()->getPaymentMethod();
                 $cctype = $this->_getCcCodeType($paymentMethod);
                 $_payment->setCcType($cctype);
                 $_payment->setCcLast4($chargeObject->getCard()->getLast4());
                 $_payment->save();
                 $_order->setStatus($orderStatus, false);
                 $_order->addStatusToHistory($orderStatus, 'Payment successfully ' . $chargeObject->getStatus() . '
                 with Transaction ID ' . $chargeObject->getId());
                 $_order->save();
                 $this->getResponse()->setBody('Payment successfully ' . $chargeObject->getStatus() . '
                             with Transaction ID ' . $chargeObject->getId());
                 $this->_redirect('checkout/onepage/success', array('_secure' => true));
             } elseif ($chargeObject->getStatus() == 'Voided') {
             } elseif ($chargeObject->getStatus() == 'Declined') {
             } elseif ($chargeObject->getStatus() == 'Pending' && $chargeObject->getChargeMode() == 3) {
                 $orderStatus = $this->_requesttConfigData('order_status_capture');
                 if ($_order->getStatus() != 'canceled' || $_order->getStatus() != $orderStatus) {
                     $_order->setStatus('pending', false);
                 }
                 $_payment->setTransactionId($chargeId);
                 $_payment->setParentTransactionId($chargeId);
                 $_payment->authorize(true, $_order->getBaseTotalDue());
                 $_payment->save();
                 $_order->save();
                 $this->_redirect('checkout/onepage/success', array('_secure' => true));
             }
         }
         // end is valid
     }
     //end if posted empty
 }
include "../../../includes/gatewayfunctions.php";
include "../../../includes/invoicefunctions.php";
include "../includes/model/methods/creditcard.php";
$responseToken = !empty($_REQUEST['cko-payment-token']) ? (string) $_REQUEST['cko-payment-token'] : '';
$otherVariables = getvariables();
$gatewayModule = model_methods_creditcard::PAYMENT_CODE;
$GATEWAY = getGatewayVariables($gatewayModule);
if (empty($responseToken) || empty($_SESSION['checkout_payment_token']) || (string) $_SESSION['checkout_payment_token']['token'] !== $responseToken) {
    logTransaction($GATEWAY["name"], 'Your payment was not completed. Your payment tokens do not match. Action - 3d secure authorize. Try again or contact customer support.', "Unsuccessful");
    header("Location:" . $otherVariables["systemurl"] . "/cart.php");
    exit;
}
$secretKey = $GATEWAY['secretkey'];
$mode = $GATEWAY['modetype'];
$invoiceId = $_SESSION['checkout_payment_token']['invoice_id'];
$Api = CheckoutApi_Api::getApi(array('mode' => $mode));
$verifyParams = array('paymentToken' => $responseToken, 'authorization' => $secretKey);
$respondCharge = $Api->verifyChargePaymentToken($verifyParams);
$returnUrl = $otherVariables["systemurl"] . "/viewinvoice.php?id=" . $invoiceId;
if ($Api->getExceptionState()->hasError()) {
    $message = 'Your payment was not completed.' . $Api->getExceptionState()->getErrorMessage() . ' and try again or contact customer support.';
    logTransaction($GATEWAY["name"], $message, "Unsuccessful");
    $_SESSION['checkout_error'] = true;
    $_SESSION['checkout_error_message'] = $message;
    header("Location:" . $returnUrl);
    exit;
}
$chargeId = is_object($respondCharge) ? $respondCharge->getId() : null;
if (!$respondCharge->isValid() || !model_methods_creditcard::responseValidation($respondCharge)) {
    $transactionMessage = !empty($chargeId) ? ", transaction id - {$chargeId}" : '';
    logTransaction($GATEWAY["name"], "Your payment was not completed. Response is invalid for trackId - {$invoiceId}{$transactionMessage}. Action - 3d secure authorize. Try again or contact customer support.", "Unsuccessful");
 public function VoidAction()
 {
     $_id = $this->getRequest()->getParam('order_id');
     $_order = Mage::getModel('sales/order')->load($_id);
     $_payment = $_order->getPayment();
     $chargeId = preg_replace('/\\-capture$/', '', $_payment->getLastTransId());
     $_authorizeAmount = $_payment->getAmountAuthorized();
     /** @var CheckoutApi_Client_ClientGW3  $Api */
     $_Api = CheckoutApi_Api::getApi(array('mode' => $this->getConfigData('mode')));
     $secretKey = $this->getConfigData('privatekey');
     $_config = array();
     $_config['authorization'] = $secretKey;
     $_config['chargeId'] = $chargeId;
     $_config['postedParam'] = array('value' => (int) ($_authorizeAmount * 100));
     $_refundCharge = $_Api->voidCharge($_config);
     $_payment->void(new Varien_Object());
     if ($_refundCharge->isValid() && $_refundCharge->getRefunded() && preg_match('/^1[0-9]+$/', $_refundCharge->getResponseCode())) {
         if ($_payment->getMethodInstance() instanceof CheckoutApi_ChargePayment_Model_Method_Creditcard) {
             $_voidObj = new Varien_Object();
             $_id = $this->getRequest()->getParam('order_id');
             /** @var Mage_Sales_Model_Order $_order */
             $_order = Mage::getModel('sales/order')->load($_id);
             $_order->getPayment()->setTransactionId(null)->setParentTransactionId($_refundCharge->getId())->void(new Varien_Object());
         }
         $_order->registerCancellation('Transaction has been void')->save();
         $_rawInfo = $_refundCharge->toArray();
         $_payment->setAdditionalInformation('rawrespond', $_rawInfo);
         $_payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $_rawInfo);
         $_payment->setTransactionId($_refundCharge->getId());
         $_payment->setIsTransactionClosed(1)->setShouldCloseParentTransaction(1);
         $_payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, null, false, 'Transaction has been void');
         $_payment->void($_voidObj);
         $_payment->unsLastTransId();
     } else {
         Mage::getSingleton('adminhtml/session')->addError($_refundCharge->getExceptionState()->getErrorMessage());
     }
     $this->_redirectReferer();
 }
 public function getOrderPlaceRedirectUrl()
 {
     $info = $this->getInfoInstance();
     $toReturn = null;
     $cko_redirectUrl = $info->getAdditionalInformation('cko_redirectUrl');
     $cko_lp_redirectUrl = $info->getAdditionalInformation('cko_lp_redirectUrl');
     $cko_3d_redirectUrl = $info->getAdditionalInformation('cko_3d_redirectUrl');
     $Api = CheckoutApi_Api::getApi(array('mode' => $this->getConfigData('mode')));
     $config['authorization'] = $this->getConfigData('privatekey');
     if ($cko_redirectUrl) {
         $dataOrder = $this->getCentinelValidationData();
         $block = Mage::getBlockSingleton('checkoutapi_chargePayment/form_creditcard')->getPaymentTokenResult($dataOrder->getOrderNumber());
         $paymentToken = $block['token'];
         $cko_redirectUrl = Mage::helper('checkoutapi_chargePayment')->replace_between($cko_redirectUrl, 'paymentToken=', '&', $paymentToken);
         $toReturn = $cko_redirectUrl . '&trackId=' . $dataOrder->getOrderNumber();
     }
     if ($cko_3d_redirectUrl) {
         $dataOrder = $this->getCentinelValidationData();
         $config['paymentToken'] = $info->getAdditionalInformation('cko_cc_paymenToken');
         $chargeResponse = $Api->verifyChargePaymentToken($config);
         $chargeUpdated = $Api->updateTrackId($chargeResponse, $dataOrder->getOrderNumber());
         $toReturn = $cko_3d_redirectUrl;
     }
     if ($cko_lp_redirectUrl) {
         $urlArray = explode("=", $cko_lp_redirectUrl);
         $paymentToken = $urlArray[1];
         $dataOrder = $this->getCentinelValidationData();
         $config['paymentToken'] = $paymentToken;
         $chargeResponse = $Api->verifyChargePaymentToken($config);
         $chargeUpdated = $Api->updateTrackId($chargeResponse, $dataOrder->getOrderNumber());
         $toReturn = $cko_lp_redirectUrl;
     }
     return $toReturn;
 }
/**
 * Refund transaction.
 *
 * @param $params
 * @return array
 */
function checkoutjs_refund($params)
{
    $_config = array();
    $amount = (int) $params['amount'];
    $currencyDesc = $params['amount'];
    $_config['authorization'] = $params['secretkey'];
    $_config['mode'] = $params['modetype'];
    $_config['chargeId'] = $params['transid'];
    $_Api = CheckoutApi_Api::getApi(array('mode' => $_config['modetype']));
    $amountCents = $_Api->valueToDecimal($amount, $currencyDesc);
    $_config['postedParam'] = array('value' => $amountCents);
    $_refundCharge = $_Api->refundCharge($_config);
    if ($_Api->getExceptionState()->hasError()) {
        logTransaction(model_methods_creditcard::PAYMENT_CODE, $_Api->getExceptionState()->getErrorMessage(), "Unsuccessful");
    }
    if ($_refundCharge->isValid()) {
        logTransaction(model_methods_creditcard::PAYMENT_CODE, $_refundCharge->toArray(), "Success");
        return array("status" => "success", "transid" => $params["invoiceid"], "rawdata" => $_refundCharge->getRawRespond());
    }
    logTransaction(model_methods_creditcard::PAYMENT_CODE, $_refundCharge->toArray(), "fail");
    return array("status" => "error", "rawdata" => $_refundCharge->getRawRespond());
}
 /**
  * Create charge settings.
  *
  * @param $config
  * Charge settings
  *
  * @return array
  * Settings form array
  */
 protected function createCharge($config)
 {
     $config = array();
     $payment_method = commerce_payment_method_instance_load('commerce_checkoutpayment|commerce_payment_commerce_checkoutpayment');
     $secret_key = $payment_method['settings']['private_key'];
     $mode = $payment_method['settings']['mode'];
     $timeout = $payment_method['settings']['timeout'];
     $config['authorization'] = $secret_key;
     $config['timeout'] = $timeout;
     $config['paymentToken'] = $_POST['cko-cc-paymenToken'];
     $api = CheckoutApi_Api::getApi(array('mode' => $mode));
     return $api->verifyChargePaymentToken($config);
 }
 private function placeOrder($config)
 {
     $Api = CheckoutApi_Api::getApi(array('mode' => $this->endpoint));
     return $Api->createCharge($config);
 }
Ejemplo n.º 24
0
 public function getCardToken()
 {
     $cardTokenConfig['authorization'] = "pk_test_88a9f52e-17e3-4a3f-a11e-669757454288";
     $Api = \CheckoutApi_Api::getApi();
     $cardTokenConfig['postedParam'] = array('number' => '4543474002249996', 'expiryMonth' => 06, 'expiryYear' => 2017, 'cvv' => 956);
     $respondCardToken = $Api->getCardToken($cardTokenConfig);
     if ($respondCardToken->isValid()) {
         return $respondCardToken->getId();
     }
     return null;
 }
Ejemplo n.º 25
0
 /**
  * Helpper static function for setting  for $_apiClass.
  * @param CheckoutApi_Client_Client $apiClass gateway interface name
  */
 public static function setApiClass($apiClass)
 {
     self::$_apiClass = $apiClass;
 }
<?php

/**
 * CallBack script for Gateway
 *
 */
include "../../../init.php";
include "../../../includes/functions.php";
include "../../../includes/gatewayfunctions.php";
include "../../../includes/invoicefunctions.php";
include "../includes/model/methods/creditcard.php";
$gatewaymodule = model_methods_creditcard::PAYMENT_CODE;
$GATEWAY = getGatewayVariables($gatewaymodule);
$secretKey = $GATEWAY['secretkey'];
$Api = CheckoutApi_Api::getApi(array('mode' => $GATEWAY['modetype']));
$OtherVariables = getvariables();
if (empty($_SESSION['favcolor']) || empty($_REQUEST['cko-card-token'])) {
    logTransaction($GATEWAY["name"], 'Your payment was not completed. Customer session or card token is empty. Action - authorize. Try again or contact customer support.', "Unsuccessful");
    header("Location:" . $OtherVariables["systemurl"] . "/cart.php");
    exit;
}
$result = mysql_query("Select * from `tblinvoices` where id =" . $_SESSION['favcolor']['postedParam']['trackId']);
while ($row = mysql_fetch_assoc($result)) {
    $ClientID = $row['userid'];
}
$invoiceId = $_SESSION['favcolor']['postedParam']['trackId'];
$currency = $_SESSION['favcolor']['postedParam']['currency'];
$config['authorization'] = $GATEWAY['secretkey'];
$config['postedParam'] = array('trackId' => $invoiceId, 'value' => $_SESSION['favcolor']['postedParam']['value'], "chargeMode" => model_methods_creditcard::CHECKOUT_NON_PCI_CHARGE_MODE_NON_3D, 'currency' => $currency, 'autoCapture' => $_SESSION['favcolor']['postedParam']['autoCapture'], 'autoCapTime' => $_SESSION['favcolor']['postedParam']['autoCapTime'], 'cardToken' => $_REQUEST['cko-card-token'], 'email' => $_SESSION['favcolor']['postedParam']['email'], 'customerName' => $_SESSION['favcolor']['postedParam']['custName'], 'metadata' => $_SESSION['favcolor']['postedParam']['metadata']);
$respondCharge = $Api->createCharge($config);
$returnUrl = $OtherVariables["systemurl"] . "/viewinvoice.php?id=" . $invoiceId;
<?php

define('SKIP_COOKIE_CHECK', true);
require_once './auth.php';
include './payment/includes/autoload.php';
x_load('order');
$posted_data = file_get_contents("php://input");
if (empty($posted_data)) {
    // empty request
    exit;
} else {
    $payment_cc_data = func_query_first("SELECT * FROM {$sql_tbl['ccprocessors']} WHERE processor='checkoutapipayment.php'");
    $Api = CheckoutApi_Api::getApi(array('mode' => $payment_cc_data['param01']));
    $objectCharge = $Api->chargeToObj($posted_data);
    if ($objectCharge->isValid()) {
        /*
         * Need to get track id
         */
        $order_id = $objectCharge->getTrackId();
        if ($objectCharge->getCaptured()) {
            $advinfo = 'Your payment has been successfully completed';
            func_change_order_status($order_id, 'C', $advinfo);
            // completed status?
        } elseif ($objectCharge->getRefunded()) {
            $advinfo = 'Your payment has been refunded';
            func_change_order_status($order_id, 'D', $advinfo);
            // declined status?
        } elseif (!$objectCharge->getAuthorised()) {
            $advinfo[] = 'Your order has been cancelled';
            func_change_order_status($order_id, 'D', $advinfo);
            // cancelled status?