本文整理汇总了PHP中Mage_Payment_Model_Info::setTransactionId方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Payment_Model_Info::setTransactionId方法的具体用法?PHP Mage_Payment_Model_Info::setTransactionId怎么用?PHP Mage_Payment_Model_Info::setTransactionId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Payment_Model_Info
的用法示例。
在下文中一共展示了Mage_Payment_Model_Info::setTransactionId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _place
/**
* Send request with new payment to PinPayments gateway
*
* @param Mage_Payment_Model_Info $payment
* @param string $requestType
* @param Dwyera_Pinpay_Model_Request
* @return boolean Returns true if order was successfully placed
* @throws Mage_Core_Exception
* @throws InvalidArgumentException
*/
protected function _place($payment, $requestType, $request)
{
$payment->setAmount($request->getAmount());
switch ($requestType) {
case self::REQUEST_TYPE_AUTH_ONLY:
case self::REQUEST_TYPE_AUTH_CAPTURE:
case self::REQUEST_TYPE_CAPTURE_ONLY:
break;
default:
throw new InvalidArgumentException("Invalid request type of {$requestType}");
}
$httpResponse = $this->_postRequest($request, $requestType);
// wrap the gateway response in the pinpay/result model
/** @var Dwyera_Pinpay_Model_Result $result */
$result = Mage::getModel("pinpay/result", $httpResponse);
switch ($result->getGatewayResponseStatus()) {
case $result::RESPONSE_CODE_APPROVED:
// Sets the response token
$payment->setCcTransId('' . $result->getResponseToken());
$payment->setTransactionId('' . $result->getResponseToken());
return true;
case $result::RESPONSE_CODE_SUSP_FRAUD:
$payment->setIsTransactionPending(true);
$payment->setIsFraudDetected(true);
$payment->setCcTransId('' . $result->getErrorToken());
$payment->setTransactionId('' . $result->getErrorToken());
return true;
default:
Mage::log('Payment could not be processed. ' . $result->getErrorDescription(), Zend_Log::INFO, self::$logFile);
Mage::throwException(Mage::helper('pinpay')->__($result->getErrorDescription() . self::RESPONSE_APPEND_MSG));
}
}
示例2: collectPayment
public function collectPayment(\Mage_Payment_Model_Info $payment, $amount, $capture = true)
{
$Currency = Mage::app()->getStore()->getBaseCurrencyCode();
require_once MAGENTO_ROOT . '/lib/Start/autoload.php';
# At the top of your PHP file
$token = isset($_POST['payfortToken']) ? $_POST['payfortToken'] : false;
$email = isset($_POST['payfortEmail']) ? $_POST['payfortEmail'] : false;
if (!$token || !$email) {
//this block will be executed if the order was authorized earlier and now trying to capture amount
$token_array = $payment->getAdditionalInformation('token');
$token = $token_array['token'];
$email = $token_array['email'];
}
if (!$token || !$email) {
Mage::throwException('Invalid Token');
}
$currency = !isset($Currency) ? 'AED' : $Currency;
if (file_exists(MAGENTO_ROOT . '/data/currencies.json')) {
$currency_json_data = json_decode(file_get_contents(MAGENTO_ROOT . '/data/currencies.json'), 1);
$currency_multiplier = $currency_json_data[$currency];
} else {
$currency_multiplier = 100;
}
$amount_in_cents = $amount * $currency_multiplier;
$order = $payment->getOrder();
$order_items_array_full = array();
foreach ($order->getAllVisibleItems() as $value) {
$order_items_array['title'] = $value->getName();
$order_items_array['amount'] = round($value->getPrice(), 2) * $currency_multiplier;
$order_items_array['quantity'] = $value->getQtyOrdered();
array_push($order_items_array_full, $order_items_array);
}
$shipping_amount = $order->getShippingAmount();
$shipping_amount = $shipping_amount * $currency_multiplier;
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$username = $customer->getName();
$registered_at = date(DATE_ISO8601, strtotime($customer->getCreatedAt()));
} else {
$username = "Guest";
$registered_at = date(DATE_ISO8601, strtotime(date("Y-m-d H:i:s")));
}
$billing_data = $order->getBillingAddress()->getData();
if (is_object($order->getShippingAddress())) {
$shipping_data = $order->getShippingAddress()->getData();
$shipping_address = array("first_name" => $shipping_data['firstname'], "last_name" => $shipping_data['lastname'], "country" => $shipping_data['country_id'], "city" => $shipping_data['city'], "address" => $shipping_data['customer_address'], "phone" => $shipping_data['telephone'], "postcode" => $shipping_data['postcode']);
} else {
$shipping_address = array();
}
$billing_address = array("first_name" => $billing_data['firstname'], "last_name" => $billing_data['lastname'], "country" => $billing_data['country_id'], "city" => $billing_data['city'], "address" => $billing_data['customer_address'], "phone" => $billing_data['telephone'], "postcode" => $billing_data['postcode']);
$shopping_cart_array = array('user_name' => $username, 'registered_at' => $registered_at, 'items' => $order_items_array_full, 'billing_address' => $billing_address, 'shipping_address' => $shipping_address);
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$charge_args = array('description' => "Magento charge for " . $email, 'card' => $token, 'currency' => $currency, 'email' => $email, 'ip' => $_SERVER['REMOTE_ADDR'], 'amount' => $amount_in_cents, 'capture' => $capture, 'shipping_amount' => $shipping_amount, 'shopping_cart' => $shopping_cart_array, 'metadata' => array('reference_id' => $orderId));
$ver = new Mage();
$version = $ver->getVersion();
$userAgent = 'Magento ' . $version . ' / Start Plugin ' . self::PLUGIN_VERSION;
Start::setUserAgent($userAgent);
$method = $payment->getMethodInstance();
if ($method->getConfigData('test_mode') == 1) {
Start::setApiKey($method->getConfigData('test_secret_key'));
} else {
Start::setApiKey($method->getConfigData('live_secret_key'));
}
try {
// Charge the token
$charge = Start_Charge::create($charge_args);
//need to process charge as success or failed
$payment->setTransactionId($charge["id"]);
if ($capture) {
$payment->setIsTransactionClosed(1);
} else {
$payment->setIsTransactionClosed(0);
}
} catch (Start_Error $e) {
$error_code = $e->getErrorCode();
if ($error_code === "card_declined") {
$errorMsg = 'Charge was declined. Please, contact you bank for more information or use a different card.';
} else {
$errorMsg = $e->getMessage();
}
throw new Mage_Payment_Model_Info_Exception($errorMsg);
}
//need to process charge as success or failed
}
示例3: _void
/**
* Send void request to MerchantWare gateway
*
* @param Mage_Payment_Model_Info $payment
* @return $result
* @throws Mage_Core_Exception
*/
private function _void($payment)
{
$error = false;
$soapClient = $this->getSoapApi();
$this->iniRequest();
//Add token
if ($payment->getParentTransactionId() !== FALSE) {
$this->_request->token = $payment->getParentTransactionId();
} else {
//Cannot void
$error = Mage::helper('merchantware_directpost')->__('No previous transactions could be found. Cannot void this transaction.');
Mage::throwException($error);
}
//Add order info
$order = $payment->getOrder();
$this->_request->merchantTransactionId = $order->getIncrementId();
$additionalInfo = array();
try {
$result = $soapClient->Void($this->_request);
$result = $result->VoidResult;
if (!empty($result->ErrorMessage)) {
$additionalInfo['ErrorMessage'] = $result->ErrorMessage;
}
//Authorization is approved.
$additionalInfo['ApprovalStatus'] = $result->ApprovalStatus;
$additionalInfo['Amount'] = $result->Amount;
$additionalInfo['AuthorizationCode'] = $result->AuthorizationCode;
if (!empty($result->Cardholder)) {
$additionalInfo['Cardholder'] = $result->Cardholder;
}
if (!empty($result->AvsResponse)) {
$additionalInfo['AvsResponse'] = $result->AvsResponse;
}
if (!empty($result->CvResponse)) {
$additionalInfo['CvResponse'] = $result->AvsResponse;
}
$additionalInfo['CardType'] = $result->CardType;
if (!empty($result->InvoiceNumber)) {
$additionalInfo['InvoiceNumber'] = $result->InvoiceNumber;
}
$additionalInfo['Token'] = $result->Token;
$additionalInfo['TransactionDate'] = $result->TransactionDate;
$additionalInfo['TransactionType'] = $result->TransactionType;
if (!empty($result->ExtraData)) {
$additionalInfo['ExtraData'] = $result->ExtraData;
}
switch ($this->_parseApprovalStatus($result->ApprovalStatus)) {
case self::APPROVAL_STATUS_APPROVED:
//Void Approved.
$message = 'Type: Void | ApprovalStatus: ' . $result->ApprovalStatus . ' | Amount: ' . $result->Amount;
$payment->setSkipTransactionCreation(false);
$payment->setTransactionId($result->Token)->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, null, false, $message)->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $additionalInfo)->setIsTransactionClosed(1)->save();
break;
case self::APPROVAL_STATUS_DECLINED:
case self::APPROVAL_STATUS_DECLINED_DUPLICATE:
case self::APPROVAL_STATUS_FAILED:
$error = Mage::helper('merchantware_directpost')->__('Void request failed. Gateway error response: %s', $result->ApprovalStatus, $result->ErrorMessage);
Mage::throwException($error);
break;
case self::APPROVAL_STATUS_REFERRAL:
default:
$error = Mage::helper('merchantware_directpost')->__('Unable to void this transaction. Gateway approval status: %s | Gateway error response: %s', $result->ApprovalStatus, $result->ErrorMessage);
Mage::throwException($error);
break;
}
return $result;
} catch (Exception $e) {
Mage::throwException(Mage::helper('merchantware_directpost')->__('Gateway request error: %s', $e->getMessage()));
}
if ($error !== false) {
Mage::throwException($error);
}
return false;
}