-
Notifications
You must be signed in to change notification settings - Fork 0
/
author_reg.php
75 lines (68 loc) · 2.83 KB
/
author_reg.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
require_once 'core/init.php';
error_reporting(-1);
require './luhn-creator.php';
//Load composer autoload
require_once __DIR__ . '/vendor/autoload.php';
//load environment variables
(new \Dotenv\Dotenv(__DIR__))->load();
$paystack = new \Yabacon\Paystack(PAYSTACK_SECRET_KEY);
$req = [];
// add the time of the request to the array
$req['time'] = gmdate("Y-m-d\TH:i:s\Z");
// add the user's ip to the array
$req['ip'] = getIp();
// get the formdata submitted
$req['form'] = json_encode($_POST);
// add the user email to the array
$req['email'] = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
// add the amount to the array
$req['bundle'] = floatval(filter_input(INPUT_POST, 'bundle'));
$title = $_POST['title'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$author_name = $_POST['author_name'];
$email = $_POST['email'];
$phone_number = $_POST['phone_number'];
$street = $_POST['street'];
$highQual = $_POST['highest_qualification'];
$institution = $_POST['institution'];
$occupation = $_POST['occupation'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];
$plan = $_POST['bundle'];
$course = $_POST['course'];
$charge = $plan * 100;
// get a code to use for this transaction
$newcode = getUnusedCode();
// save the array to a file named by the code chosen
file_put_contents('results/' . $newcode . '-request.json', json_encode($req));
// confirm that we got a valid email
if (!$req['email']) {
die('An invalid email was sent');
}
// confirm that we got a valid amount
if (!$req['bundle']) {
die('An invalid amount was sent');
}
// initiate transaction (Remember to change this if you are using Guzzle)
$virdir = new VirtualDirectory();
// Check the README here > https://github.com/yabacon/paystack-php/
$response = $paystack->transaction->initialize([
'reference'=>$newcode,
'amount'=>$charge, // in kobo
'email'=>$req['email'],
'callback_url'=>rtrim($virdir->thisURL,'/') . '/author_pay.php'
]);
// check if transaction url was generated
if ($url = $response->data->authorization_url) {
$db->query("INSERT INTO author_registered (course,tx_ref,title,first_name,last_name,author_name,email,phone_number,street,highest_q,institution,
occupation,state,city,country,bundle)
VALUES ('$course','$newcode','$title','$first_name','$last_name','$author_name','$email','$phone_number','$street','$highQual','$institution','$occupation','$state','$city','$country','$plan')");
header('Location: '.$url);
}else {
header('Location: error.php');
}
die();
?>