Secure checkout
Big Enlight Academy

Big Enlight Academy

By Big Enlight

PRICE
₦20,000.00
Your purchase confirmation and product access will be sent to this email.

Secure payment powered by Paystack
, 'rate' => 1.0, 'name' => 'US Dollar'], 'NGN' => ['sym' => "\u{20A6}", 'rate' => 1000.0, 'name' => 'Nigerian Naira'], ]; foreach ($fixed as $code => $entry) $list[$code] = $entry; if (!isset($list['GBP'])) { $list = [ 'GBP' => [ 'sym' => "\u{00A3}", 'rate' => 1.0, 'name' => 'British Pound' ] ] + $list; } return $list; } function bp_money(float $gbp, array $cur): string { return $cur['sym'] . number_format( $gbp * (float)$cur['rate'], 2 ); } /** * Public image URL. */ function bp_asset_url(string $path): string { $path = trim($path); if ($path === '') { return ''; } if (preg_match('~^https?://~i', $path)) { return $path; } return site_url() . '/' . ltrim($path, '/'); } /** * Safely obtain a user's basic information. */ function bp_user(mysqli $c, int $id): ?array { if ($id <= 0) { return null; } $st = $c->prepare(" SELECT id, first_name, email FROM users WHERE id=? LIMIT 1 "); if (!$st) { return null; } $st->bind_param('i', $id); $st->execute(); return $st->get_result()->fetch_assoc() ?: null; } /* ================================================================ PRODUCT HELPERS ================================================================ */ function bp_product(mysqli $c, int $id): ?array { $cols = bp_cols($c, 'users'); $ln = in_array('last_name', $cols, true) ? "CONCAT(u.first_name,' ',COALESCE(u.last_name,''))" : 'u.first_name'; $st = $c->prepare(" SELECT p.*, TRIM($ln) AS creator_name, u.email AS creator_email FROM creator_products p JOIN users u ON u.id=p.user_id WHERE p.id=? AND p.status='active' LIMIT 1 "); $st->bind_param('i', $id); $st->execute(); return $st->get_result()->fetch_assoc() ?: null; } function bp_product_any(mysqli $c, int $id): ?array { $cols = bp_cols($c, 'users'); $ln = in_array('last_name', $cols, true) ? "CONCAT(u.first_name,' ',COALESCE(u.last_name,''))" : 'u.first_name'; $st = $c->prepare(" SELECT p.*, TRIM($ln) AS creator_name, u.email AS creator_email FROM creator_products p JOIN users u ON u.id=p.user_id WHERE p.id=? LIMIT 1 "); $st->bind_param('i', $id); $st->execute(); return $st->get_result()->fetch_assoc() ?: null; } /** * Validate affiliate. * * Creator cannot be his own affiliate. */ function bp_affiliate( mysqli $c, int $aid, int $creator ): int { if ($aid <= 0 || $aid === $creator) { return 0; } $st = $c->prepare(" SELECT id FROM users WHERE id=? LIMIT 1 "); $st->bind_param('i', $aid); $st->execute(); return $st->get_result()->num_rows ? $aid : 0; } function bp_link(int $pid, int $uid): string { return site_url() . '/shop/?p=' . $pid . '&a=' . $uid; } /* ================================================================ CATEGORIES ================================================================ */ function bp_cats(): array { return [ 'Earning & Money' => "\u{1F4B0}", 'Business' => "\u{1F4BC}", 'Marketing' => "\u{1F4E3}", 'Education' => "\u{1F393}", 'Tech & Software' => "\u{1F4BB}", 'Design & Creative' => "\u{1F3A8}", 'Health & Fitness' => "\u{1F4AA}", 'Lifestyle' => "\u{1F33F}", 'Entertainment' => "\u{1F3AC}", 'Other' => "\u{1F4E6}" ]; } function bp_cat(string $c): string { return isset(bp_cats()[$c]) ? $c : 'Other'; } /* ================================================================ ACCENTS ================================================================ */ function bp_accents(): array { return [ 'purple' => ['#7c3aed', '#a855f7'], 'green' => ['#16a34a', '#4ade80'], 'orange' => ['#ea580c', '#fb923c'], 'blue' => ['#2563eb', '#60a5fa'], 'red' => ['#dc2626', '#f87171'], 'black' => ['#111827', '#4b5563'] ]; } /* ================================================================ INLINE ICONS ================================================================ */ function bp_i(string $n): string { static $p = [ 'cart' => ' ', 'eye' => ' ', 'user' => ' ', 'bolt' => '', 'lock' => ' ', 'card' => ' ', 'search' => ' ', 'arrow' => ' ', 'back' => ' ', 'info' => ' ', 'tag' => ' ', 'check' => '', 'grid' => ' ' ]; return ''; } /* ================================================================ BEAUTIFUL PUBLIC CSS ================================================================ */ function bp_css(): string { return <<<'CSS' :root{ --p:#7c3aed; --p2:#a855f7; --p3:#c084fc; --t:#1a1033; --m:#6b6785; --l:#e6dcfb; --s:#ffffff; --bg:#f6f2ff; --good:#16a34a; --danger:#dc2626; --shadow:0 18px 50px rgba(76,29,149,.10); } @media(prefers-color-scheme:dark){ :root{ --t:#f3eefe; --m:#aaa2c0; --l:#3a2a63; --s:#1b1230; --bg:#10091e; --shadow:0 18px 50px rgba(0,0,0,.28); } } *{ box-sizing:border-box; } html{ scroll-behavior:smooth; } body{ margin:0; background: radial-gradient(circle at 10% 0%,rgba(168,85,247,.14),transparent 30%), radial-gradient(circle at 90% 10%,rgba(124,58,237,.10),transparent 28%), var(--bg); color:var(--t); font:16px/1.55 system-ui,"Segoe UI",Arial,sans-serif; min-height:100vh; } a{ color:inherit; text-decoration:none; } button, input, select{ font:inherit; } .w{ width:min(760px,100%); margin:0 auto; padding:1rem; } .top{ position:sticky; top:0; z-index:20; background:rgba(46,16,101,.96); backdrop-filter:blur(14px); border-bottom:4px solid var(--p2); padding:.85rem 1rem; box-shadow:0 10px 30px rgba(46,16,101,.18); } .top a{ display:block; max-width:760px; margin:0 auto; } .top img{ height:34px; display:block; } .box{ position:relative; background:rgba(255,255,255,.96); border:1px solid var(--l); border-radius:24px; padding:1.2rem; margin:1rem 0; box-shadow:var(--shadow); animation:fadeUp .55s ease both; } @media(prefers-color-scheme:dark){ .box{ background:rgba(27,18,48,.96); } } .box::before{ content:""; position:absolute; inset:0; border-radius:24px; pointer-events:none; background:linear-gradient( 135deg, rgba(168,85,247,.08), transparent 40%, rgba(124,58,237,.04) ); } h1{ position:relative; font-size:1.5rem; line-height:1.25; margin:.2rem 0 .35rem; letter-spacing:-.02em; } h2{ font-size:1.15rem; margin:.2rem 0 .8rem; } .g{ display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:.8rem; } .c{ background:var(--s); border:1px solid var(--l); border-radius:20px; overflow:hidden; display:flex; flex-direction:column; box-shadow:0 10px 28px rgba(76,29,149,.08); transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease; animation:fadeUp .5s ease both; } .c:hover{ transform:translateY(-4px); box-shadow:0 18px 38px rgba(76,29,149,.14); border-color:var(--p2); } .c .pic{ aspect-ratio:4/3; background:linear-gradient(135deg,var(--p),var(--p2)); display:grid; place-items:center; color:#fff; font-size:2.4rem; font-weight:800; overflow:hidden; } .c .pic img{ width:100%; height:100%; object-fit:cover; } .c .in{ padding:.85rem; display:flex; flex-direction:column; gap:.35rem; flex:1; } .c h3{ font-size:.95rem; margin:0; line-height:1.25; } .c small, .m{ color:var(--m); font-size:.82rem; } .pr{ font-weight:800; } .btn{ position:relative; display:flex; align-items:center; justify-content:center; gap:.45rem; text-align:center; border:0; border-radius:14px; padding:.85rem 1rem; font-weight:750; font-size:.95rem; background:linear-gradient(135deg,var(--p),var(--p2)); color:#fff; cursor:pointer; width:100%; min-height:48px; overflow:hidden; transition: transform .2s ease, box-shadow .2s ease, filter .2s ease; box-shadow:0 9px 22px rgba(124,58,237,.22); } .btn::after{ content:""; position:absolute; top:0; left:-120%; width:70%; height:100%; background:linear-gradient( 90deg, transparent, rgba(255,255,255,.28), transparent ); transform:skewX(-20deg); transition:left .6s ease; } .btn:hover::after{ left:140%; } .btn:hover{ transform:translateY(-2px); filter:brightness(1.04); box-shadow:0 13px 28px rgba(124,58,237,.28); } .btn:active{ transform:translateY(0) scale(.985); } .btn.o{ background:transparent; color:var(--p); border:1.5px solid var(--p); box-shadow:none; } .btn.o:hover{ background:rgba(124,58,237,.06); } .hero{ width:100%; max-height:340px; object-fit:cover; border-radius:18px; display:block; margin:.8rem 0; } label{ display:block; font-weight:750; font-size:.88rem; margin:.9rem 0 .35rem; } input, select{ width:100%; padding:.85rem .9rem; border-radius:14px; border:1.5px solid var(--l); background:var(--s); color:var(--t); outline:none; transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease; } input:focus, select:focus{ border-color:var(--p); box-shadow:0 0 0 4px rgba(124,58,237,.10); transform:translateY(-1px); } .msg{ position:relative; padding:.9rem 1rem; border-radius:16px; margin:.8rem 0 1rem; font-weight:650; animation:fadeUp .45s ease both; } .bad{ background:#fee2e2; color:#991b1b; border:1px solid #fecaca; } .ok{ background:#dcfce7; color:#166534; border:1px solid #bbf7d0; } .row{ display:flex; justify-content:space-between; align-items:center; gap:1rem; padding:.75rem 0; border-bottom:1px solid var(--l); } .row:last-child{ border-bottom:0; } .row b{ font-size:1.1rem; } .bd{ position:absolute; left:.45rem; top:.45rem; display:flex; flex-direction:column; align-items:flex-start; gap:.25rem; } .bd span{ padding:.16rem .5rem; border-radius:999px; font-size:.7rem; font-weight:800; color:#fff; background:#ea580c; } .bd .pn{ background:var(--p); } .bd .ds{ background:#16a34a; } .c .pic{ position:relative; } .c s{ color:var(--m); font-size:.78rem; font-weight:400; } .ic{ width:1em; height:1em; flex:none; vertical-align:-.14em; } .sp{ display:block; background:linear-gradient(90deg,var(--p),var(--p2)); color:#fff; text-align:center; font-weight:750; font-size:.82rem; padding:.5rem 1rem; } .ft{ text-align:center; padding:1.2rem 0 2rem; } .ft a{ display:inline-block; padding:.6rem 1.15rem; border-radius:999px; border:1.5px solid var(--l); color:var(--m); font-size:.85rem; background:var(--s); transition:transform .2s ease; } .ft a:hover{ transform:translateY(-2px); } .ft b{ color:var(--p); } .purchase-icon{ width:72px; height:72px; margin:0 auto 1rem; border-radius:50%; display:grid; place-items:center; color:#fff; background:linear-gradient(135deg,var(--p),var(--p2)); box-shadow: 0 12px 30px rgba(124,58,237,.25), 0 0 0 9px rgba(124,58,237,.07); animation:successPop .65s cubic-bezier(.2,.8,.2,1) both; } .purchase-icon svg{ width:34px; height:34px; } .checkout-head{ text-align:center; padding:.3rem 0 1rem; } .checkout-head .mini{ display:inline-flex; align-items:center; gap:.4rem; padding:.35rem .7rem; border-radius:999px; background:rgba(124,58,237,.08); color:var(--p); font-size:.75rem; font-weight:800; margin-bottom:.7rem; } .price-display{ margin:1rem 0; padding:1rem; border-radius:18px; background: linear-gradient( 135deg, rgba(124,58,237,.10), rgba(168,85,247,.05) ); border:1px solid var(--l); } .price-display .label{ color:var(--m); font-size:.78rem; } .price-display .amount{ font-size:1.8rem; font-weight:850; letter-spacing:-.03em; color:var(--p); } .secure-note{ display:flex; align-items:center; justify-content:center; gap:.4rem; color:var(--m); font-size:.76rem; margin-top:.85rem; } .pulse{ animation:pulse 2.3s ease-in-out infinite; } @keyframes fadeUp{ from{ opacity:0; transform:translateY(12px); } to{ opacity:1; transform:translateY(0); } } @keyframes successPop{ 0%{ opacity:0; transform:scale(.55) rotate(-8deg); } 65%{ opacity:1; transform:scale(1.08) rotate(2deg); } 100%{ transform:scale(1) rotate(0); } } @keyframes pulse{ 0%,100%{ box-shadow: 0 12px 30px rgba(124,58,237,.22), 0 0 0 0 rgba(124,58,237,.10); } 50%{ box-shadow: 0 15px 34px rgba(124,58,237,.28), 0 0 0 9px rgba(124,58,237,.04); } } @media(max-width:560px){ .w{ padding:.75rem; } .box{ border-radius:20px; padding:1rem; } .g{ grid-template-columns:1fr; } h1{ font-size:1.35rem; } } CSS; } /* ================================================================ PAGE HEADER / FOOTER ================================================================ */ function bp_head( string $title, bool $strip = false, string $accent = '' ): void { $logo = is_file(dirname(__DIR__) . '/logo.png') ? '../logo.png' : ''; $a = bp_accents()[$accent] ?? null; echo ' ' . e($title) . ' ' . ( $strip ? 'Explore more with Creovix →' : '' ) . '
'; } function bp_foot(bool $strip = false): void { echo ( $strip ? '' : '' ) . '
'; } /* ================================================================ PAYSTACK ================================================================ */ function bp_pay_call( string $path, ?array $post = null ): ?array { $ch = curl_init( 'https://api.paystack.co' . $path ); curl_setopt_array( $ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 25, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . PAYSTACK_SECRET, 'Content-Type: application/json' ] ] ); if ($post !== null) { curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($post) ); } $out = curl_exec($ch); curl_close($ch); return $out ? json_decode($out, true) : null; } function bp_pay_start( array $o, string $callback ): array { $r = bp_pay_call( '/transaction/initialize', [ 'email' => $o['buyer_email'], 'amount' => (int)round( $o['paid_amount'] * 100 ), 'currency' => $o['currency'], 'reference' => $o['ref'], 'callback_url' => $callback ] ); if ( !empty($r['status']) && !empty($r['data']['authorization_url']) ) { return [ $r['data']['authorization_url'], '' ]; } return [ null, $r['message'] ?? 'The payment service could not be reached. Please try again.' ]; } function bp_pay_verify(array $o): bool { $r = bp_pay_call( '/transaction/verify/' . rawurlencode($o['ref']) ); $d = $r['data'] ?? []; return !empty($r['status']) && ($d['status'] ?? '') === 'success' && (int)($d['amount'] ?? 0) >= (int)round($o['paid_amount'] * 100) && strtoupper($d['currency'] ?? '') === strtoupper($o['currency']); } /* ================================================================ EMAILS ================================================================ Verification-style: short, plain, one table, one plain link. No buttons, no images, no promo tone, no exclamation marks. Subjects are fixed calm sentences (never the product title). No recipient ever sees another recipient's email address. ================================================================ */ /** * BUYER EMAIL * * The buyer sees only their own order details and their own links. */ function bp_email_buyer( mysqli $c, array $o, array $p, array $cur ): void { $title = (string)$p['title']; $price = bp_money( (float)$o['price_gbp'], $cur ); $body = mail_h1('Hi ' . e($o['buyer_name']) . ',') . mail_p( 'Thank you for your order. Your details are below.' ) . mail_rows([ ['Product', $title], ['Amount', $price], ['Reference', $o['ref']], ['Creator', $p['creator_name']] ]); $text = "Hi {$o['buyer_name']},\n\n" . "Thank you for your order. Your details are below.\n\n" . "Product: $title\n" . "Amount: $price\n" . "Reference: {$o['ref']}\n" . "Creator: {$p['creator_name']}\n"; if (!empty($p['product_link'])) { $body .= mail_p( 'Open your product:
' . '' . e($p['product_link']) . '' ); $text .= "\nOpen your product:\n" . $p['product_link'] . "\n"; } if (!empty($p['material_link'])) { $body .= mail_p( 'Additional material:
' . '' . e($p['material_link']) . '' ); $text .= "\nAdditional material:\n" . $p['material_link'] . "\n"; } $text .= "\nCreovix"; $subject = 'Your Creovix order confirmation'; send_mail( $o['buyer_email'], $subject, mail_layout( 'Your order details are inside.', $subject, $body ), $text ); } /** * CREATOR EMAIL * * Privacy rule: * - Buyer name and buyer email are NOT included at all. * - If affiliate sale, the affiliate NAME is shown. * - No extra explanation text is added. */ function bp_email_creator( mysqli $c, array $o, array $p, array $cur ): void { $creator = bp_user( $c, (int)$o['creator_id'] ); if (!$creator || empty($creator['email'])) { error_log( 'bp_email_creator: creator ' . (int)$o['creator_id'] . ' has no email on record (order ' . $o['ref'] . ')' ); return; } $title = (string)$p['title']; $saleAmount = bp_money( (float)$o['price_gbp'], $cur ); $earning = bp_money( (float)$o['creator_gbp'], $cur ); $rows = [ ['Product', $title], ['Amount', $saleAmount], ['Your earnings', $earning] ]; $affiliateName = ''; if ((int)$o['affiliate_id'] > 0) { $affiliate = bp_user( $c, (int)$o['affiliate_id'] ); $affiliateName = trim( (string)( $affiliate['first_name'] ?? 'Affiliate' ) ); $rows[] = [ 'Affiliate', $affiliateName ]; $intro = 'A customer just ordered your product through an affiliate link.'; } else { $intro = 'A customer just ordered your product.'; } $body = mail_h1('Hi ' . e($creator['first_name']) . ',') . mail_p(e($intro)) . mail_rows($rows) . mail_p( 'Open your dashboard:
' . '' . e(site_url() . '/user/index.php') . '' ); $text = "Hi {$creator['first_name']},\n\n" . $intro . "\n\n" . "Product: $title\n" . "Amount: $saleAmount\n" . "Your earnings: $earning\n"; if ($affiliateName !== '') { $text .= "Affiliate: " . $affiliateName . "\n"; } $text .= "\nOpen your dashboard:\n" . site_url() . '/user/index.php' . "\n\nCreovix"; $subject = 'New order on your Creovix product'; send_mail( $creator['email'], $subject, mail_layout( 'Your order details are inside.', $subject, $body ), $text ); } /** * AFFILIATE EMAIL * * Sent EVERY time a real affiliate is attached to the order, * even when the commission is 0, so the affiliate is never * missed: they always get feedback and the dashboard row. * * Shows the buyer NAME only. Buyer email is never included. */ function bp_email_affiliate( mysqli $c, array $o, array $p, array $cur ): void { if ((int)$o['affiliate_id'] <= 0) { return; } $affiliate = bp_user( $c, (int)$o['affiliate_id'] ); if (!$affiliate || empty($affiliate['email'])) { error_log( 'bp_email_affiliate: affiliate ' . (int)$o['affiliate_id'] . ' has no email on record (order ' . $o['ref'] . ')' ); return; } $title = (string)$p['title']; $price = bp_money( (float)$o['price_gbp'], $cur ); $hasComm = (float)$o['comm_gbp'] > 0; $commission = bp_money( (float)$o['comm_gbp'], $cur ); $note = $hasComm ? 'The amount has been added to your Creovix balance.' : 'This order has been added to your Creovix dashboard.'; $body = mail_h1('Hi ' . e($affiliate['first_name']) . ',') . mail_p( 'A customer just ordered a product through your link. The details are below.' ) . mail_rows([ ['Product', $title], ['Buyer', $o['buyer_name']], ['Amount', $price], ['Your commission', $commission] ]) . mail_p(e($note)) . mail_p( 'Open your dashboard:
' . '' . e(site_url() . '/user/index.php') . '' ); $text = "Hi {$affiliate['first_name']},\n\n" . "A customer just ordered a product through your link. The details are below.\n\n" . "Product: $title\n" . "Buyer: {$o['buyer_name']}\n" . "Amount: $price\n" . "Your commission: $commission\n\n" . $note . "\n\nOpen your dashboard:\n" . site_url() . '/user/index.php' . "\n\nCreovix"; $subject = 'New order through your Creovix link'; send_mail( $affiliate['email'], $subject, mail_layout( 'Your order details are inside.', $subject, $body ), $text ); } /** * Run one email sender on its own. * * A failure in one email can never stop the other two. * send_mail() returning false is logged too. */ function bp_send_safe( string $label, string $ref, callable $fn ): void { try { $res = $fn(); if ($res === false) { error_log( "bp_emails: $label email returned false (order $ref)" ); } } catch (Throwable $t) { error_log( "bp_emails: $label email failed (order $ref): " . $t->getMessage() ); } } /** * Send all three independent transactional emails. * * ORDER MATTERS FOR THE AFFILIATE: the affiliate email is sent * FIRST, wrapped on its own, so nothing can ever block it. */ function bp_emails( mysqli $c, array $o ): void { $curList = bp_currencies($c); $cur = $curList[$o['currency']] ?? [ 'sym' => $o['currency'] . ' ', 'rate' => (float)$o['rate'], 'name' => $o['currency'] ]; /* * The order stores the exact exchange rate used at checkout, * so the email uses that exact rate. */ $cur['rate'] = (float)$o['rate']; $p = bp_product_any( $c, (int)$o['product_id'] ); if (!$p) { error_log( 'bp_emails: product not found for order ' . $o['ref'] ); return; } $ref = (string)$o['ref']; /* * 1. AFFILIATE FIRST — never missed, even at 0 commission. */ if ((int)$o['affiliate_id'] > 0) { bp_send_safe( 'affiliate', $ref, function () use ($c, $o, $p, $cur) { return bp_email_affiliate($c, $o, $p, $cur); } ); usleep(400000); } /* * 2. BUYER */ bp_send_safe( 'buyer', $ref, function () use ($c, $o, $p, $cur) { return bp_email_buyer($c, $o, $p, $cur); } ); usleep(400000); /* * 3. CREATOR */ bp_send_safe( 'creator', $ref, function () use ($c, $o, $p, $cur) { return bp_email_creator($c, $o, $p, $cur); } ); } /* ================================================================ FULFILMENT ================================================================ */ function bp_fulfil( mysqli $c, string $ref ): ?array { $c->begin_transaction(); try { /* * FOR UPDATE prevents the Paystack return page and webhook * from fulfilling the same order at the same time. */ $st = $c->prepare(" SELECT * FROM product_orders WHERE ref=? LIMIT 1 FOR UPDATE "); $st->bind_param('s', $ref); $st->execute(); $o = $st->get_result()->fetch_assoc(); if (!$o) { $c->rollback(); return null; } /* * Already fulfilled. * Do NOT send another set of emails. */ if ($o['status'] === 'paid') { $c->rollback(); return $o; } $pid = (int)$o['product_id']; $cr = (int)$o['creator_id']; $af = (int)$o['affiliate_id']; /* * Product title. */ $st = $c->prepare(" SELECT title FROM creator_products WHERE id=? LIMIT 1 "); $st->bind_param('i', $pid); $st->execute(); $title = (string)( $st->get_result() ->fetch_assoc()['title'] ?? 'Product' ); /* * Existing affiliate_sales table may have different columns * depending on the version of the platform. */ $has = bp_cols( $c, 'affiliate_sales' ); /* * Low-level insert into affiliate_sales. * $f = [column => [type, value]] * * NOTE: buyer_name is stored, never buyer_email, so no * dashboard row can ever expose a customer's address. */ $run = function (array $f) use ($c): void { $names = array_keys($f); $types = ''; $vals = []; foreach ($f as $v) { $types .= $v[0]; $vals[] = $v[1]; } $sql = 'INSERT INTO affiliate_sales (' . implode(',', $names) . ',created_at) VALUES (' . implode( ',', array_fill( 0, count($names), '?' ) ) . ',NOW())'; $s = $c->prepare($sql); if (!$s) { throw new RuntimeException( 'Could not prepare affiliate sale insert.' ); } $s->bind_param( $types, ...$vals ); $s->execute(); }; $ins = function ( int $uid, float $amt, string $role ) use ( $run, $title, $pid, $o, $has ) { if ($uid <= 0) { return; } $f = [ 'user_id' => ['i', $uid], 'product_name' => ['s', $title], 'commission' => ['d', $amt], 'status' => ['s', 'approved'], 'product_id' => ['i', $pid], 'buyer_name' => ['s', $o['buyer_name']], 'order_ref' => ['s', $o['ref']], 'role' => ['s', $role] ]; if (in_array('amount', $has, true)) { $f['amount'] = [ 'd', (float)$o['price_gbp'] ]; } try { $run($f); } catch (Throwable $first) { /* * Fallback: write only the columns every version of * the platform has. This stops one unexpected column * from rolling back the whole sale (which would also * block every email and the affiliate reward). */ error_log( 'bp_fulfil: full affiliate_sales insert failed (' . $first->getMessage() . '), retrying minimal insert' ); $min = [ 'user_id' => ['i', $uid], 'product_name' => ['s', $title], 'commission' => ['d', $amt], 'status' => ['s', 'approved'] ]; if (in_array('amount', $has, true)) { $min['amount'] = [ 'd', (float)$o['price_gbp'] ]; } $run($min); } }; /* * Creator earning. */ if ( (float)$o['creator_gbp'] > 0 ) { $s = $c->prepare(" UPDATE users SET balance=balance+? WHERE id=? "); $v = (float)$o['creator_gbp']; $s->bind_param( 'di', $v, $cr ); $s->execute(); } $ins( $cr, (float)$o['creator_gbp'], 'creator' ); /* * Affiliate reward. * * The commission is added to the balance only when it is * above zero, but the sale row is ALWAYS written when an * affiliate is on the order, so the affiliate dashboard * (sales count, totals, recent activity) always updates. */ if ($af > 0) { $v = (float)$o['comm_gbp']; if ($v > 0) { $s = $c->prepare(" UPDATE users SET balance=balance+? WHERE id=? "); $s->bind_param( 'di', $v, $af ); $s->execute(); } $ins( $af, $v, 'affiliate' ); } /* * Mark paid only after all financial operations succeeded. */ $s = $c->prepare(" UPDATE product_orders SET status='paid', paid_at=NOW() WHERE id=? "); $oid = (int)$o['id']; $s->bind_param( 'i', $oid ); $s->execute(); $c->commit(); } catch (Throwable $t) { $c->rollback(); error_log( 'bp_fulfil: ' . $t->getMessage() ); return null; } $o['status'] = 'paid'; /* * Emails happen AFTER the transaction commits. * * If SMTP temporarily fails, the sale itself remains paid. * The mail error is logged by includes/mail.php. */ try { bp_emails( $c, $o ); } catch (Throwable $t) { error_log( 'bp_emails: ' . $t->getMessage() ); } return $o; } /* ================================================================ PRODUCT LIST ================================================================ */ if (!defined('BUY_HOT_SALES')) { define('BUY_HOT_SALES', 3); } if (!defined('BUY_HOT_VIEWS')) { define('BUY_HOT_VIEWS', 100); } function bp_list( mysqli $c, int $limit = 80 ): array { $cols = bp_cols( $c, 'users' ); $ln = in_array('last_name', $cols, true) ? "CONCAT(u.first_name,' ',COALESCE(u.last_name,''))" : 'u.first_name'; $rs = $c->query(" SELECT p.*, TRIM($ln) creator_name, ( SELECT COUNT(*) FROM product_orders o WHERE o.product_id=p.id AND o.status='paid' ) sales_n FROM creator_products p JOIN users u ON u.id=p.user_id WHERE p.status='active' "); $pin = []; $hot = []; $rest = []; while ($rs && ($r = $rs->fetch_assoc())) { $r['price_now'] = bp_price($r); $r['disc'] = ( (float)$r['price'] > 0 && $r['price_now'] < (float)$r['price'] ) ? (int)round( ( 1 - $r['price_now'] / (float)$r['price'] ) * 100 ) : 0; $r['pinned'] = (int)($r['pinned'] ?? 0); $r['sales_n'] = (int)$r['sales_n']; $r['views'] = (int)($r['views'] ?? 0); $r['hot'] = ( $r['sales_n'] >= BUY_HOT_SALES || $r['views'] >= BUY_HOT_VIEWS ); $r['trend'] = !$r['hot'] && ( $r['sales_n'] >= 1 || $r['views'] >= 30 ); $r['category'] = bp_cat( (string)($r['category'] ?? '') ); if ($r['pinned'] > 0) { $pin[] = $r; } elseif ($r['hot']) { $hot[] = $r; } else { $rest[] = $r; } } usort( $pin, fn($a, $b) => $b['pinned'] <=> $a['pinned'] ?: $a['id'] <=> $b['id'] ); shuffle($hot); shuffle($rest); return array_slice( array_merge( $pin, $hot, $rest ), 0, $limit ); } /* ================================================================ LIBRARY MODE ================================================================ */ if (defined('BUY_LIB')) { return; } /* ================================================================ PAGE START ================================================================ */ bp_schema($conn); /* ================================================================ PAYSTACK WEBHOOK ================================================================ */ if (isset($_GET['hook'])) { $raw = file_get_contents( 'php://input' ); $signature = $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] ?? ''; if ( !hash_equals( hash_hmac( 'sha512', $raw, PAYSTACK_SECRET ), $signature ) ) { http_response_code(401); exit; } $ev = json_decode( $raw, true ); if ( ($ev['event'] ?? '') === 'charge.success' && !empty( $ev['data']['reference'] ) ) { bp_fulfil( $conn, (string)$ev['data']['reference'] ); } http_response_code(200); exit; } /* ================================================================ PAYMENT RETURN PAGE ================================================================ */ if (isset($_GET['ref'])) { $ref = trim( (string)$_GET['ref'] ); $st = $conn->prepare(" SELECT * FROM product_orders WHERE ref=? LIMIT 1 "); $st->bind_param( 's', $ref ); $st->execute(); $o = $st->get_result() ->fetch_assoc(); /* * Verify directly with Paystack when necessary. */ if ( $o && $o['status'] !== 'paid' && bp_pay_verify($o) ) { $o = bp_fulfil( $conn, $ref ) ?: $o; } bp_head( 'Your purchase' ); if ( !$o || $o['status'] !== 'paid' ) { echo '
' . bp_i('card') . '

Payment not confirmed yet

Your payment is still being confirmed. If your account was charged, please wait a moment and check again.

Check payment again
'; } else { $p = bp_product_any( $conn, (int)$o['product_id'] ); if (!$p) { echo '
The product could not be loaded. Your payment was recorded.
'; bp_foot(); exit; } echo '
' . bp_i('check') . '
Payment received successfully.
' . bp_i('check') . ' Purchase confirmed

' . e($p['title']) . '

Your purchase is ready.

ORDER REFERENCE
' . e($o['ref']) . '

A private confirmation email has been sent to ' . e($o['buyer_email']) . '.

Open my product ' . bp_i('arrow') . ' '; if (!empty($p['material_link'])) { echo '

Open product material ' . bp_i('arrow') . ' '; } echo '
Explore more products '; } bp_foot(); exit; } /* ================================================================ CHECKOUT ================================================================ */ $pid = (int)( $_GET['p'] ?? $_POST['p'] ?? 0 ); $p = $pid ? bp_product( $conn, $pid ) : null; if (!$p) { bp_head( 'Not available' ); echo '
' . bp_i('info') . '

Product not available

This product may have been removed, unpublished or is no longer available.

See all products
'; bp_foot(); exit; } /* * Affiliate can come from: * ?a=5 * POST a * cvx_ref cookie * * The FIRST VALID one wins. (Before, a hidden POST field of "0" * could hide a valid cookie, so the affiliate was lost.) */ $aff = 0; foreach ( [ $_GET['a'] ?? 0, $_POST['a'] ?? 0, $_COOKIE['cvx_ref'] ?? 0 ] as $candidate ) { $candidate = bp_affiliate( $conn, (int)$candidate, (int)$p['user_id'] ); if ($candidate) { $aff = $candidate; break; } } /* * Keep the affiliate for 30 days (same cookie as shop/index.php) * so the referral survives until payment. */ if ( $aff && (int)($_COOKIE['cvx_ref'] ?? 0) !== $aff && !headers_sent() ) { setcookie( 'cvx_ref', (string)$aff, [ 'expires' => time() + 30 * 86400, 'path' => '/', 'secure' => !empty($_SERVER['HTTPS']), 'httponly' => true, 'samesite' => 'Lax' ] ); } $cur = bp_currencies( $conn ); $gbp = bp_price($p); $err = ''; /* ================================================================ CHECKOUT POST ================================================================ */ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = trim( (string)( $_POST['name'] ?? '' ) ); $mail = trim( (string)( $_POST['email'] ?? '' ) ); $code = strtoupper( (string)( $_POST['currency'] ?? 'GBP' ) ); if ( !hash_equals( $_SESSION['bp_t'] ?? 'x', (string)( $_POST['t'] ?? '' ) ) ) { $err = 'Please refresh the page and try again.'; } elseif ( mb_strlen($name) < 2 || mb_strlen($name) > 100 ) { $err = 'Please enter your name.'; } elseif ( !filter_var( $mail, FILTER_VALIDATE_EMAIL ) ) { $err = 'Please enter a valid email address.'; } elseif ( !isset($cur[$code]) ) { $err = 'Please choose a currency.'; } else { /* * Affiliate commission is calculated only when * a valid affiliate is attached to the order. */ $comm = $aff ? round( $gbp * (float)( $p['commission_pct'] ?? 0 ) / 100, 4 ) : 0.0; $net = round( $gbp - $comm, 4 ); $rate = (float)$cur[$code]['rate']; $paid = round( $gbp * $rate, 2 ); $ref = 'CVX' . strtoupper( bin2hex( random_bytes(7) ) ); $mine = (int)$p['user_id']; /* * NULL when there is no affiliate. */ $aid = $aff ?: null; $st = $conn->prepare(" INSERT INTO product_orders ( ref, product_id, creator_id, affiliate_id, buyer_name, buyer_email, price_gbp, comm_gbp, creator_gbp, currency, rate, paid_amount, status, created_at ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', NOW() ) "); if (!$st) { $err = 'We could not create your order. Please try again.'; } else { $st->bind_param( 'siiissdddsdd', $ref, $pid, $mine, $aid, $name, $mail, $gbp, $comm, $net, $code, $rate, $paid ); if (!$st->execute()) { $err = 'We could not create your order. Please try again.'; } else { unset( $_SESSION['bp_t'] ); /* * FREE PRODUCT * * No Paystack payment. * Fulfil immediately. */ if ($gbp <= 0) { bp_fulfil( $conn, $ref ); header( 'Location: buy.php?ref=' . urlencode($ref) ); exit; } /* * PAID PRODUCT */ $o = [ 'ref' => $ref, 'buyer_email' => $mail, 'paid_amount' => $paid, 'currency' => $code ]; $cb = site_url() . '/shop/buy.php?ref=' . urlencode($ref); [ $url, $e2 ] = bp_pay_start( $o, $cb ); if ($url) { header( 'Location: ' . $url ); exit; } /* * Payment initialization failed. * * Delete the unused pending order so the buyer * can safely retry without accumulating bad orders. */ try { $del = $conn->prepare(" DELETE FROM product_orders WHERE ref=? AND status='pending' LIMIT 1 "); $del->bind_param( 's', $ref ); $del->execute(); } catch (Throwable $ignore) { } $err = $e2 ?: 'The payment service could not be started. Please try again.'; } } } } /* * New anti-double-submit token. */ $_SESSION['bp_t'] = $_SESSION['bp_t'] ?? bin2hex( random_bytes(16) ); bp_head( 'Checkout' ); $img = bp_asset_url( (string)( $p['image'] ?? '' ) ); $dflt = isset($cur['NGN']) ? 'NGN' : 'GBP'; ?>
Secure checkout
Big Enlight Academy

Big Enlight Academy

By Big Enlight

PRICE
₦20,000.00
Your purchase confirmation and product access will be sent to this email.

Secure payment powered by Paystack