feat(payment): finish Zibll key contract and wire checkout gateways
Drop dual-read payment runtime fallbacks, align PHP schema to Vue keys, read gateway credentials only from aksrt_settings with enable toggles, expose configured adapters at checkout, fix credits pay signatures, and apply order expiry settings. Wire orphan order/card-pass/withdrawal schema pages; delete unused Payment* wrappers.
This commit is contained in:
1 parent
12c31ad82b
commit
c93b303453
16 files changed
+298
-228
No files matched your search
@@ -122,6 +122,12 @@ class AKSRT_Shop_Checkout_Service {
|
||||
'discount' => $data['discount'],
|
||||
];
|
||||
|
||||
$expiry_minutes = 30;
|
||||
if (class_exists('AKSRT_Settings')) {
|
||||
$order_settings = AKSRT_Settings::get_order_settings();
|
||||
$expiry_minutes = max(5, min(1440, (int) ($order_settings['expiry'] ?? 30)));
|
||||
}
|
||||
|
||||
$order_number = AKSRT_Order_Repository::get_instance()->create([
|
||||
'user_id' => $user_id,
|
||||
'product_type' => 'shop_product',
|
||||
@@ -130,7 +136,7 @@ class AKSRT_Shop_Checkout_Service {
|
||||
'currency' => 'CNY',
|
||||
'status' => AKSRT_Order::STATUS_PENDING,
|
||||
'payment_method' => $payment_method,
|
||||
'expires_at' => date('Y-m-d H:i:s', strtotime('+10 minutes')),
|
||||
'expires_at' => date('Y-m-d H:i:s', strtotime('+' . $expiry_minutes . ' minutes')),
|
||||
'note' => wp_json_encode($meta_payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||||
]);
|
||||
|
||||
@@ -246,14 +252,20 @@ class AKSRT_Shop_Checkout_Service {
|
||||
return ['success' => false, 'message' => __('订单金额无效。', 'aksrt')];
|
||||
}
|
||||
|
||||
$balance = AKSRT_Credits::get_balance($user_id);
|
||||
$balance = AKSRT_Credits::balance($user_id);
|
||||
if ($balance < $amount) {
|
||||
return ['success' => false, 'message' => sprintf(__('积分不足,需要 %d 积分,当前余额 %d。', 'aksrt'), $amount, $balance)];
|
||||
}
|
||||
|
||||
$deducted = AKSRT_Credits::deduct($amount, $user_id, 'shop_points_pay', sprintf(__('积分购买订单 %s', 'aksrt'), $order_number));
|
||||
if (!$deducted) {
|
||||
return ['success' => false, 'message' => __('积分扣除失败。', 'aksrt')];
|
||||
$deducted = AKSRT_Credits::deduct(
|
||||
$user_id,
|
||||
$amount,
|
||||
'shop_points_pay',
|
||||
['order' => $order_number],
|
||||
sprintf(__('积分购买订单 %s', 'aksrt'), $order_number)
|
||||
);
|
||||
if (is_wp_error($deducted)) {
|
||||
return ['success' => false, 'message' => $deducted->get_error_message() ?: __('积分扣除失败。', 'aksrt')];
|
||||
}
|
||||
|
||||
$repo = AKSRT_Order_Repository::get_instance();
|
||||
|
||||
@@ -74,23 +74,68 @@ class AKSRT_Shop_Product_Service {
|
||||
}
|
||||
|
||||
public function get_payment_method_options(): array {
|
||||
return [
|
||||
'balance' => [
|
||||
'value' => 'balance',
|
||||
'label' => __('站内余额', 'aksrt'),
|
||||
'description' => __('即时完成支付并写回订单状态。', 'aksrt'),
|
||||
],
|
||||
'points' => [
|
||||
'value' => 'points',
|
||||
'label' => __('积分兑换', 'aksrt'),
|
||||
$methods = [];
|
||||
|
||||
if (class_exists('AKSRT_Payment_Gateway')) {
|
||||
foreach (AKSRT_Payment_Gateway::get_instance()->get_all() as $id => $gateway) {
|
||||
if (!method_exists($gateway, 'is_configured') || !$gateway->is_configured()) {
|
||||
continue;
|
||||
}
|
||||
$methods[$id] = [
|
||||
'value' => $id,
|
||||
'label' => method_exists($gateway, 'get_name') ? (string) $gateway->get_name() : $id,
|
||||
'description' => $this->gateway_method_description((string) $id),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists('AKSRT_Settings') && AKSRT_Settings::credits_enabled()) {
|
||||
$methods['points'] = [
|
||||
'value' => 'points',
|
||||
'label' => __('积分兑换', 'aksrt'),
|
||||
'description' => __('使用积分购买积分商品。', 'aksrt'),
|
||||
],
|
||||
'manual_review' => [
|
||||
'value' => 'manual_review',
|
||||
'label' => __('人工确认', 'aksrt'),
|
||||
];
|
||||
}
|
||||
|
||||
$manual = true;
|
||||
if (class_exists('AKSRT_Settings')) {
|
||||
$gw = AKSRT_Settings::get_payment_gateway_settings();
|
||||
$manual = !empty($gw['manual_review']) || ($gw['mode'] ?? '') === 'manual_review';
|
||||
}
|
||||
if ($manual) {
|
||||
$methods['manual_review'] = [
|
||||
'value' => 'manual_review',
|
||||
'label' => __('人工确认', 'aksrt'),
|
||||
'description' => __('保留待支付订单,后续由管理员确认。', 'aksrt'),
|
||||
],
|
||||
];
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($methods)) {
|
||||
$methods['manual_review'] = [
|
||||
'value' => 'manual_review',
|
||||
'label' => __('人工确认', 'aksrt'),
|
||||
'description' => __('保留待支付订单,后续由管理员确认。', 'aksrt'),
|
||||
];
|
||||
}
|
||||
|
||||
return $methods;
|
||||
}
|
||||
|
||||
private function gateway_method_description(string $id): string {
|
||||
switch ($id) {
|
||||
case 'balance':
|
||||
return __('即时完成支付并写回订单状态。', 'aksrt');
|
||||
case 'alipay':
|
||||
return __('跳转支付宝完成支付。', 'aksrt');
|
||||
case 'wechatpay':
|
||||
return __('微信扫码或跳转完成支付。', 'aksrt');
|
||||
case 'paypal':
|
||||
return __('跳转 PayPal 完成支付。', 'aksrt');
|
||||
case 'stripe':
|
||||
return __('跳转 Stripe Checkout 完成支付。', 'aksrt');
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function get_shipping_method_options(): array {
|
||||
|
||||
Reference in new issue
Block a user