我有一个捆绑了WordPress主题的脚本。我想把货币从美元改为英镑。主题控制面板中有一个设置,但在结账时不会反映出来。
PayPal技术支持已经查看并返回以下内容:
paymentrequest_0_currencycode
已成功传递给SetExpressCheckout
API请求(paymentrequest_0_currencycode
“GBP”),但它根本未传递给DoExpressCheckoutPayment
API请求,因此结果事务失败, :
errorcode 10444 shortmessage "Transaction refused because of an invalid argument. See additional error messages for details." longmessage "The transaction currency specified must be the same as previously specified."
要解决此问题,您必须检查
DoExpressCheckoutPayment
API请求,并确保通过paymentrequest_0_currencycode=GBP
。
但我不确定应该应用此修复程序的位置我尝试将其添加到DoExpressCheckoutPayment
函数中但没有成功。这是完整的脚本。任何提示都会很棒。
<?php
ini_set('log_errors', true);
ini_set('error_log', THEME_DOCUMENT_ROOT.'/ipn_errors.log');
/**
* PayPal API
*/
if ( ! class_exists('WPCAds_PayPalAPI') ) {
class WPCAds_PayPalAPI {
/**
* Start express checkout
*/
function StartExpressCheckout() {
global $redux_demo;
$paypal_api_environment = $redux_demo['paypal_api_environment'];
$paypal_success = $redux_demo['paypal_success'];
$paypal_fail = $redux_demo['paypal_fail'];
$paypal_api_username = $redux_demo['paypal_api_username'];
$paypal_api_password = $redux_demo['paypal_api_password'];
$paypal_api_signature = $redux_demo['paypal_api_signature'];
if ( $paypal_api_environment != '1' && $paypal_api_environment != '2' )
trigger_error('Environment does not defined! Please define it at the plugin configuration page!', E_USER_ERROR);
/*if ( $paypal_fail === FALSE || ! is_numeric($paypal_fail) )
trigger_error('Cancel page not defined! Please define it at the plugin configuration page!', E_USER_ERROR);
if ( $paypal_success === FALSE || ! is_numeric($paypal_success) )
trigger_error('Success page not defined! Please define it at the plugin configuration page!', E_USER_ERROR);*/
global $wpdb;
$result = $wpdb->get_results( "SELECT * FROM td_url" );
foreach ( $result as $info ) {
$url = $info->url;
}
global $redux_demo;
$currency_code = $redux_demo['currency-code'];
//$currency_code = "GBP";
$planID = $_POST['paypal-payment-package'];
$planPACKAGE = get_the_title( $planID );
$package_price = get_post_meta($planID, 'package_price', true);
// FIELDS
$fields = array(
'USER' => urlencode($paypal_api_username),
'PWD' => urlencode($paypal_api_password),
'SIGNATURE' => urlencode($paypal_api_signature),
'VERSION' => urlencode('72.0'),
'PAYMENTREQUEST_0_PAYMENTACTION' => urlencode('Sale'),
'PAYMENTREQUEST_0_AMT0' => $package_price,
'PAYMENTREQUEST_0_CUSTOM' => $_POST['PAYMENTREQUEST_0_CUSTOM'],
'PAYMENTREQUEST_0_AMT' => $package_price,
'PAYMENTREQUEST_0_ITEMAMT' => $package_price,
'ITEMAMT' => $package_price,
'PAYMENTREQUEST_0_CURRENCYCODE' => $currency_code,
'RETURNURL' => urlencode( $url.'/inc/payments/paypal/form-handler.php?func=confirm'),
'CANCELURL' => urlencode(get_permalink($paypal_fail)),
'METHOD' => urlencode('SetExpressCheckout')
);
$fields['PAYMENTREQUEST_0_CUSTOM'] = $_POST['PAYMENTREQUEST_0_CUSTOM'];
if ( isset($_POST['PAYMENTREQUEST_0_DESC']) )
$fields['PAYMENTREQUEST_0_DESC'] = $planPACKAGE;
if ( isset($_POST['RETURN_URL']) )
$_SESSION['RETURN_URL'] = $_POST['RETURN_URL'];
if ( isset($_POST['CANCEL_URL']) )
$fields['CANCELURL'] = $_POST['CANCEL_URL'];
$fields['PAYMENTREQUEST_0_QTY0'] = 1;
$fields['PAYMENTREQUEST_0_AMT'] = $package_price;
if ( isset($_POST['TAXAMT']) ) {
$fields['PAYMENTREQUEST_0_TAXAMT'] = $_POST['TAXAMT'];
$fields['PAYMENTREQUEST_0_AMT'] += $_POST['TAXAMT'];
}
if ( isset($_POST['HANDLINGAMT']) ) {
$fields['PAYMENTREQUEST_0_HANDLINGAMT'] = $_POST['HANDLINGAMT'];
$fields['PAYMENTREQUEST_0_AMT'] += $_POST['HANDLINGAMT'];
}
if ( isset($_POST['SHIPPINGAMT']) ) {
$fields['PAYMENTREQUEST_0_SHIPPINGAMT'] = $_POST['SHIPPINGAMT'];
$fields['PAYMENTREQUEST_0_AMT'] += $_POST['SHIPPINGAMT'];
}
$fields_string = '';
foreach ( $fields as $key => $value )
$fields_string .= $key.'='.$value.'&';
rtrim($fields_string,'&');
// CURL
$ch = curl_init();
if ( $paypal_api_environment == '1' )
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
elseif ( $paypal_api_environment == '2' )
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.paypal.com/nvp');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
parse_str($result, $result);
if ( $result['ACK'] == 'Success' ) {
if ( $paypal_api_environment == '1' )
header('Location: https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&useraction=commit&token='.$result['TOKEN']);
elseif ( $paypal_api_environment == '2' )
header('Location: https://www.paypal.com/webscr?cmd=_express-checkout&useraction=commit&token='.$result['TOKEN']);
exit;
} else {
print_r($result);
}
}
/**
* Validate payment
*/
function ConfirmExpressCheckout() {
global $redux_demo;
$paypal_api_environment = $redux_demo['paypal_api_environment'];
$paypal_success = $redux_demo['paypal_success'];
$paypal_fail = $redux_demo['paypal_fail'];
$paypal_api_username = $redux_demo['paypal_api_username'];
$paypal_api_password = $redux_demo['paypal_api_password'];
$paypal_api_signature = $redux_demo['paypal_api_signature'];
// FIELDS
$fields = array(
'USER' => urlencode($paypal_api_username),
'PWD' => urlencode($paypal_api_password),
'SIGNATURE' => urlencode($paypal_api_signature),
'VERSION' => urlencode('72.0'),
'TOKEN' => urlencode($_GET['token']),
'METHOD' => urlencode('GetExpressCheckoutDetails')
);
$fields_string = '';
foreach ( $fields as $key => $value )
$fields_string .= $key.'='.$value.'&';
rtrim($fields_string,'&');
// CURL
$ch = curl_init();
if ( $paypal_api_environment == '1' )
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
elseif ( $paypal_api_environment == '2' )
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.paypal.com/nvp');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
parse_str($result, $result);
if ( $result['ACK'] == 'Success' ) {
WPCAds_PayPalAPI::SavePayment($result, 'pending');
WPCAds_PayPalAPI::DoExpressCheckout($result);
} else {
WPCAds_PayPalAPI::SavePayment($result, 'failed');
}
}
/**
* Close transaction
*/
function DoExpressCheckout($result) {
global $redux_demo;
$paypal_api_environment = $redux_demo['paypal_api_environment'];
$paypal_success = $redux_demo['paypal_success'];
$paypal_fail = $redux_demo['paypal_fail'];
$paypal_api_username = $redux_demo['paypal_api_username'];
$paypal_api_password = $redux_demo['paypal_api_password'];
$paypal_api_signature = $redux_demo['paypal_api_signature'];
// FIELDS
$fields = array(
'USER' => urlencode($paypal_api_username),
'PWD' => urlencode($paypal_api_password),
'SIGNATURE' => urlencode($paypal_api_signature),
'VERSION' => urlencode('72.0'),
'PAYMENTREQUEST_0_PAYMENTACTION' => urlencode('Sale'),
'PAYERID' => urlencode($result['PAYERID']),
'TOKEN' => urlencode($result['TOKEN']),
'PAYMENTREQUEST_0_AMT' => urlencode($result['AMT']),
'METHOD' => urlencode('DoExpressCheckoutPayment')
);
$fields_string = '';
foreach ( $fields as $key => $value)
$fields_string .= $key.'='.$value.'&';
rtrim($fields_string,'&');
// CURL
$ch = curl_init();
if ( $paypal_api_environment == '1' )
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
elseif ( $paypal_api_environment == '2' )
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.paypal.com/nvp');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
parse_str($result, $result);
if ( $result['ACK'] == 'Success' ) {
WPCAds_PayPalAPI::UpdatePayment($result, 'success');
} else {
WPCAds_PayPalAPI::UpdatePayment($result, 'failed');
}
}
/**
* Save payment result into database
*/
function SavePayment($result, $status) {
global $wpdb;
$update_data = array('token' => $result['TOKEN'], 'status' => 'pending');
$where = array('custom_id' => $result['PAYMENTREQUEST_0_CUSTOM']);
$update_format = array('%s', '%s');
$wpdb->update('td_payments', $update_data, $where, $update_format);
}
/**
* Update payment
*/
function UpdatePayment($result, $status) {
global $wpdb;
$update_data = array('transaction_id' => $result['PAYMENTINFO_0_TRANSACTIONID'],
'status' => $status);
$where = array('token' => $result['TOKEN']);
$update_format = array('%s', '%s');
$wpdb->update('td_payments', $update_data, $where, $update_format);
$transactionToken = $result['TOKEN'];
global $wpdb;
$payments = $wpdb->get_results( "SELECT * FROM `td_payments` where token = '".$transactionToken."'");
$planNAME = $payments[0]->name;
$planEMAIL = $payments[0]->email;
$planPACKAGE = $payments[0]->package;
$planPRICE = $payments[0]->price;
$planCURRENCY = $payments[0]->currency;
$planTYPE = $payments[0]->payment_type;
$planPHONE = $payments[0]->phone;
//=========================================
// Send email to admin ====================
//=========================================
global $redux_demo;
$admin_email = $redux_demo['admin-email'];
$admin_email_title = $redux_demo['payment-admin-title'];
$admin_email_message = $redux_demo['payment-admin-message'];
if(empty($admin_email)) {
$admin_email = "test@mail.com";
}
if(empty($admin_email_title)) {
$admin_email_title = "New payment!";
}
if(empty($admin_email_message)) {
$admin_email_message = "Master, you have a new payment: ";
}
$blog_title = get_bloginfo('name');
$emailTo = $admin_email;
$subject = $admin_email_title;
$body = $admin_email_message. "\r\n\r\n" .$planNAME. "\r\n" .$planEMAIL. "\r\n" .$planPACKAGE. "\r\n" .$planPRICE."".$planCURRENCY. "\r\n" .$planTYPE;
$headers = 'From website' . "\r\n" . 'Reply-To: ' . $email;
wp_mail($emailTo, $subject, $body, $headers);
//=========================================
//=========================================
// Send email to subscriber ===============
//=========================================
global $redux_demo;
$admin_email = $redux_demo['admin-email'];
$user_email_title = $redux_demo['payment-user-title'];
$user_email_message = $redux_demo['payment-user-message'];
if(empty($admin_email)) {
$admin_email = "test@mail.com";
}
if(empty($user_email_title)) {
$user_email_title = "Payment notification!";
}
if(empty($user_email_message)) {
$user_email_message = "Congratulations. Your payment went through!";
}
$blog_title = get_bloginfo('name');
$from = $admin_email;
$headers = 'From: '.$from . "\r\n";
$subject = $user_email_title;
$body = $user_email_message. "\r\n\r\n" .$planNAME. "\r\n" .$planEMAIL. "\r\n" .$planPHONE. "\r\n" .$planPACKAGE. "\r\n" .$planPRICE."".$planCURRENCY. "\r\n" .$planTYPE;
wp_mail($planEMAIL, $subject, $body, $headers);
//=========================================
}
}
}
答案 0 :(得分:0)
看看$fields
和StartExpressCheckout()
中DoExpressCheckout()
数组之间的差异,您会发现后者缺少'PAYMENTREQUEST_0_CURRENCYCODE'
。您可以通过将$fields
中的DoExpressCheckout()
数组修改为以下内容来解决此问题:
global $redux_demo;
$currency_code = $redux_demo['currency-code'];
// FIELDS
$fields = array(
'USER' => urlencode($paypal_api_username),
'PWD' => urlencode($paypal_api_password),
'SIGNATURE' => urlencode($paypal_api_signature),
'VERSION' => urlencode('72.0'),
'PAYMENTREQUEST_0_PAYMENTACTION' => urlencode('Sale'),
'PAYMENTREQUEST_0_CURRENCYCODE' => $currency_code,
'PAYERID' => urlencode($result['PAYERID']),
'TOKEN' => urlencode($result['TOKEN']),
'PAYMENTREQUEST_0_AMT' => urlencode($result['AMT']),
'METHOD' => urlencode('DoExpressCheckoutPayment')
);