Yah and still an issue
seeing this error [02-Dec-2024 04:55:10 America/Chicago] PHP Warning: Undefined array key “HTTP_REFERER” in /home2/dataeel/public_html/wp-content/plugins/download-manager/src/User/Login.php on line 199
For prepaid credits need the following to allow admin settings for return.
function ShowPaymentForm($AutoSubmit = 0)
{
global $current_user, $wpdb;
$orderid = Session::get(‘orderid’);
if (self::checkCredits())
\WPDMPP\Libs\Order::complete_order($orderid);
else return “<div class=’alert alert-danger’>”.__(‘Not enough balance’,’wpdmpc’).”</div>”;
$wpdb->insert(
“{$wpdb->prefix}ahm_credit_history”,
array(
‘credit’ ► $this->Amount,
‘price’ ► 0,
‘time’ ► time(),
‘status’ ► “spent”,
‘uid’ ► get_current_user_id(),
‘comment’ ► get_current_user_id(),
),
array(
‘%f’,
‘%f’,
‘%d’,
‘%s’,
‘%d’,
‘%s’
)
);
$balance = get_user_meta($current_user->ID, “prepaid_credits”, true);
update_user_meta($current_user->ID, “prepaid_credits”, ($balance – $this->Amount));
$Form = “<div class=’alert alert-success’><b>Payment Completed Successfully</b><br/><i class=’fa fa-sun fa-spin’></i> Redirecting…</div><script>location.href=’/member-dashboard’;</script>”;
//$Form .= get_user_meta( $current_user->ID, “prepaid_credits”, true );
return $Form;
}
it is in the wpdm-prepaid_credit file
Ok so subscription gives a zero payment requirement and the redirect is in wpdm-premium-packages.php and the function is
`
/**
* Placing order from checkout process
*/
function place_order( $order_id ) {
//if(floatval(wpdmpp_get_cart_total()) <= 0 ) return;
global $wpdb;
$order = new Order();
$order = $order->getOrder( $order_id );
$order_total = $order->total;
$tax = $order->tax;
$items = maybe_unserialize( $order->cart_data );
//$cart_data = wpdmpp_get_cart_data();
if ( ! is_array( $items ) || count( $items ) == 0 ) {
Messages::Error( __( “Cart is Empty!”, “wpdm-premium-packages” ), 0 );
die();
}
$order_title = $order->title;
do_action( “wpdm_before_placing_order”, $order_id );
// If order total is not 0 then go to payment gateway
if ( $order_total > 0 ) {
$payment = new Payment();
$payment->initiateProcessor( wpdm_query_var( ‘payment_method’, ‘txt’ ) );
$payment->Processor->OrderTitle = $order_title;
$payment->Processor->InvoiceNo = $order_id;
$payment->Processor->Custom = $order_id;
$payment->Processor->Amount = number_format( $order_total, 2, “.”, “” );
echo $payment->Processor->showPaymentForm( 1 );
if ( ! isset( $payment->Processor->EmptyCartOnPlaceOrder ) || $payment->Processor->EmptyCartOnPlaceOrder == true ) {
wpdmpp_empty_cart();
}
die();
} else {
// if order total is 0 then empty cart and redirect to home
Order::complete_order( $order_id );
wpdmpp_empty_cart();
//wpdmpp_js_redirect( wpdmpp_orders_page( ‘id=’ . $order_id ) );
wpdmpp_js_redirect(‘/member-dashboard’ );
}
}’
I added my own redirect but be great if this was a dynamic item in settings.
Thanks I just recoded orders.php and have manual updates. Hopefully in future upgrades we have more flexibility on table titles, currency, and listing the items. Especially for prepaid credits
Only issue when setting up credits as a currency the stripe payment module uses that currency and hits an error. Way to separate the two.
Yah but still want the listed items. I just recoded orders.php for now
Thanks have updated and will check.
Also have shortcode that adds currency:
function add_custom_currency($currencies) {
// Add custom currency ‘Credits’
$currencies[‘CRD’] = ‘Credits’;
return $currencies;
}
add_filter(‘wpdmpp_currencies’, ‘add_custom_currency’);
function add_custom_currency_data($currencies) {
$currencies[‘CRD’] = array(
‘numeric_code’ ► 999, // Custom numeric code
‘code’ ► ‘CRD’,
‘name’ ► ‘Credits’,
‘symbol’ ► ‘ C’,
‘fraction_name’ ► ‘Credit’,
‘decimals’ ► 0, // Adjust according to your needs
);
return $currencies;
}
add_filter(‘wpdmpp_currencies’, ‘add_custom_currency_data’);
Not an issue just doesn’t have the option to change redirect url for completed payment. My client doesn’t want to go to the invoice when transaction is complete. He wants to go to a custom dashboard we created.
Using Pay with credits
That is for the test pay. I am using site credits addon
Keep me updated
On the emails template you use the shortcode {{items}} that shows a list of the items purchased. The issue is the list shows $ currency for the item price when we have credits as the primary currency. Need to remove the $ symbol for credit purchases.
function check_item_purchased($pid) {
if (!is_user_logged_in()) {
return false;
}
global $wpdb;
$current_user = wp_get_current_user();
$uid = $current_user->ID;
$orderid = $wpdb->get_var(
$wpdb->prepare(
"SELECT o.order_id
FROM {$wpdb->prefix}ahm_orders o
JOIN {$wpdb->prefix}ahm_order_items oi
ON o.order_id = oi.oid
WHERE o.uid = %d
AND oi.pid = %d
AND o.order_status = 'Completed'",
$uid,
$pid
)
);
return $orderid ? true : false;
}
function check_item_purchased_api() {
$pid = isset($_GET['pid']) ? intval($_GET['pid']) : 0;
$purchased = check_item_purchased($pid);
wp_send_json([
'purchased' ► $purchased
]);
}
add_action('wp_ajax_check_item_purchased', 'check_item_purchased_api');
add_action('wp_ajax_nopriv_check_item_purchased', 'check_item_purchased_api');
I created some code to do it:
document.addEventListener('DOMContentLoaded', function () {
// Select all buttons that have a class starting with 'btn-addtocart-'
const buttons = document.querySelectorAll('.btn-addtocart');
buttons.forEach(button ► {
// Extract the item ID from the button's class list
const itemId = Array.from(button.classList).find(cls ► cls.startsWith('btn-addtocart-')).replace('btn-addtocart-', '');
// Make an AJAX request to check if the item has been purchased
fetch(<code>/wp-admin/admin-ajax.php?action=check_item_purchased&pid=${itemId}</code>)
.then(response ► response.json())
.then(data ► {
if (data.purchased) {
// Disable the button and change the text if the item is already purchased
button.disabled = true;
button.textContent = 'Already Purchased! ';
button.style.backgroundColor = 'red';
button.style.borderColor = 'red'; // Optional: If you want to change the border color as well
}
});
});
});
Yah it confuses my customers as 1 credit is $5.00 but when they get the invoice it shows $1.00.
disregard figured it out. Thanks
Looking to remove currency from cart page. Our packages are priced as credits and in order to have both credits and subscription to work we need to remove the $ currency from the page to not confuse people.
Disregard figured it out