/**
  * Handle any risk decision returned from Braintree
  *
  * @param                $result
  * @param \Varien_Object $payment
  *
  * @return $this
  */
 protected function handleFraud($result, Varien_Object $payment)
 {
     // Verify we have risk data
     if (isset($result->transaction) && isset($result->transaction->riskData) && isset($result->transaction->riskData->decision)) {
         // If the decision is to review the payment mark the payment as such
         if ($result->transaction->riskData->decision == self::ADVANCED_FRAUD_REVIEW || $result->transaction->riskData->decision == self::ADVANCED_FRAUD_DECLINE) {
             // Mark the payment as pending
             $payment->setIsTransactionPending(true);
             // If the payment got marked as fraud/decline, we mark it as fraud
             if ($result->transaction->riskData->decision == self::ADVANCED_FRAUD_DECLINE) {
                 $payment->setIsFraudDetected(true);
             }
         }
     }
     return $this;
 }
 public function authorize(Varien_Object $payment, $amount)
 {
     require_once Mage::getModuleDir('coinbase-php', 'Coinbase_Coinbase') . "/coinbase-php/Coinbase.php";
     // Step 1: Use the Coinbase API to create redirect URL.
     $apiKey = Mage::getStoreConfig('payment/Coinbase/api_key');
     $apiSecret = Mage::getStoreConfig('payment/Coinbase/api_secret');
     if ($apiKey == null || $apiSecret == null) {
         throw new Exception("Before using the Coinbase plugin, you need to enter an API Key and Secret in Magento Admin > Configuration > System > Payment Methods > Coinbase.");
     }
     $coinbase = Coinbase::withApiKey($apiKey, $apiSecret);
     $order = $payment->getOrder();
     $currency = $order->getBaseCurrencyCode();
     $callbackSecret = Mage::getStoreConfig('payment/Coinbase/callback_secret');
     if ($callbackSecret == "generate") {
         // Important to keep the callback URL a secret
         $callbackSecret = md5('secret_' . mt_rand());
         Mage::getModel('core/config')->saveConfig('payment/Coinbase/callback_secret', $callbackSecret)->cleanCache();
         Mage::app()->getStore()->resetConfig();
     }
     $successUrl = Mage::getStoreConfig('payment/Coinbase/custom_success_url');
     $cancelUrl = Mage::getStoreConfig('payment/Coinbase/custom_cancel_url');
     if ($successUrl == false) {
         $successUrl = Mage::getUrl('coinbase_coinbase') . 'redirect/success/';
     }
     if ($cancelUrl == false) {
         $cancelUrl = Mage::getUrl('coinbase_coinbase') . 'redirect/cancel/';
     }
     $name = "Order #" . $order['increment_id'];
     $custom = $order->getId();
     $params = array('description' => 'Order #' . $order['increment_id'], 'callback_url' => Mage::getUrl('coinbase_coinbase') . 'callback/callback/?secret=' . $callbackSecret, 'success_url' => $successUrl, 'cancel_url' => $cancelUrl, 'info_url' => Mage::getBaseUrl());
     // Generate the code
     try {
         $code = $coinbase->createButton($name, $amount, $currency, $custom, $params)->button->code;
     } catch (Exception $e) {
         throw new Exception("Could not generate checkout page. Double check your API Key and Secret. " . $e->getMessage());
     }
     $redirectUrl = 'https://coinbase.com/checkouts/' . $code;
     // Step 2: Redirect customer to payment page
     $payment->setIsTransactionPending(true);
     // Set status to Payment Review while waiting for Coinbase postback
     Mage::getSingleton('customer/session')->setRedirectUrl($redirectUrl);
     return $this;
 }
 /**
  * Processes order status and return information about order status and state
  * Doesn' change anything to the order. Just returns an object showing what to do.
  * @param $statusCode
  * @return Varien_Object
  */
 public function processStatus($statusCode)
 {
     $return = new Varien_Object();
     $return->setStateChanged(true);
     $return->setIsTransactionPending(true);
     //payment is pending?
     switch ($statusCode) {
         case '1':
             $return->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
             $return->setIsCustomerNotified($this->getCode() != 'pagseguro_cc');
             if ($this->getCode() == 'pagseguro_cc') {
                 $return->setStateChanged(false);
             }
             $return->setMessage('Aguardando pagamento: o comprador iniciou a transação,
             mas até o momento o PagSeguro não recebeu nenhuma informação sobre o pagamento.');
             break;
         case '2':
             $return->setState(Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW);
             $return->setIsCustomerNotified(true);
             $return->setMessage('Em análise: o comprador optou por pagar com um cartão de crédito e
                 o PagSeguro está analisando o risco da transação.');
             break;
         case '3':
             $return->setState(Mage_Sales_Model_Order::STATE_PROCESSING);
             $return->setIsCustomerNotified(true);
             $return->setMessage('Paga: a transação foi paga pelo comprador e o PagSeguro já recebeu uma confirmação
                 da instituição financeira responsável pelo processamento.');
             $return->setIsTransactionPending(false);
             break;
         case '4':
             $return->setMessage('Disponível: a transação foi paga e chegou ao final de seu prazo de liberação sem
                 ter sido retornada e sem que haja nenhuma disputa aberta.');
             $return->setIsCustomerNotified(false);
             $return->setStateChanged(false);
             $return->setIsTransactionPending(false);
             break;
         case '5':
             $return->setState(Mage_Sales_Model_Order::STATE_PROCESSING);
             $return->setIsCustomerNotified(false);
             $return->setIsTransactionPending(false);
             $return->setMessage('Em disputa: o comprador, dentro do prazo de liberação da transação,
                 abriu uma disputa.');
             break;
         case '6':
             $return->setState(Mage_Sales_Model_Order::STATE_CLOSED);
             $return->setIsCustomerNotified(false);
             $return->setIsTransactionPending(false);
             $return->setMessage('Devolvida: o valor da transação foi devolvido para o comprador.');
             break;
         case '7':
             $return->setState(Mage_Sales_Model_Order::STATE_CANCELED);
             $return->setIsCustomerNotified(true);
             $return->setMessage('Cancelada: a transação foi cancelada sem ter sido finalizada.');
             break;
         default:
             $return->setIsCustomerNotified(false);
             $return->setStateChanged(false);
             $return->setMessage('Codigo de status inválido retornado pelo PagSeguro. (' . $statusCode . ')');
     }
     return $return;
 }
 /**
  * Makes method specific manipulations after authorize/clone transaction success
  * 
  * @param Varien_Object $payment $payment
  * @param array $result
  */
 protected function _processMethodSpecificTransactionSuccess($payment, $result)
 {
     // Saving token if applicable, additional manipulations for multishipping
     if (isset($result->transaction->creditCard['token']) && $result->transaction->creditCard['token']) {
         $token = $result->transaction->creditCard['token'];
         $payment->setTransactionAdditionalInfo('token', $token);
         if ($payment->getIsMultishipping()) {
             if (!Mage::registry(self::REGISTER_NAME)) {
                 Mage::register(self::REGISTER_NAME, $token);
             }
             if (Mage::getSingleton('checkout/session')->getBraintreeDeleteCard() === true) {
                 Mage::getSingleton('checkout/session')->setBraintreeDeleteCard($token);
             }
         }
     }
     // Advanced fraud protection data
     if (isset($result->transaction->riskData) && $this->getConfigData('fraudprotection')) {
         $decision = $result->transaction->riskData->decision;
         $helper = Mage::helper('braintree_payments');
         if ($decision == self::RISK_DATA_NOT_EVALUATED || $decision == self::RISK_DATA_REVIEW) {
             $payment->setIsTransactionPending(true);
             $payment->setIsFraudDetected(true);
         } else {
             if ($decision == self::RISK_DATA_DECLINE) {
                 Braintree_Transaction::void($result->transaction->id);
                 throw new Mage_Payment_Model_Info_Exception($helper->__('Try another card'));
             }
         }
         $system = $this->getConfigData('kount_id') ? 'Kount' : $helper->__('Braintree Advanced Fraud Protection Tool');
         $id = '';
         if ($result->transaction->riskData->id) {
             $id = $helper->__(', ID is "%s"', $result->transaction->riskData->id);
         }
         $comment = $helper->__('Transaction was evaluated with %s: decision is "%s"', $system, $decision) . $id;
         $payment->getOrder()->addStatusHistoryComment($comment);
     }
 }
 /**
  * Authorize payment
  *
  * @param Mage_Sales_Model_Order_Payment | Mage_Sales_Model_Quote_Payment $payment
  * @param mixed $amount
  * @return Mage_Paypal_Model_Payflowlink
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     $txnId = $payment->getAdditionalInformation('authorization_id');
     /** @var $transaction Mage_Paypal_Model_Payment_Transaction */
     $transaction = Mage::getModel('paypal/payment_transaction');
     $transaction->loadByTxnId($txnId);
     $payment->setTransactionId($txnId)->setIsTransactionClosed(0);
     if ($payment->getAdditionalInformation('paypal_fraud_filters') !== null) {
         $payment->setIsTransactionPending(true);
         $payment->setIsFraudDetected(true);
     }
     if ($transaction->getId() && $payment->getAdditionalInformation('authorization_amount') != Mage_Paypal_Model_Config::AUTHORIZATION_AMOUNT_FULL) {
         $this->_addTransaction($payment, $txnId);
     }
     $this->_authorize($payment, $amount, $transaction, $txnId);
     if ($payment->getAdditionalInformation('authorization_amount') != Mage_Paypal_Model_Config::AUTHORIZATION_AMOUNT_FULL) {
         $payment->setParentTransactionId($txnId);
         parent::authorize($payment, $amount);
         if ($payment->getTransactionId()) {
             $payment->setAdditionalInformation('authorization_id', $payment->getTransactionId());
         }
     }
     $transaction->delete();
     return $this;
 }
Example #6
0
 public function authorize(Varien_Object $payment, $amount)
 {
     $apiToken = Mage::getStoreConfig('payment/Bitbayar/api_token');
     $bitbayar_currency = 'IDR';
     if ($apiToken == null) {
         throw new Exception("Before using the Bitbayar plugin, you need to enter an API Token in Magento Admin > Configuration > System > Payment Methods.");
     }
     if (strlen($apiToken) != 33 || $apiToken[0] != 'S') {
         throw new Exception("API Token is not valid!");
     }
     $baseCurrencyCode = Mage::app()->getBaseCurrencyCode();
     $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
     $currencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));
     if ($baseCurrencyCode != $bitbayar_currency) {
         $curr_rate = $currencyRates[$bitbayar_currency];
     } else {
         $curr_rate = 1;
     }
     //~ $data_currency = array(
     //~ 'baseCurrencyCode' => $baseCurrencyCode,
     //~ 'allowedCurrencies' => $allowedCurrencies,
     //~ 'currencyRates' => $currencyRates,
     //~ 'IDRRates' => $currencyRates['IDR'],
     //~
     //~ );
     //~ print_r($data_currency);
     $order = $payment->getOrder();
     $currency = $order->getBaseCurrencyCode();
     $successUrl = Mage::getStoreConfig('payment/Bitbayar/custom_success_url');
     $cancelUrl = Mage::getStoreConfig('payment/Bitbayar/custom_cancel_url');
     if ($successUrl == false) {
         $successUrl = Mage::getUrl('bitbayar') . 'redirect/success/';
     }
     if ($cancelUrl == false) {
         $cancelUrl = Mage::getUrl('bitbayar') . 'redirect/cancel/';
     }
     $bitbayar_url = 'https://bitbayar.com/api/create_invoice';
     $dataPost = array('token' => $apiToken, 'invoice_id' => $order['increment_id'], 'rupiah' => round($amount * $curr_rate), 'memo' => 'Invoice #' . $order['increment_id'] . ' - Magento', 'callback_url' => Mage::getUrl('bitbayar') . 'callback/callback', 'url_success' => $successUrl, 'url_failed' => $cancelUrl);
     $bb_pay = $this->curlPost($bitbayar_url, $dataPost);
     $result = json_decode($bb_pay);
     if ($result->success) {
         $redirectUrl = $result->payment_url;
     }
     //~ Redirect customer to payment page
     $payment->setIsTransactionPending(true);
     // Set status to Payment Review while waiting for Bitbayar postback
     Mage::getSingleton('customer/session')->setRedirectUrl($redirectUrl);
     return $this;
 }
 /**
  * Authorize payment method
  *
  * @param Varien_Object $payment
  * @param float $amount
  *
  * @throws Exception Payment could not be executed
  *
  * @return Iways_PayPalPlus_Model_Payment
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     $paymentId = Mage::app()->getRequest()->getParam('paymentId');
     $payerId = Mage::app()->getRequest()->getParam('PayerID');
     try {
         if (Mage::getStoreConfig('payment/iways_paypalplus_payment/transfer_reserved_order_id')) {
             Mage::getModel('iways_paypalplus/api')->patchInvoiceNumber($paymentId, $payment->getOrder()->getIncrementId());
         }
     } catch (\Exception $e) {
         Mage::logException($e);
     }
     /**
      * @var \PayPal\Api\Payment $ppPayment
      */
     $ppPayment = Mage::getModel('iways_paypalplus/api')->executePayment($paymentId, $payerId);
     Mage::getSingleton('customer/session')->setPayPalPaymentId(null);
     Mage::getSingleton('customer/session')->setPayPalPaymentPatched(null);
     if (!$ppPayment) {
         Mage::throwException('Payment could not be executed.');
     }
     if ($paymentInstructions = $ppPayment->getPaymentInstruction()) {
         $payment->setData('ppp_pui_reference_number', $paymentInstructions->getReferenceNumber());
         $payment->setData('ppp_pui_instruction_type', $paymentInstructions->getInstructionType());
         $payment->setData('ppp_pui_payment_due_date', Mage::helper('iways_paypalplus')->convertDueDate($paymentInstructions->getPaymentDueDate()));
         $payment->setData('ppp_pui_note', $paymentInstructions->getNote());
         $bankInsctructions = $paymentInstructions->getRecipientBankingInstruction();
         $payment->setData('ppp_pui_bank_name', $bankInsctructions->getBankName());
         $payment->setData('ppp_pui_account_holder_name', $bankInsctructions->getAccountHolderName());
         $payment->setData('ppp_pui_international_bank_account_number', $bankInsctructions->getInternationalBankAccountNumber());
         $payment->setData('ppp_pui_bank_identifier_code', $bankInsctructions->getBankIdentifierCode());
         $payment->setData('ppp_pui_routing_number', $bankInsctructions->getRoutingNumber());
         $ppAmount = $paymentInstructions->getAmount();
         $payment->setData('ppp_pui_amount', $ppAmount->getValue());
         $payment->setData('ppp_pui_currency', $ppAmount->getCurrency());
     }
     $transactionId = null;
     try {
         $transactions = $ppPayment->getTransactions();
         if ($transactions && isset($transactions[0])) {
             $resource = $transactions[0]->getRelatedResources();
             if ($resource && isset($resource[0])) {
                 $sale = $resource[0]->getSale();
                 $transactionId = $sale->getId();
                 if ($sale->getState() == self::PENDING) {
                     $payment->setIsTransactionPending(true);
                 }
             }
         }
     } catch (Exception $e) {
         $transactionId = $ppPayment->getId();
     }
     $payment->setTransactionId($transactionId);
     $payment->setParentTransactionId($ppPayment->getId());
     if ($ppPayment->getState() == self::PPP_STATUS_APPROVED) {
         $payment->setStatus(self::STATUS_APPROVED);
     }
     return $this;
 }
Example #8
0
 /**
  * Processing the transaction using the transparent redirect integration
  *
  * @param Varien_Object $payment
  * @param unknown_type $amount
  */
 public function _runTransparentRedirectTransaction(Varien_Object $payment, $amount)
 {
     $takePaymentInStoreBaseCurrency = $this->getConfigData('takePaymentInStoreBaseCurrency');
     $GLOBALS['m_boPayInvoice'] = false;
     $payment->setIsTransactionPending(true);
     $nVersion = $this->getVersion();
     $szMerchantID = $this->getConfigData('merchantid');
     $szPassword = $this->getConfigData('password');
     $szPreSharedKey = $this->getConfigData('presharedkey');
     $hmHashMethod = $this->getConfigData('hashmethod');
     $szCallbackURL = Mage::getUrl('cardsaveonlinepayments/payment/callbacktransparentredirect', array('_secure' => true));
     $order = $payment->getOrder();
     $billingAddress = $order->getBillingAddress();
     $iclISOCurrencyList = CSV_ISOCurrencies::getISOCurrencyList();
     $iclISOCountryList = CSV_ISOCountries::getISOCountryList();
     $szStartDateMonth = '';
     $szStartDateYear = '';
     if (!$takePaymentInStoreBaseCurrency) {
         // Take payment in order currency
         $szCurrencyShort = $order->getOrderCurrency()->getCurrencyCode();
         if ($szCurrencyShort != '' && $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency)) {
             $nCurrencyCode = $icISOCurrency->getISOCode();
         }
         // Calculate amount
         $power = pow(10, $icISOCurrency->getExponent());
         $nAmount = round($order->getGrandTotal() * $power, 0);
     } else {
         // Take payment in site base currency
         //$szCurrencyShort = $order->getOrderCurrency()->getCurrencyCode();
         $szCurrencyShort = $order->getBaseCurrencyCode();
         if ($szCurrencyShort != '' && $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency)) {
             $nCurrencyCode = $icISOCurrency->getISOCode();
         }
         // Calculate amount
         $nAmount = $this->_getRoundedAmount($amount, $icISOCurrency->getExponent());
     }
     $szOrderID = $payment->getOrder()->increment_id;
     //date time with 2008-12-01 14:12:00 +01:00 format
     $szTransactionDateTime = date('Y-m-d H:i:s P');
     $szOrderDescription = '';
     //$szTransactionType = 'SALE';
     $paymentAction = $this->getConfigData('payment_action');
     if ($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE) {
         $szTransactionType = "SALE";
     } else {
         if ($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE) {
             $szTransactionType = "PREAUTH";
         } else {
             Mage::throwException('Unknown payment action: ' . $paymentAction);
         }
     }
     $szAddress1 = $billingAddress->getStreet1();
     $szAddress2 = $billingAddress->getStreet2();
     $szAddress3 = $billingAddress->getStreet3();
     $szAddress4 = $billingAddress->getStreet4();
     $szCity = $billingAddress->getCity();
     $szState = $billingAddress->getRegion();
     $szPostCode = $billingAddress->getPostcode();
     $szISO2CountryCode = $billingAddress->getCountry();
     $szCountryShort = $this->_getISO3Code($szISO2CountryCode);
     if ($iclISOCountryList->getISOCountry($szCountryShort, $icISOCountry)) {
         $nCountryCode = $icISOCountry->getISOCode();
     }
     $szCardName = $payment->getCcOwner();
     $szCardNumber = $payment->getCcNumber();
     $szExpiryDateMonth = $payment->getCcExpMonth();
     $szExpiryDateYear = $payment->getCcExpYear();
     if ($payment->getCcSsStartMonth() != '') {
         $szStartDateMonth = $payment->getCcSsStartMonth();
     }
     if ($payment->getCcSsStartYear() != '') {
         $szStartDateYear = $payment->getCcSsStartYear();
     }
     $szIssueNumber = $payment->getCcSsIssue();
     $szCV2 = $payment->getCcCid();
     $szHashDigest = CSV_PaymentFormHelper::calculateTransparentRedirectHashDigest($szMerchantID, $szPassword, $hmHashMethod, $szPreSharedKey, $nAmount, $nCurrencyCode, $szOrderID, $szTransactionType, $szTransactionDateTime, $szCallbackURL, $szOrderDescription);
     Mage::getSingleton('checkout/session')->setHashdigest($szHashDigest)->setMerchantid($szMerchantID)->setAmount($nAmount)->setCurrencycode($nCurrencyCode)->setOrderid($szOrderID)->setTransactiontype($szTransactionType)->setTransactiondatetime($szTransactionDateTime)->setCallbackurl($szCallbackURL)->setOrderdescription($szOrderDescription)->setAddress1($szAddress1)->setAddress2($szAddress2)->setAddress3($szAddress3)->setAddress4($szAddress4)->setCity($szCity)->setState($szState)->setPostcode($szPostCode)->setCountrycode($nCountryCode)->setCardname($szCardName)->setCardnumber($szCardNumber)->setExpirydatemonth($szExpiryDateMonth)->setExpirydateyear($szExpiryDateYear)->setStartdatemonth($szStartDateMonth)->setStartdateyear($szStartDateYear)->setIssuenumber($szIssueNumber)->setCv2($szCV2);
     Mage::getSingleton('checkout/session')->setRedirectionmethod('_runRedirectedPaymentComplete');
     $payment->getOrder()->setIsHostedPaymentPending(true);
     /* serve out a dummy CrossReference as the TransactionId - this need to be done to enable the "Refund" button 
        in the Magento CreditMemo internal refund mechanism */
     $payment->setTransactionId($szOrderID . "_" . date('YmdHis'));
 }