fix(pay): preserve order note JSON, shared coupon burn, plate free VIP cashier
- Order_Repository: status note merges into JSON as status_note instead of wiping coupon/topic_pay meta - Extract aksrt_burn_order_coupon / aksrt_coupon_usage_exists for content + topic - Money plate follow (incl. VIP free) always opens multi-gateway cashier for 0-order ledger
This commit is contained in:
@@ -246,21 +246,9 @@ class AKSRT_Content_Pay {
|
||||
|
||||
$buyer_id = (int) ($order['user_id'] ?? 0);
|
||||
|
||||
// Coupon burn.
|
||||
$coupon = is_array($meta['coupon'] ?? null) ? $meta['coupon'] : [];
|
||||
$coupon_code = sanitize_text_field((string) ($coupon['code'] ?? $meta['coupon_code'] ?? ''));
|
||||
$coupon_discount = (float) ($meta['coupon_discount'] ?? $meta['discount'] ?? ($coupon['discount'] ?? 0));
|
||||
if ($coupon_code !== '' && class_exists('AKSRT_Coupon') && !$this->coupon_usage_exists($order_number)) {
|
||||
$coupon_api = AKSRT_Coupon::get_instance();
|
||||
$coupon_api->use_coupon($coupon_code);
|
||||
$validated = $coupon_api->validate($coupon_code, max(0.01, $coupon_discount), ['user_id' => $buyer_id]);
|
||||
$coupon_id = (int) ($validated['coupon']['id'] ?? $coupon['id'] ?? 0);
|
||||
if ($coupon_id <= 0 && !empty($coupon['id'])) {
|
||||
$coupon_id = (int) $coupon['id'];
|
||||
}
|
||||
if ($coupon_id > 0) {
|
||||
$coupon_api->log_usage($coupon_id, max(0, $buyer_id), $order_number, max(0.0, $coupon_discount));
|
||||
}
|
||||
// Coupon burn (shared helper; idempotent via coupon_usage.order_number).
|
||||
if (function_exists('aksrt_burn_order_coupon')) {
|
||||
aksrt_burn_order_coupon($order_number, $meta, $buyer_id);
|
||||
}
|
||||
|
||||
// Affiliate commission (does not reduce buyer pay).
|
||||
@@ -307,19 +295,6 @@ class AKSRT_Content_Pay {
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
|
||||
private function coupon_usage_exists(string $order_number): bool {
|
||||
global $wpdb;
|
||||
$table = AKSRT_DB_Migrator::table('coupon_usage');
|
||||
if ($table === '' || $order_number === '') {
|
||||
return false;
|
||||
}
|
||||
$found = $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT id FROM {$table} WHERE order_number = %s LIMIT 1",
|
||||
$order_number
|
||||
));
|
||||
return !empty($found);
|
||||
}
|
||||
|
||||
private function rebate_log_exists(string $order_number, int $referrer_id): bool {
|
||||
global $wpdb;
|
||||
$table = AKSRT_DB_Migrator::table('rebate_log');
|
||||
|
||||
Reference in New Issue
Block a user