feat(forum): guest cash purchase for topic and plate follow
- Reuse pay_no_logged_in / pay_cookie_day; generalized guest cookie helpers - Topic + plate cash: guest preview/purchase (no balance), order.user_id=0, cookie unlock - View gates: can_view_topic pay + plate follow accept signed guest cookies - Templates: guest buy/follow CTAs; poll endpoint allows plate_follow guest orders
This commit is contained in:
1 parent
a9150862ef
commit
6b6314b033
9 files changed
+274
-70
No files matched your search
+75
-14
@@ -361,12 +361,31 @@ if (!function_exists('aksrt_content_order_cookie_token_key')) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set guest paid cookies after content order paid (Zibll zibpay_posts_order_created_set_cookie).
|
||||
* Whether guest cash purchase is allowed for forum topic / plate follow.
|
||||
* Reuses global pay_no_logged_in (same switch as content).
|
||||
*
|
||||
* @param WP_Post|int|null $post Topic or plate post (optional filter context).
|
||||
*/
|
||||
if (!function_exists('aksrt_allow_guest_forum_pay')) {
|
||||
function aksrt_allow_guest_forum_pay($post = null): bool {
|
||||
$order = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_order_settings() : [];
|
||||
$paid = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_paid_content_settings() : [];
|
||||
$allow = !empty($order['no_logged_in']) || !empty($paid['no_logged_in']);
|
||||
/**
|
||||
* @param bool $allow
|
||||
* @param WP_Post|int|null $post
|
||||
*/
|
||||
return (bool) apply_filters('aksrt_allow_guest_forum_pay', $allow, $post);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set guest paid cookies after cash order paid (content / topic / plate_follow).
|
||||
*
|
||||
* @param array<string,mixed> $order
|
||||
*/
|
||||
if (!function_exists('aksrt_set_guest_content_pay_cookies')) {
|
||||
function aksrt_set_guest_content_pay_cookies(array $order): void {
|
||||
if (!function_exists('aksrt_set_guest_pay_cookies')) {
|
||||
function aksrt_set_guest_pay_cookies(array $order): void {
|
||||
$post_id = (int) ($order['product_id'] ?? 0);
|
||||
$order_number = (string) ($order['order_number'] ?? '');
|
||||
if ($post_id <= 0 || $order_number === '') {
|
||||
@@ -390,19 +409,30 @@ if (!function_exists('aksrt_set_guest_content_pay_cookies')) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve guest paid order from browser cookie for a post.
|
||||
* Set guest paid cookies after content order paid (Zibll zibpay_posts_order_created_set_cookie).
|
||||
*
|
||||
* @param array<string,mixed> $order
|
||||
*/
|
||||
if (!function_exists('aksrt_set_guest_content_pay_cookies')) {
|
||||
function aksrt_set_guest_content_pay_cookies(array $order): void {
|
||||
aksrt_set_guest_pay_cookies($order);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve guest paid order from browser cookie for a product.
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
if (!function_exists('aksrt_get_guest_content_paid_order')) {
|
||||
function aksrt_get_guest_content_paid_order(int $post_id): ?array {
|
||||
if ($post_id <= 0 || empty($_COOKIE['aksrt_pay_' . $post_id])) {
|
||||
if (!function_exists('aksrt_get_guest_paid_order')) {
|
||||
function aksrt_get_guest_paid_order(int $product_id, string $product_type = ''): ?array {
|
||||
if ($product_id <= 0 || empty($_COOKIE['aksrt_pay_' . $product_id])) {
|
||||
return null;
|
||||
}
|
||||
if (!class_exists('AKSRT_Order_Repository')) {
|
||||
if (!class_exists('AKSRT_Order_Repository') || !class_exists('AKSRT_Domain_Model')) {
|
||||
return null;
|
||||
}
|
||||
$order_number = sanitize_text_field((string) $_COOKIE['aksrt_pay_' . $post_id]);
|
||||
$order_number = sanitize_text_field((string) $_COOKIE['aksrt_pay_' . $product_id]);
|
||||
if ($order_number === '') {
|
||||
return null;
|
||||
}
|
||||
@@ -410,10 +440,16 @@ if (!function_exists('aksrt_get_guest_content_paid_order')) {
|
||||
if (!$order) {
|
||||
return null;
|
||||
}
|
||||
if ((string) ($order['product_type'] ?? '') !== AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE) {
|
||||
$ptype = sanitize_key((string) ($order['product_type'] ?? ''));
|
||||
$want = sanitize_key($product_type);
|
||||
if ($want !== '' && $ptype !== $want) {
|
||||
return null;
|
||||
}
|
||||
if ((int) ($order['product_id'] ?? 0) !== $post_id) {
|
||||
if ((int) ($order['product_id'] ?? 0) !== $product_id) {
|
||||
return null;
|
||||
}
|
||||
// Guest orders only (logged-in users use user_id access).
|
||||
if ((int) ($order['user_id'] ?? -1) !== 0) {
|
||||
return null;
|
||||
}
|
||||
$status = (string) ($order['status'] ?? '');
|
||||
@@ -421,11 +457,10 @@ if (!function_exists('aksrt_get_guest_content_paid_order')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cookie day window from paid_at.
|
||||
$paid_at = (string) ($order['paid_at'] ?? $order['created_at'] ?? '');
|
||||
if ($paid_at !== '') {
|
||||
$ts = strtotime($paid_at);
|
||||
$days = aksrt_guest_pay_cookie_days($post_id);
|
||||
$days = aksrt_guest_pay_cookie_days($product_id);
|
||||
if ($ts !== false && ($ts + DAY_IN_SECONDS * $days) < time()) {
|
||||
return null;
|
||||
}
|
||||
@@ -443,7 +478,21 @@ if (!function_exists('aksrt_get_guest_content_paid_order')) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether current request has paid access via guest cookie.
|
||||
* Resolve guest paid order from browser cookie for a post (content/resource).
|
||||
*
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
if (!function_exists('aksrt_get_guest_content_paid_order')) {
|
||||
function aksrt_get_guest_content_paid_order(int $post_id): ?array {
|
||||
$type = class_exists('AKSRT_Domain_Model')
|
||||
? AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE
|
||||
: 'resource';
|
||||
return aksrt_get_guest_paid_order($post_id, $type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether current request has paid access via guest cookie (content/resource product).
|
||||
*/
|
||||
if (!function_exists('aksrt_guest_has_paid_access')) {
|
||||
function aksrt_guest_has_paid_access(int $post_id): bool {
|
||||
@@ -451,6 +500,18 @@ if (!function_exists('aksrt_guest_has_paid_access')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Guest paid plate follow access (cookie).
|
||||
*/
|
||||
if (!function_exists('aksrt_guest_has_plate_follow_access')) {
|
||||
function aksrt_guest_has_plate_follow_access(int $plate_id): bool {
|
||||
$type = class_exists('AKSRT_Domain_Model')
|
||||
? AKSRT_Domain_Model::ORDER_PRODUCT_PLATE_FOLLOW
|
||||
: 'plate_follow';
|
||||
return null !== aksrt_get_guest_paid_order($plate_id, $type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the amount a given user should pay for a post (Zibll VIP tier min).
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user