本文整理汇总了PHP中Varien_Object::setIsTransactionClosed方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Object::setIsTransactionClosed方法的具体用法?PHP Varien_Object::setIsTransactionClosed怎么用?PHP Varien_Object::setIsTransactionClosed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Object
的用法示例。
在下文中一共展示了Varien_Object::setIsTransactionClosed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: capture
/**
* Capture (confirm) an open transaction ('AUTHORIZED') at svea. We use the
* ConfirmTransaction class directly because the operation is simple.
*
* @param Varien_Object $payment
* @param float $amount
* @return $this|void
* @throws Mage_Payment_Exception
*/
public function capture(Varien_Object $payment, $amount)
{
$sveaOrderId = $payment->getParentTransactionId();
if (null === $sveaOrderId) {
// If there is no previous authorization
$sveaOrderId = $payment->getTransactionId();
}
$order = $payment->getOrder();
$paymentMethodConfig = $this->getSveaStoreConfClass($order->getStoreId());
$config = new SveaMageConfigProvider($paymentMethodConfig);
$countryId = $order->getBillingAddress()->getCountryId();
$confirmTransactionRequest = new Svea\HostedService\ConfirmTransaction($config);
$confirmTransactionRequest->countryCode = $countryId;
$confirmTransactionRequest->transactionId = $sveaOrderId;
$defaultCaptureDate = explode('T', date('c'));
// [0] contains date part
$confirmTransactionRequest->captureDate = $defaultCaptureDate[0];
$response = $confirmTransactionRequest->doRequest();
if ($response->accepted !== 1) {
$message = 'Capture failed for transaction ' . $sveaOrderId . ': ' . $response->errormessage . ' (' . $response->resultcode . ')';
throw new Mage_Payment_Exception($message);
}
$result = $this->_flatten($response);
$payment->setIsTransactionClosed(true)->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $result);
return $this;
}
示例2: authorize
/** For authorization **/
public function authorize(Varien_Object $payment, $amount)
{
Mage::log('authorize method', null, 'cmss.log');
#getOrderid
$order = $payment->getOrder();
$billing = $order->getBillingAddress();
#creating request object for stripe
$request = array('amount' => $amount * 100, 'currency' => strtolower($order->getBaseCurrencyCode()), 'card' => array('number' => $payment->getCcNumber(), 'exp_month' => sprintf('%02d', $payment->getCcExpMonth()), 'exp_year' => $payment->getCcExpYear(), 'cvc' => $payment->getCcCid(), 'name' => $billing->getName(), 'address_line1' => $billing->getStreet(1), 'address_line2' => $billing->getStreet(2), 'address_zip' => $billing->getPostcode(), 'address_state' => $billing->getRegion(), 'address_country' => $billing->getCountry()), 'description' => sprintf('#%s, %s', $order->getIncrementId(), $order->getCustomerEmail()));
#request to stripe to charge the card
try {
//Stripe::setApiKey('sk_test_4SaT1bB6uEuFF5POEUnsSZHJ');
$response = Stripe_Charge::create($request);
Mage::log('authorize method' . print_r($response, true), null, 'cmss.log');
//$fmessage=$response->failure_code;
if ($response->paid) {
$result = 1;
} else {
$result = false;
}
} catch (Exception $e) {
$this->debugData($e->getMessage());
Mage::throwException(Mage::helper('paygate')->__($e->getMessage()));
}
if ($result === false) {
$errorCode = 'Invalid Data';
$errorMsg = $this->_getHelper()->__('Error Processing the request');
} else {
Mage::log($result, null, $this->getCode() . '.log');
//process result here to check status etc as per payment gateway.
// if invalid status throw exception
if ($result == 1) {
//Mage::log('sdsd'.$response->id, null, 'cmss.log');
$payment->setTransactionId($response->id);
$payment->setIsTransactionClosed(1);
$payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('key1' => 'value1', 'key2' => 'value2'));
//
} else {
Mage::throwException($errorMsg);
}
// Add the comment and save the order
}
if ($errorMsg) {
Mage::throwException($errorMsg);
}
$this->capture($payment, $order->getGrandTotal());
// Create invoice
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(array());
$invoice->register();
$invoice->setCanVoidFlag(true);
$invoice->getOrder()->setIsInProcess(true);
$invoice->setState(2);
if (Mage::helper('sales')->canSendNewInvoiceEmail($order->getStoreId())) {
$invoice->setEmailSent(true);
$invoice->sendEmail();
}
$invoice->save();
$order->setTotalPaid($order->getBaseGrandTotal());
$order->addStatusHistoryComment('Captured online amount of R$' . $order->getBaseGrandTotal(), false);
$order->save();
//Mage::log($response->id, null, 'mss.log');
return $this;
}
示例3: capture
/**
* Authorize and Capture
*
* @param Varien_Object $payment
* @param float $amount
*
* @return Amazon_Payments_Model_PaymentMethod
*/
public function capture(Varien_Object $payment, $amount)
{
$transactionAuth = $payment->lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
$authReferenceId = $transactionAuth->getTxnId();
$order = $payment->getOrder();
$result = $this->_getApi($order->getStoreId())->capture($authReferenceId, $authReferenceId, $amount, $order->getBaseCurrencyCode(), $this->_getSoftDescriptor());
if ($result) {
$status = $result->getCaptureStatus();
// Error handling
switch ($status->getState()) {
case Amazon_Payments_Model_Api::AUTH_STATUS_PENDING:
Mage::getSingleton('adminhtml/session')->addError('The invoice you are trying to create is for an authorization that is more than 7 days old. A capture request has been made. Please try and create this invoice again in 1 hour, allowing time for the capture to process.');
// cont'd...
// cont'd...
case Amazon_Payments_Model_Api::AUTH_STATUS_DECLINED:
case Amazon_Payments_Model_Api::AUTH_STATUS_CLOSED:
$this->_setErrorCheck();
Mage::throwException('Amazon Payments capture error: ' . $status->getReasonCode() . ' - ' . $status->getReasonDescription());
break;
case Amazon_Payments_Model_Api::AUTH_STATUS_COMPLETED:
// Already captured.
break;
default:
$this->_setErrorCheck();
Mage::throwException('Amazon Payments capture error.');
break;
}
$payment->setTransactionId($result->getAmazonCaptureId());
$payment->setParentTransactionId($authReferenceId);
$payment->setIsTransactionClosed(false);
} else {
$this->_setErrorCheck();
Mage::throwException('Unable to capture payment at this time. Please try again later.');
}
return $this;
}
示例4: capture
public function capture(Varien_Object $payment, $amount)
{
$session = Mage::getSingleton('core/session');
$logger = Mage::helper('worldpay/logger');
if ($session->getData('wp_3dscompletionNeeded')) {
$payment->setIsTransactionClosed(0);
$payment->setSkipOrderProcessing(true);
$payment->setStatus(self::STATUS_APPROVED);
$payment->setAmount($amount);
$payment->setShouldCloseParentTransaction(1);
$payment->setAdditionalInformation("worldpayOrderCode", $session->getData('wp_orderCode'));
$payment->setLastTransId($session->getData('wp_orderCode'));
$payment->setTransactionId($session->getData('wp_orderCode'));
$session->setData('wp_3dscompletionNeeded', false);
return $this;
}
$worldpayOrderCode = $payment->getData('last_trans_id');
if ($worldpayOrderCode) {
$worldpay = $this->setupWorldpay();
try {
$authorizationTransaction = $payment->getAuthorizationTransaction();
if ($authorizationTransaction) {
$payment->setAdditionalInformation("worldpayOrderCode", $authorizationTransaction->getTxnId());
$worldpayOrderCode = $authorizationTransaction->getTxnId();
} else {
$worldpayOrderCode = $payment->getAdditionalInformation('worldpayOrderCode');
}
$worldpay->captureAuthorisedOrder($worldpayOrderCode, $amount * 100);
$payment->setShouldCloseParentTransaction(1)->setIsTransactionClosed(1);
$logger->log('Capture Order: ' . $session->getData('wp_orderCode') . ' success');
} catch (Exception $e) {
$logger->log('Capture Order: ' . $session->getData('wp_orderCode') . ' failed with ' . $e->getMessage());
Mage::throwException('Payment failed, please try again later ' . $e->getMessage());
}
} else {
$payment->setAdditionalInformation('payment_type', 'capture');
return $this->createOrder($payment, $amount, false);
}
}
示例5: refund
/**
* Refund money
*
* @param Varien_Object $payment
* @param float $amount
* @return Mage_Payment_Model_Abstract
*/
public function refund(Varien_Object $payment, $amount)
{
//parent::refund($payment, $amount);
$captureTxnId = $payment->getParentTransactionId();
if ($captureTxnId) {
$order = $payment->getOrder();
$request = $this->_getApiRequest();
$request->setData('transaction_id', $captureTxnId)->setData('amount', $amount)->setData('currency_code', $order->getBaseCurrencyCode())->setData('cc_number', $payment->getCcLast4());
$canRefundMore = $order->canCreditmemo();
$allRefunds = (double) $amount + (double) $order->getBaseTotalOnlineRefunded() + (double) $order->getBaseTotalOfflineRefunded();
$isFullRefund = !$canRefundMore && 0.0001 > (double) $order->getBaseGrandTotal() - $allRefunds;
$request->setData('is_full_refund', (int) $isFullRefund);
// whether to close capture transaction
$invoiceCanRefundMore = $payment->getCreditmemo()->getInvoice()->canRefund();
$payment->setShouldCloseParentTransaction($invoiceCanRefundMore ? 0 : 1);
$payment->setIsTransactionClosed(1);
$api = $this->_getApi()->doRefund($request);
$this->_importResultToPayment($payment, $api->getResponse());
return $api->getResponse();
} else {
Mage::throwException(Mage::helper('enterprise_pbridge')->__('Impossible to issue a refund transaction, because capture transaction does not exist.'));
}
}
示例6: void
/**
* Void payment abstract method
*
* @param Varien_Object $payment
*
* @return Mage_Payment_Model_Abstract
*/
public function void(Varien_Object $payment)
{
try {
// Init the environment
$this->_getWrapper()->init($payment->getOrder()->getStoreId());
// Retrieve the transaction ID
$transactionId = $this->_getWrapper()->getCleanTransactionId($payment->getLastTransId());
// Load the transaction from Braintree
$transaction = Braintree_Transaction::find($transactionId);
// If the transaction hasn't yet settled we can't do partial refunds
if ($transaction->status !== Braintree_Transaction::AUTHORIZED || $transaction->status !== Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
Mage::throwException($this->_getHelper()->__('You can only void authorized/submitted for settlement payments, please setup a credit memo if you wish to refund this order.'));
}
// Swap between refund and void
$result = Braintree_Transaction::void($transactionId);
// If it's a success close the transaction
if ($result->success) {
$payment->setIsTransactionClosed(1);
} else {
if ($result->errors->deepSize() > 0) {
Mage::throwException($this->_getWrapper()->parseErrors($result->errors->deepAll()));
} else {
Mage::throwException('Unknown');
}
}
} catch (Exception $e) {
Mage::throwException($this->_getHelper()->__('An error occurred whilst trying to void the transaction: ') . $e->getMessage());
}
return $this;
}
示例7: refund
public function refund(Varien_Object $payment, $amount)
{
if (Mage::getStoreConfig('billmate/settings/activation')) {
$k = Mage::helper('billmateinvoice')->getBillmate(true, false);
$invoiceId = $payment->getMethodInstance()->getInfoInstance()->getAdditionalInformation('invoiceid');
$values = array('number' => $invoiceId);
$paymentInfo = $k->getPaymentInfo($values);
if ($paymentInfo['PaymentData']['status'] == 'Paid' || $paymentInfo['PaymentData']['status'] == 'Factoring') {
$values['partcredit'] = false;
$result = $k->creditPayment(array('PaymentData' => $values));
if (isset($result['code'])) {
Mage::throwException(utf8_encode($result['message']));
}
if (!isset($result['code'])) {
$payment->setTransactionId($result['number']);
$payment->setIsTransactionClosed(1);
}
}
}
return $this;
}
示例8: _authorize
/**
* Authorize or Capture payment
*
* @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
* @param float $amount
* @param bool $capture
* @return $this
*/
private function _authorize(Varien_Object $payment, $amount, $capture)
{
$order = $payment->getOrder();
/* @var $order Mage_Sales_Model_Order */
$multiToken = false;
$cardData = null;
$additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null);
$secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null;
$saveCreditCard = !!(bool) $additionalData->getCcSaveFuture();
$customerId = $additionalData->getCustomerId();
if ($saveCreditCard) {
$multiToken = true;
$cardData = new HpsCreditCard();
$cardData->number = $payment->getCcLast4();
$cardData->expYear = $payment->getCcExpYear();
$cardData->expMonth = $payment->getCcExpMonth();
}
$chargeService = $this->_getChargeService();
$cardHolder = $this->_getCardHolderData($order);
$details = $this->_getTxnDetailsData($order);
$cardOrToken = new HpsTokenData();
$cardOrToken->tokenValue = $secureToken;
try {
if ($capture) {
if ($payment->getCcTransId()) {
$response = $chargeService->capture($payment->getCcTransId(), $amount);
} else {
$response = $chargeService->charge($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
}
} else {
$response = $chargeService->authorize($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
}
$this->_debugChargeService($chargeService);
$payment->setStatus(self::STATUS_APPROVED);
$payment->setAmount($amount);
$payment->setLastTransId($response->transactionId);
$payment->setCcTransId($response->transactionId);
$payment->setTransactionId($response->transactionId);
$payment->setIsTransactionClosed(0);
if ($multiToken) {
$tokenData = $response->tokenData;
/* @var $tokenData HpsTokenData */
if ($tokenData->responseCode == '0') {
if ($customerId > 0) {
Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType, $customerId);
} else {
Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType);
}
} else {
Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN);
}
}
} catch (HpsCreditException $e) {
Mage::logException($e);
$this->_debugChargeService($chargeService, $e);
$payment->setStatus(self::STATUS_DECLINED);
$this->throwUserError($e->getMessage(), $e->resultText, TRUE);
} catch (HpsException $e) {
$this->_debugChargeService($chargeService, $e);
$payment->setStatus(self::STATUS_ERROR);
$this->throwUserError($e->getMessage(), NULL, TRUE);
} catch (Exception $e) {
$this->_debugChargeService($chargeService, $e);
Mage::logException($e);
$payment->setStatus(self::STATUS_ERROR);
$this->throwUserError($e->getMessage());
}
return $this;
}
示例9: void
/**
* Voids transaction
*
* @param Varien_Object $payment
* @return Braintree_Payments_Model_Paymentmethod
*/
public function void(Varien_Object $payment)
{
$transactionIds = array();
$invoice = Mage::registry('current_invoice');
$message = false;
if ($invoice && $invoice->getId() && $invoice->getTransactionId()) {
$transactionIds[] = Mage::helper('braintree_payments')->clearTransactionId($invoice->getTransactionId());
} else {
$collection = Mage::getModel('sales/order_payment_transaction')->getCollection()->addFieldToSelect('txn_id')->addOrderIdFilter($payment->getOrder()->getId())->addTxnTypeFilter(array(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE));
$fetchedIds = $collection->getColumnValues('txn_id');
foreach ($fetchedIds as $transactionId) {
$txnId = Mage::helper('braintree_payments')->clearTransactionId($transactionId);
if (!in_array($txnId, $transactionIds)) {
$transactionIds[] = $txnId;
}
}
}
foreach ($transactionIds as $transactionId) {
$transaction = Braintree_Transaction::find($transactionId);
if ($transaction->status !== Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT && $transaction->status !== Braintree_Transaction::AUTHORIZED) {
$message = Mage::helper('braintree_payments')->__('Some transactions are already settled or voided and cannot be voided.');
throw new Mage_Core_Exception($message, self::VOID_ALREADY_SETTLED_EXCEPTION);
}
if ($transaction->status === Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
$message = Mage::helper('braintree_payments')->__('Voided capture.');
}
}
$errors = '';
foreach ($transactionIds as $transactionId) {
$this->_debug('void-' . $transactionId);
$result = Braintree_Transaction::void($transactionId);
$this->_debug($result);
if (!$result->success) {
$errors .= ' ' . Mage::helper('braintree_payments/error')->parseBraintreeError($result);
} else {
if ($message) {
$payment->setMessage($message);
}
}
}
if ($errors) {
Mage::throwException(Mage::helper('braintree_payments')->__('There was an error voiding the transaction.') . $errors);
} else {
$match = true;
foreach ($transactionIds as $transactionId) {
$collection = Mage::getModel('sales/order_payment_transaction')->getCollection()->addFieldToFilter('parent_txn_id', array('eq' => $transactionId))->addFieldToFilter('txn_type', Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID);
if ($collection->getSize() < 1) {
$match = false;
}
}
if ($match) {
$payment->setIsTransactionClosed(1);
}
}
return $this;
}
示例10: refund
/**
* Refund specified amount for payment
*
* @param \Varien_Object $payment
* @param float $amount
*
* @return $this
* @throws \Mage_Core_Exception
*/
public function refund(Varien_Object $payment, $amount)
{
try {
// Attempt to load the invoice
/* @var $invoice Mage_Sales_Model_Order_Invoice */
$invoice = $payment->getCreditmemo()->getInvoice();
if (!$invoice) {
Mage::throwException('Unable to load invoice from credit memo.');
}
// Init the environment
$this->_getWrapper()->init($payment->getOrder()->getStoreId());
// Convert the refund amount
$refundAmount = $this->_getWrapper()->getCaptureAmount($payment->getOrder(), $amount);
// Retrieve the transaction ID
$transactionId = $this->_getWrapper()->getCleanTransactionId($invoice->getTransactionId());
// Load the transaction from Braintree
$transaction = Braintree_Transaction::find($transactionId);
// If the transaction hasn't yet settled we can't do partial refunds
if ($transaction->status === Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
// If we're doing a partial refund and it's not settled it's a no go
if ($transaction->amount != $refundAmount) {
Mage::throwException($this->_getHelper()->__('This transaction has not yet settled, please wait until the transaction has settled to process a partial refund.'));
}
}
// Swap between refund and void
$result = $transaction->status === Braintree_Transaction::SETTLED || $transaction->status == Braintree_Transaction::SETTLING || isset($transaction->paypal) && isset($transaction->paypal['paymentId']) && !empty($transaction->paypal['paymentId']) ? Braintree_Transaction::refund($transactionId, $refundAmount) : Braintree_Transaction::void($transactionId);
// If it's a success close the transaction
if ($result->success) {
// Pass over the transaction ID
$payment->getCreditmemo()->setRefundTransactionId($result->transaction->id);
// Only close the transaction once the
if ($transaction->amount == $refundAmount) {
$payment->setIsTransactionClosed(1);
// Mark the invoice as canceled if the invoice was completely refunded
$invoice->setState(Mage_Sales_Model_Order_Invoice::STATE_CANCELED);
}
} else {
if ($result->errors->deepSize() > 0) {
Mage::throwException($this->_getWrapper()->parseErrors($result->errors->deepAll()));
} else {
Mage::throwException('An unknown error has occurred whilst trying to process the transaction');
}
}
} catch (Exception $e) {
Mage::throwException($this->_getHelper()->__('An error occurred whilst trying to process the refund: ') . $e->getMessage());
}
return $this;
}
示例11: capture
/**
* The transaction is captured with the specified amount.
*
* @param Varien_Object $payment The payment object containing all the payment specific data for the order.
* @param unknown_type $amount The amount to capture. This may be less than the amount of the order but not more.
* @return Customweb_SaferpayCw_Model_Method
*/
public function capture(Varien_Object $payment, $amount)
{
$invoice = Mage::registry('current_invoice');
try {
$transaction = $this->getHelper()->loadTransactionByPayment($payment->getId());
$order = $payment->getOrder();
Customweb_SaferpayCw_Model_ConfigurationAdapter::setStore($order);
$adapter = $this->getHelper()->createContainer()->getBean('Customweb_Payment_BackendOperation_Adapter_Service_ICapture');
if ($transaction->getTransactionObject()->isCapturePossible()) {
if ($transaction->getTransactionObject()->isPartialCapturePossible()) {
if ($invoice instanceof Mage_Sales_Model_Order_Invoice) {
$items = $this->getInvoiceItems($invoice);
} else {
$items = Customweb_Util_Invoice::getItemsByReductionAmount($transaction->getTransactionObject()->getTransactionContext()->getOrderContext()->getInvoiceItems(), $amount, $transaction->getTransactionObject()->getCurrencyCode());
}
$adapter->partialCapture($transaction->getTransactionObject(), $items, true);
} else {
$adapter->capture($transaction->getTransactionObject());
}
$transaction->save();
}
if ($transaction->getTransactionObject()->isCaptured()) {
$payment->setIsTransactionClosed(false);
$captures = $transaction->getTransactionObject()->getCaptures();
$capture = end($captures);
$payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('TRANSACTIONID' => $transaction->getTransactionObject()->getPaymentId(), 'CAPTUREID' => $capture->getCaptureId(), 'AMOUNT' => $capture->getAmount(), 'AMT' => $capture->getAmount(), 'STATUS' => $capture->getStatus()));
$this->_generateTransactionId($payment, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
return $this;
} else {
$this->getHelper()->log("Capture failed. Transaction error messages : " . print_r($transaction->getTransactionObject()->getErrorMessages(), true));
$messages = $transaction->getTransactionObject()->getErrorMessages();
Mage::throwException($this->getHelper()->__('The invoice could not be captured and processed. Reason: ') . end($messages));
}
} catch (Exception $e) {
$this->getHelper()->log("Exception in Method::capture() : " . $e->getMessage());
Mage::getSingleton('core/session')->addError($e->getMessage());
throw $e;
}
}
示例12: _authorize
/**
* Authorize or Capture payment
*
* @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
* @param float $amount
* @param bool $capture
* @return $this
*/
private function _authorize(Varien_Object $payment, $amount, $capture)
{
$order = $payment->getOrder();
/* @var $order Mage_Sales_Model_Order */
$multiToken = false;
$cardData = null;
$additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null);
$secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null;
$saveCreditCard = !!(bool) $additionalData->getCcSaveFuture();
$customerId = $additionalData->getCustomerId();
$giftService = $this->_getGiftService();
$giftCardNumber = $additionalData->getGiftcardNumber();
if ($giftCardNumber) {
// 1. check balance
$giftcard = new HpsGiftCard();
$giftcard->number = $giftCardNumber;
$giftResponse = $giftService->balance($giftcard);
// 2. is balance > amount?
if ($giftResponse->balanceAmount > $amount) {
// 2.yes. process full to gift
try {
if (strpos($this->getConfigData('secretapikey'), '_cert_') !== false) {
$giftresp = $giftService->sale($giftcard, 10.0);
} else {
$giftresp = $giftService->sale($giftcard, $amount);
}
$order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $amount . '. [full payment]');
$payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('gift_card_number' => $giftCardNumber, 'gift_card_transaction' => $giftresp->transactionId, 'gift_card_amount_charged' => $amount));
$payment->setStatus(self::STATUS_APPROVED);
$payment->setAmount($amount);
$payment->setLastTransId($response->transactionId);
$payment->setTransactionId($response->transactionId);
$payment->setIsTransactionClosed(0);
return $this;
} catch (Exception $e) {
Mage::logException($e);
$payment->setStatus(self::STATUS_ERROR);
$this->throwUserError($e->getMessage(), null, true);
}
} else {
// 2.no. process full gift card amt and card process remainder
$giftresp = $giftService->sale($giftcard, $giftResponse->balanceAmount);
$order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $giftResponse->balanceAmount . '. [partial payment]')->save();
$payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('gift_card_number' => $giftCardNumber, 'gift_card_transaction' => $giftresp->transactionId, 'gift_card_amount_charged' => $giftResponse->balanceAmount));
$payment->setAmount($giftResponse->balanceAmount)->save();
$amount = $amount - $giftResponse->balanceAmount;
// remainder
// 3. TODO: if the card payment fails later, refund the gift transaction
}
}
if ($saveCreditCard) {
$multiToken = true;
$cardData = new HpsCreditCard();
$cardData->number = $payment->getCcLast4();
$cardData->expYear = $payment->getCcExpYear();
$cardData->expMonth = $payment->getCcExpMonth();
}
$chargeService = $this->_getChargeService();
$cardHolder = $this->_getCardHolderData($order);
$details = $this->_getTxnDetailsData($order);
$cardOrToken = new HpsTokenData();
$cardOrToken->tokenValue = $secureToken;
try {
if ($capture) {
if ($payment->getCcTransId()) {
$response = $chargeService->capture($payment->getCcTransId(), $amount);
} else {
$response = $chargeService->charge($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
}
} else {
$response = $chargeService->authorize($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
}
$this->_debugChargeService($chargeService);
$payment->setStatus(self::STATUS_APPROVED);
$payment->setAmount($amount);
$payment->setLastTransId($response->transactionId);
$payment->setCcTransId($response->transactionId);
$payment->setTransactionId($response->transactionId);
$payment->setIsTransactionClosed(0);
if ($giftCardNumber) {
$order->addStatusHistoryComment('Remaining amount to be charged to credit card ' . $this->_formatAmount($amount) . '. [partial payment]')->save();
}
if ($multiToken) {
$tokenData = $response->tokenData;
/* @var $tokenData HpsTokenData */
if ($tokenData->responseCode == '0') {
if ($customerId > 0) {
Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType, $customerId);
} else {
Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType);
}
} else {
//.........这里部分代码省略.........
示例13: void
public function void(Varien_Object $payment)
{
try {
$result = Braintree_Transaction::void($payment->getCcTransId());
if ($result->success) {
$payment->setIsTransactionClosed(1);
} else {
Mage::throwException($result->message);
}
} catch (Exception $e) {
Mage::throwException(sprintf('There was an error voiding the transaction. (%s)', $e->getMessage()));
}
return $this;
}
示例14: authorize
/**
* Authorize payment abstract method
*
* @param Varien_Object $payment
* @param float $amount
*
* @return Mage_Payment_Model_Abstract
*/
public function authorize(Varien_Object $payment, $amount)
{
// Leave the transaction opened so it can later be captured in backend
$payment->setIsTransactionClosed(false);
$this->_doOpenpayTransaction($payment, $amount, false);
return $this;
}
示例15: authorize
/**
* Authorize a payment
*
* @param Varien_Object $payment
* @param float $amount
*
* @return Mage_Payment_Model_Abstract
*/
public function authorize(Varien_Object $payment, $amount)
{
if (!$this->_isBackendOrder) {
if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
$transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
$payment->setTransactionId($transID);
$payment->setIsTransactionClosed(0);
Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
return $this;
} elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
//$payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
return $this;
}
}
/* @var Mage_Sales_Model_Order_Payment $payment */
if ($amount <= 0) {
Mage::throwException(Mage::helper('paygate')->__('Invalid amount for authorize.'));
}
$request = Mage::getModel('ewayrapid/request_token');
/** @todo there's an error in case recurring profile */
if (!$payment->getIsRecurring()) {
$this->_shouldCreateOrUpdateToken($payment, $request);
}
$amount = round($amount * 100);
$request->doAuthorisation($payment, $amount);
return $this;
}