Functions Integration

‘POST’,’callback’=>’bbb_billplz_callback’,’permission_callback’=>’__return_true’)); }); function bbb_billplz_callback(WP_REST_Request $req){ $data = $req->get_body_params(); // Billplz posts form data; verify fields as needed $paid = (isset($data[‘paid’]) && $data[‘paid’]==’true’) || (isset($data[‘state’]) && $data[‘state’]==’paid’); if($paid){ $txn_id = $data[‘id’] ?? uniqid(‘billplz_’); $email = $data[’email’] ?? ”; $name = $data[‘name’] ?? ”; $amount = $data[‘amount’] ?? 0; bbb_record_payment(‘billplz’,$amount,$txn_id,$email,$name,$data); if($email) bbb_create_vip_user($email, $name ?: $email); return rest_ensure_response([‘status’=>’ok’]); } return rest_ensure_response([‘status’=>’failed’]); }// QR upload endpoint add_action(‘rest_api_init’, function(){ register_rest_route(‘bbb/v1′,’/qr-upload’, array(‘methods’=>’POST’,’callback’=>’bbb_qr_upload’,’permission_callback’=>’__return_true’)); }); function bbb_qr_upload($req){ if(empty($_FILES[‘proof’])) return rest_ensure_response([‘error’=>’No file uploaded’]); $file = $_FILES[‘proof’]; require_once(ABSPATH.’wp-admin/includes/file.php’); $overrides = array(‘test_form’=>false); $move = wp_handle_upload($file, $overrides); if(isset($move[‘url’])){ $payer_name = sanitize_text_field($_POST[‘payer_name’] ?? ”); $post_id = wp_insert_post(array( ‘post_title’=>’QR Payment – ‘.wp_strip_all_tags($payer_name), ‘post_content’=>’Proof uploaded: ‘.$move[‘url’], ‘post_status’=>’publish’, ‘post_type’=>’bbb_payment_proof’ )); // notify admin wp_mail(get_option(‘admin_email’), ‘New QR Payment Proof’, ‘Uploaded: ‘.$move[‘url’]); return rest_ensure_response([‘message’=>’Uploaded successfully’,’url’=>$move[‘url’]]); } return rest_ensure_response([‘error’=>’Upload failed’]); }// Short helper to expose Stripe publishable key to front-end add_action(‘wp_head’,’bbb_expose_public_keys’); function bbb_expose_public_keys(){ if(defined(‘BBB_STRIPE_PUBLISHABLE’)){ echo ““; } }// Install notes: see top of file for constants. Ensure stripe-php installed and autoload included. // Example to include composer autoload at top of file if you used composer in theme/plugin: // require_once __DIR__ . ‘/vendor/autoload.php’;?>
Translate »
滚动至顶部