- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们商店的基础货币是美元,我们为国际客户使用 PayPal。我们希望使用 ccAvenue (INR) 作为印度客户的支付网关。不幸的是,ccAvenue 不读取货币。所以 12 美元将从我们的网站推出,ccAvenue 会将其解读为 12 印度卢比,而不是正确的 600 印度卢比。
如何即时转换金额(从美元到印度卢比),以便我们的网站向 ccAvenue 发送正确的金额?最好这应该在插件中使用实时货币转换服务来完成。但是,我们对粗略的解决方法持开放态度 - 例如每周两次手动更新转换率等。这是指向 free ccavenue woocommerce plugin 的链接。 .
任何帮助将非常感激。
这是插件的 index.php:
<?php
/*
Plugin Name: WooCommerce CCAvenue gateway
Plugin URI: http://mrova.com/
Description: Extends WooCommerce with mrova ccavenue gateway.
Version: 1.1
Author: mRova
Author URI: http://mrova.com/
Copyright: © 2009-2012 mRova.
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_action('plugins_loaded', 'woocommerce_mrova_ccave_init', 0);
function woocommerce_mrova_ccave_init() {
if ( !class_exists( 'WC_Payment_Gateway' ) ) return;
/**
* Localisation
*/
load_plugin_textdomain('wc-mrova-ccave', false, dirname( plugin_basename( __FILE__ ) ) . '/languages');
/**
* Gateway class
*/
class WC_Mrova_Ccave extends WC_Payment_Gateway {
protected $msg = array();
public function __construct(){
// Go wild in here
$this -> id = 'ccavenue';
$this -> method_title = __('CCAvenue', 'mrova');
$this -> icon = WP_PLUGIN_URL . "/" . plugin_basename(dirname(__FILE__)) . '/images/logo.gif';
$this -> has_fields = false;
$this -> init_form_fields();
$this -> init_settings();
$this -> title = $this -> settings['title'];
$this -> description = $this -> settings['description'];
$this -> merchant_id = $this -> settings['merchant_id'];
$this -> working_key = $this -> settings['working_key'];
$this -> redirect_page_id = $this -> settings['redirect_page_id'];
$this -> liveurl = 'https://www.ccavenue.com/shopzone/cc_details.jsp';
$this -> msg['message'] = "";
$this -> msg['class'] = "";
add_action('init', array(&$this, 'check_ccavenue_response'));
add_action('valid-ccavenue-request', array(&$this, 'successful_request'));
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
add_action('woocommerce_receipt_ccavenue', array(&$this, 'receipt_page'));
add_action('woocommerce_thankyou_ccavenue',array(&$this, 'thankyou_page'));
}
function init_form_fields(){
$this -> form_fields = array(
'enabled' => array(
'title' => __('Enable/Disable', 'mrova'),
'type' => 'checkbox',
'label' => __('Enable CCAvenue Payment Module.', 'mrova'),
'default' => 'no'),
'title' => array(
'title' => __('Title:', 'mrova'),
'type'=> 'text',
'description' => __('This controls the title which the user sees during checkout.', 'mrova'),
'default' => __('CCAvenue', 'mrova')),
'description' => array(
'title' => __('Description:', 'mrova'),
'type' => 'textarea',
'description' => __('This controls the description which the user sees during checkout.', 'mrova'),
'default' => __('Pay securely by Credit or Debit card or internet banking through CCAvenue Secure Servers.', 'mrova')),
'merchant_id' => array(
'title' => __('Merchant ID', 'mrova'),
'type' => 'text',
'description' => __('This id(USER ID) available at "Generate Working Key" of "Settings and Options at CCAvenue."')),
'working_key' => array(
'title' => __('Working Key', 'mrova'),
'type' => 'text',
'description' => __('Given to Merchant by CCAvenue', 'mrova'),
),
'redirect_page_id' => array(
'title' => __('Return Page'),
'type' => 'select',
'options' => $this -> get_pages('Select Page'),
'description' => "URL of success page"
)
);
}
/**
* Admin Panel Options
* - Options for bits like 'title' and availability on a country-by-country basis
**/
public function admin_options(){
echo '<h3>'.__('CCAvenue Payment Gateway', 'mrova').'</h3>';
echo '<p>'.__('CCAvenue is most popular payment gateway for online shopping in India').'</p>';
echo '<table class="form-table">';
$this -> generate_settings_html();
echo '</table>';
}
/**
* There are no payment fields for CCAvenue, but we want to show the description if set.
**/
function payment_fields(){
if($this -> description) echo wpautop(wptexturize($this -> description));
}
/**
* Receipt Page
**/
function receipt_page($order){
echo '<p>'.__('Thank you for your order, please click the button below to pay with CCAvenue.', 'mrova').'</p>';
echo $this -> generate_ccavenue_form($order);
}
/**
* Process the payment and return the result
**/
function process_payment($order_id){
$order = &new woocommerce_order($order_id);
return array('result' => 'success', 'redirect' => add_query_arg('order',
$order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id'))))
);
}
/**
* Check for valid CCAvenue server callback
**/
function check_ccavenue_response(){
global $woocommerce;
if(isset($_REQUEST['Order_Id']) && isset($_REQUEST['AuthDesc'])){
$order_id_time = $_REQUEST['Order_Id'];
$order_id = explode('_', $_REQUEST['Order_Id']);
$order_id = (int)$order_id[0];
if($order_id != ''){
try{
$order = new woocommerce_order($order_id);
$merchant_id = $_REQUEST['Merchant_Id'];
$amount = $_REQUEST['Amount'];
$checksum = $_REQUEST['Checksum'];
$AuthDesc = $_REQUEST['AuthDesc'];
$Checksum = $this -> verifyCheckSum($merchant_id, $order_id_time, $amount, $AuthDesc, $checksum, $this -> working_key);
$transauthorised = false;
if($order -> status !=='completed'){
if($Checksum=="true")
{
if($AuthDesc=="Y"){
$transauthorised = true;
$this -> msg['message'] = "Thank you for shopping with us. Your account has been charged and your transaction is successful. We will be shipping your order to you soon.";
$this -> msg['class'] = 'success';
if($order -> status == 'processing'){
}else{
$order -> payment_complete();
$order -> add_order_note('CCAvenue payment successful<br/>Bank Ref Number: '.$_REQUEST['nb_bid']);
$order -> add_order_note($this->msg['message']);
$woocommerce -> cart -> empty_cart();
}
}else if($AuthDesc=="B"){
$this -> msg['message'] = "Thank you for shopping with us. We will keep you posted regarding the status of your order through e-mail";
$this -> msg['class'] = 'info';
//Here you need to put in the routines/e-mail for a "Batch Processing" order
//This is only if payment for this transaction has been made by an American Express Card
//since American Express authorisation status is available only after 5-6 hours by mail from ccavenue and at the "View Pending Orders"
}
else{
$this -> msg['class'] = 'error';
$this -> msg['message'] = "Thank you for shopping with us. However, the transaction has been declined.";
//Here you need to put in the routines for a failed
//transaction such as sending an email to customer
//setting database status etc etc
}
}else{
$this -> msg['class'] = 'error';
$this -> msg['message'] = "Security Error. Illegal access detected";
//Here you need to simply ignore this and dont need
//to perform any operation in this condition
}
if($transauthorised==false){
$order -> update_status('failed');
$order -> add_order_note('Failed');
$order -> add_order_note($this->msg['message']);
}
add_action('the_content', array(&$this, 'showMessage'));
}}catch(Exception $e){
// $errorOccurred = true;
$msg = "Error";
}
}
}
}
function showMessage($content){
return '<div class="box '.$this -> msg['class'].'-box">'.$this -> msg['message'].'</div>'.$content;
}
/**
* Generate CCAvenue button link
**/
public function generate_ccavenue_form($order_id){
global $woocommerce;
$order = &new woocommerce_order($order_id);
$redirect_url = ($this -> redirect_page_id=="" || $this -> redirect_page_id==0)?get_site_url() . "/":get_permalink($this -> redirect_page_id);
$order_id = $order_id.'_'.date("ymds");
$checksum = $this -> getCheckSum($this -> merchant_id, $order -> order_total, $order_id, $redirect_url, $this -> working_key);
$ccavenue_args = array(
'Merchant_Id' => $this -> merchant_id,
'Amount' => $order -> order_total,
'Order_Id' => $order_id,
'Redirect_Url' => $redirect_url,
'Checksum' => $checksum,
'billing_cust_name' => $order -> billing_first_name .' '. $order -> billing_last_name,
'billing_cust_address' => $order -> billing_address_1,
'billing_cust_country' => $order -> billing_country,
'billing_cust_state' => $order -> billing_state,
'billing_cust_city' => $order -> billing_city,
'billing_zip' => $order -> shipping_postcode,
'billing_cust_tel',
'billing_cust_email' => $order -> billing_email,
'delivery_cust_name' => $order -> shipping_first_name .' '. $order -> shipping_last_name,
'delivery_cust_address' => $order -> shipping_address_1,
'delivery_cust_country' => $order -> shipping_country,
'delivery_cust_state' => $order -> shipping_state,
'delivery_cust_tel' => '',
'delivery_cust_notes' => '',
'Merchant_Param' => '',
'billing_zip_code' => $order -> billing_postcode,
'delivery_cust_city' => $order -> shipping_city,
'delivery_zip_code' => $order -> shipping_postcode);
$ccavenue_args_array = array();
foreach($ccavenue_args as $key => $value){
$ccavenue_args_array[] = "<input type='hidden' name='$key' value='$value'/>";
}
return '<form action="'.$this -> liveurl.'" method="post" id="ccavenue_payment_form">
' . implode('', $ccavenue_args_array) . '
<input type="submit" class="button-alt" id="submit_ccavenue_payment_form" value="'.__('Pay via CCAvenue', 'mrova').'" /> <a class="button cancel" href="'.$order->get_cancel_order_url().'">'.__('Cancel order & restore cart', 'mrova').'</a>
<script type="text/javascript">
jQuery(function(){
jQuery("body").block(
{
message: "<img src=\"'.$woocommerce->plugin_url().'/assets/images/ajax-loader.gif\" alt=\"Redirecting…\" style=\"float:left; margin-right: 10px;\" />'.__('Thank you for your order. We are now redirecting you to CCAvenue to make payment.', 'mrova').'",
overlayCSS:
{
background: "#fff",
opacity: 0.6
},
css: {
padding: 20,
textAlign: "center",
color: "#555",
border: "3px solid #aaa",
backgroundColor:"#fff",
cursor: "wait",
lineHeight:"32px"
}
});
jQuery("#submit_ccavenue_payment_form").click();
});
</script>
</form>';
}
/**
* CCAvenue Essential Functions
**/
private function getCheckSum($MerchantId,$Amount,$OrderId ,$URL,$WorkingKey)
{
$str ="$MerchantId|$OrderId|$Amount|$URL|$WorkingKey";
$adler = 1;
$adler = $this -> adler32($adler,$str);
return $adler;
}
private function verifyCheckSum($MerchantId,$OrderId,$Amount,$AuthDesc,$CheckSum,$WorkingKey)
{
$str = "$MerchantId|$OrderId|$Amount|$AuthDesc|$WorkingKey";
$adler = 1;
$adler = $this -> adler32($adler,$str);
if($adler == $CheckSum)
return "true" ;
else
return "false" ;
}
private function adler32($adler , $str)
{
$BASE = 65521 ;
$s1 = $adler & 0xffff ;
$s2 = ($adler >> 16) & 0xffff;
for($i = 0 ; $i < strlen($str) ; $i++)
{
$s1 = ($s1 + Ord($str[$i])) % $BASE ;
$s2 = ($s2 + $s1) % $BASE ;
//echo "s1 : $s1 <BR> s2 : $s2 <BR>";
}
return $this -> leftshift($s2 , 16) + $s1;
}
private function leftshift($str , $num)
{
$str = DecBin($str);
for( $i = 0 ; $i < (64 - strlen($str)) ; $i++)
$str = "0".$str ;
for($i = 0 ; $i < $num ; $i++)
{
$str = $str."0";
$str = substr($str , 1 ) ;
//echo "str : $str <BR>";
}
return $this -> cdec($str) ;
}
private function cdec($num)
{
for ($n = 0 ; $n < strlen($num) ; $n++)
{
$temp = $num[$n] ;
$dec = $dec + $temp*pow(2 , strlen($num) - $n - 1);
}
return $dec;
}
/*
* End CCAvenue Essential Functions
**/
// get all pages
function get_pages($title = false, $indent = true) {
$wp_pages = get_pages('sort_column=menu_order');
$page_list = array();
if ($title) $page_list[] = $title;
foreach ($wp_pages as $page) {
$prefix = '';
// show indented child pages?
if ($indent) {
$has_parent = $page->post_parent;
while($has_parent) {
$prefix .= ' - ';
$next_page = get_page($has_parent);
$has_parent = $next_page->post_parent;
}
}
// add to page list array array
$page_list[$page->ID] = $prefix . $page->post_title;
}
return $page_list;
}
}
/**
* Add the Gateway to WooCommerce
**/
function woocommerce_add_mrova_ccave_gateway($methods) {
$methods[] = 'WC_Mrova_Ccave';
return $methods;
}
add_filter('woocommerce_payment_gateways', 'woocommerce_add_mrova_ccave_gateway' );
}
?>
最佳答案
使用第三方机构提供的货币转换API,封装成wordpress函数。
open exchange rates
XE Datafeed
请参阅以下使用谷歌金融 API 的示例代码。
//get the exchange rate from google finance
function get_exchange_rate($from='USD', $to='INR') {
$url = "http://www.google.com/ig/calculator?hl=en&q=1%s=?%s"; //url for the currency convertor
$result = wp_remote_retrieve_body($response = wp_remote_get(sprintf($url, $from, $to))); // fetches the result from the url
if(is_wp_error( $response )) {
return FALSE;
}
$result = explode('"',$result);
$result = str_replace(chr(160), '', substr( $result[3], 0, strpos($result[3], ' ') ) );
return ( $result == 0 ) ? FALSE : $result;
}
关于wordpress - 如何即时将 *USD 转换为 INR* 货币? - WooCommerce,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13134574/
现在已知如下问题,并告诉你这题可以用网络流来解决,你该怎么做,该怎么建出网络流的模型? 一些前提: 显然可以发现绝不可能走横向向左的边,但可能走竖向向上的边(如下图) 那么图其实就是这样的:
条件: 我们需要我们 Magento 网站的默认显示货币是美元,Paypal(基础货币)也需要是美元(因为我们需要客户以美元支付)。 我们的 Fedex a/c 是在新加坡开设的,结果发现运费是以新加
根据 currency_str 和 created_date_time 合并两个数据帧(xrate 和 df)时遇到问题 display(xrate.info()) Int64Index: 1611
我必须匹配像 这样的值 € 6.483,00 或类似的值 18,50% 或者,再次, +65,86 % 在我起草的 Javascript 函数中: function(s) { return /^
我正在尝试将货币金额解析并存储为 BigDecimal 值。我得到了相关货币的区域设置,在大多数情况下它工作正常,但当货币是哥斯达黎加科朗时我得到了意想不到的结果。 我的哥斯达黎加客户告诉我,典型的货
在当前版本的 Excel(Office 365/2019 年 2 月)中获得近似每日外汇汇率的最简单的免费方法是什么。 我对历史数据不感兴趣,我只想要从货币 X 到货币 Y 的最后已知日汇率,并且只在
我在 spree 时遇到了麻烦,不知道如何处理。 我无法更改主要货币。 我该怎么做? 最佳答案 它在 Spree 2.0.0 中更容易,而且显然它也可以在以前的 spree 版本中工作。 转到您的 c
在我的网络应用程序中,我有一个名为“预算”的输入字段,用户可以在其中输入项目的建议预算。我需要创建一个屏蔽输入,以便在用户在输入字段中输入时自动将输入的金额转换为以下格式: 1000 10 000 1
我正在从数据库返回一个字符串,但由于数据库的编码方式,一些英镑符号 (£) 被问号取代。我想恢复井号,但不替换字符串中真正的问号。我已经设法编写了一个正则表达式来测试问号后跟数字的组合,但我不确定如何
我在使用亚马逊销售 API 时遇到问题。我在 amazon.co.uk 有一个帐户,可以正常发送产品。我在 amazon.de 有一个新帐户,除了货币外,一切都很好。 我有一个零售价为 10 英镑 (
Pharo 有什么方法可以将数字转换为单词。 例如:1200 = 一千二百而已。 实现起来并不难,只是想知道。 最佳答案 Integer>>asWords会这样做。 1200 asWords返回 'o
我有一个简单的单页网络应用程序。它从两个不同的 API 获取货币数据(以美元为单位),在成功检索后,promise 被解决,一些计算得出 GBP/Bitcoin 汇率。 我正试图找到一种干净的方法,然
我有以下简单的计算,它将两个值加在一起。这些值与使用“R”作为前缀标识的兰特(南非货币)有关。 function calculate() { var A = parseFloat(docume
使用 JavaScript,什么是将点替换为逗号的正确方法(对于欧盟货币),例如: 2000.65 将是 2000,65 而不是 2,000.65 39.20 将是 39,20 我不确定 cost.r
我在文本框中显示带有 NumberFormat 的货币符号 NumberFormat numberFormat = NumberFormat.getSimpleCurrencyFo
我已经设法从非接触式阅读器读取了一个交易事件,使用 现在我的 Activity 打开了,我被困在那个点上,因为我认为我的 Intent 中会有一些数据,比如 amou
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
这个问题在这里已经有了答案: Why not use Double or Float to represent currency? (16 个答案) 关闭 3 年前。 我的应用程序中的一些计算有问题
我使用 Jruby(反正就是 ruby,在 jvm 下运行 :D )和马拉松测试(一个 java swing 应用程序),我在处理货币数字时遇到了一些麻烦。 我不使用 Rails(不知道我是否可以
我正在尝试删除 、 或 之后的尾随零。 以一种货币表示,仍然保留货币符号。例如,€90.00 到 €90、90.00€ 到 90€ 和 €90.33 到 €90.33。 示例如下: $('.produ
我是一名优秀的程序员,十分优秀!