Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Please waith' Loading never goes away #33

Open
marshallunduemi opened this issue Oct 3, 2020 · 0 comments
Open

'Please waith' Loading never goes away #33

marshallunduemi opened this issue Oct 3, 2020 · 0 comments

Comments

@marshallunduemi
Copy link

marshallunduemi commented Oct 3, 2020

Actual Results:

There were no error messages

http://prntscr.com/usngk8


<?php
require_once 'vendor/autoload.php';

// documented at https://github.com/yabacon/paystack-php
use Yabacon\Paystack;
use Yabacon\Paystack\MetadataBuilder;

define('PAYSTACK', '1');


define('PAYSTACK_SECRET', 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$path = filter_input(INPUT_GET, 'path');

// sample code to start a transaction
// more about thr transaction/initialize enpoint
// here: https://developers.paystack.co/v1.0/reference#initialize-a-transaction
if($path === 'new-access-code'){
    if(!(($email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) 
        && ($amount = filter_input(INPUT_POST, 'amount', FILTER_VALIDATE_FLOAT)))){
        http_response_code(400);
        die('Invalid Email or amount sent');
    }

    $amountinkobo = 100 * $amount;
    $builder = new MetadataBuilder();
    $builder->withCustomField('MyStudio', 'Premium Plan Charge');
    time()%2 && $builder->withCustomFilters(['recurring'=>true]);
    $metadata = $builder->build();

    try{
        $paystack = new Paystack(PAYSTACK_SECRET);
        $paystack->disableFileGetContentsFallback();
        $trx = $paystack->transaction->initialize([
            'amount'=>$amountinkobo,
            'email'=>$email,
            'metadata'=>$metadata,
        ]);
    } catch(Exception $e){
        http_response_code(400);
        die($e->getMessage());
    }

    die($trx->data->access_code);
}

// sample code to verify a transaction reference
// more about the transaction/verify enpoint
// here: https://developers.paystack.co/v1.0/reference#verifying-transactions
if(strpos($path, 'verify/') === 0){
    // whatever is after verify is our refernce
    $reference = substr($path, 7);

    try{
        $paystack = new Paystack(PAYSTACK_SECRET);
        $paystack->disableFileGetContentsFallback();
        $trx = $paystack->transaction->verify([
            'reference'=>$reference,
        ]);
    } catch(Exception $e){
        http_response_code(400);
        die($e->getMessage());
    }

    if($trx->data->status === 'success'){
        // give value
        require '../config.php';
        //require '../logged_user_info.php';

        //genereate a unique token for each transaction secure system
        //$token = bin2hex(openssl_random_pseudo_bytes(6));
        $dated=time();
        $timeDated=date('D, M m, Y ');
        $SubscribePlan=$db->query("INSERT INTO service_sub (user_id_fk, tr_id_fk, sub_type, timeDated, sub_dated)
            VALUES ('$user_uid', '$reference', 'premium', '$timeDated', '$dated' )");

        $SubscribePlan=$db->query("UPDATE users SET service_status='on', tr_id='$reference' WHERE uid='$user_uid' ");

                # code...
          echo '<div class="notice success"><p>Your account is now activated to Premium.</p>
           <a href="../subscription.php" class="btn btn-azure" data-paystack="submit">Finished</a></div>';

    }

    // dump gateway response for display to user
    die($trx->data->gateway_response);
}

// our payment form
if($path === 'payment'){
    include_once 'pay.php';
    die();
}

// our payment form
if(($path === '/') || ($path === '')){
    include_once 'pay.php';
    die();
}

// log a client-side error
if($path === 'report'){
    file_put_contents('client-errors.log', "\n".json_encode($_POST), FILE_APPEND);
    die();
}

// if it got here, it was neither of the recognized paths
// show the welcome message
http_response_code(404);
?><p>Your server is set up.
    <br>/<?php echo $path; ?> does not exist<br>
    Open <i>/payment</i> to test the form.
    </p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant