FluentCart Admin Create Order Payment
The admin order creation is very smooth. Do you have plans to include the payment methods on that screen instead of forcing the staff person to open an icognito browser session and paste the link into the browser so they can take the payment?
Your admin order entry process is almost excellent, but we take phone orders and I promised the staff that switching to Fcart was the way to go because it's so simple to use. Not being able to enter the payment on the order screen = not user friendly.
I added a trick to popup with the payment link and retain the order-user info instead of injecting the current admin user's info (default behavior). It's a reasonable workaround until they come up with something.

Doesn't look like I can share a PHP file.
<?php
/**
-
FluentCart: Pay Now on the admin order screen.
-
Opens the existing custom payment link in a popup next to Collect Payments.
-
Requires FluentCart. Include in functions or otherwise autoload.
*/
if ( ! defined( 'ABSPATH' ) ) {exit;}
add_action( 'fluent_cart/loading_app', 'fc_pay_now_enqueue' );
add_action( 'wp_ajax_fc_pay_now_link', 'fc_pay_now_ajax_link' );
function fc_pay_now_can_manage() {
return current_user_can( 'fluent_cart_admin' )
|| current_user_can( 'fluent_cart_manage_orders' )
|| current_user_can( 'manage_options' );
}
function fc_pay_now_enqueue() {
if ( ! fc_pay_now_can_manage() ) {
return;
}
wp_register_script( 'fc-pay-now', false, [], '1.0.0', true );
wp_enqueue_script( 'fc-pay-now' );
wp_add_inline_script( 'fc-pay-now', fc_pay_now_js() );
wp_localize_script( 'fc-pay-now', 'fcPayNow', [
'ajax' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'fc_pay_now' ),
] );
}
function fc_pay_now_ajax_link() {
if ( ! fc_pay_now_can_manage() || ! wp_verify_nonce( isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '', 'fc_pay_now' ) ) {
wp_send_json( [ 'ok' => false ], 403 );
}
$order_id = isset( $_POST['order_id'] ) ? (int) $_POST['order_id'] : 0;
$order = \FluentCart\App\Models\Order::query()->find( $order_id );
if ( ! $order ) {
wp_send_json( [ 'ok' => false, 'message' => 'Order not found' ], 404 );
}
$due = (int) $order->total_amount - (int) $order->total_paid;
if ( $due <= 0 || $order->status === 'canceled' ) {
wp_send_json( [ 'ok' => false, 'message' => 'Nothing due' ] );
}
wp_send_json( [
'ok' => true,
'url' => \FluentCart\App\Services\Payments\PaymentHelper::getCustomPaymentLink( $order->uuid ),
] );
}
function fc_pay_now_js() {
return <<<'JS'
(function () {
if (!window.fcPayNow) return;function orderIdFromHash() {
var m = (window.location.hash || "").match(/\/orders\/(\d+)/);
return m ? parseInt(m[1], 10) : 0;
}function request(orderId) {
var body = new URLSearchParams();
body.set("action", "fc_pay_now_link");
body.set("nonce", window.fcPayNow.nonce);
body.set("order_id", String(orderId));
return fetch(window.fcPayNow.ajax, {
method: "POST",
credentials: "include",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: body.toString()
}).then(function (r) { return r.json(); });
}function collectHost() {
var buttons = document.querySelectorAll("button, .el-button");
for (var i = 0; i < buttons.length; i++) {
var text = (buttons[i].textContent || "").replace(/\s+/g, " ");
if (text.indexOf("Collect Payments") !== -1) {
return buttons[i].closest(".el-dropdown") || buttons[i].parentElement;
}
}
return null;
}function mount(orderId) {
if (document.getElementById("fc-pay-now")) return;
var host = collectHost();
if (!host) return;
var btn = document.createElement("button");
btn.id = "fc-pay-now";
btn.type = "button";
btn.className = "el-button el-button--primary el-button--small";
btn.style.marginRight = "8px";
btn.textContent = "Pay now";
btn.addEventListener("click", function () {
btn.disabled = true;
request(orderId).then(function (data) {
btn.disabled = false;
if (!data || !data.ok) {
window.alert((data && data.message) || "Nothing due");
return;
}
window.open(data.url, "fc_pay_now", "popup=yes,width=520,height=820,noopener");
});
});
host.parentNode.insertBefore(btn, host);
}var lastHash = "";
function watch() {
if (window.location.hash !== lastHash) {
lastHash = window.location.hash;
var old = document.getElementById("fc-pay-now");
if (old) old.remove();
}
var id = orderIdFromHash();
if (id) mount(id);
}setInterval(watch, 800);
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", watch);
} else {
watch();
}
})();
JS;
}