-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPluginPaystack.php
More file actions
148 lines (138 loc) · 5.99 KB
/
PluginPaystack.php
File metadata and controls
148 lines (138 loc) · 5.99 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
require_once 'modules/admin/models/GatewayPlugin.php';
require_once 'modules/billing/models/class.gateway.plugin.php';
class PluginPaystack extends GatewayPlugin
{
function getVariables()
{
$variables = array(
lang('Plugin Name') => array(
'type' => 'hidden',
'description' => lang('How CE sees this plugin ( not to be confused with the Signup Name )'),
'value' => 'Paystack (Debit/Credit Cards)'
),
lang('Test Mode') => array(
'type' => 'yesno',
'description' => lang('Enable this option to enable Test Mode'),
'value' => ''
),
lang('Live Secret Key') => array(
'type' => 'text',
'description' => lang('Enter your Live Secret Key here'),
'value' => ''
),
lang('Live Public Key') => array(
'type' => 'text',
'description' => lang('Enter your Live Public Key here'),
'value' => ''
),
lang('Test Secret Key') => array(
'type' => 'text',
'description' => lang('Enter your Test Secret Key here'),
'value' => ''
),
lang('Test Public Key') => array(
'type' => 'text',
'description' => lang('Enter your Test Public Key here'),
'value' => ''
),
lang('Invoice After Signup') => array(
'type' => 'yesno',
'description' => lang('Select YES if you want an invoice sent to the client after signup is complete.'),
'value' => '1'
),
lang('Signup Name') => array(
'type' => 'text',
'description' => lang('Select the name to display in the signup process for this payment type. Example: eCheck or Credit Card.'),
'value' => 'Paystack (Debit/Credit Cards)'
),
lang('Dummy Plugin') => array(
'type' => 'hidden',
'description' => lang('1 = Only used to specify a billing type for a client. 0 = full fledged plugin requiring complete functions'),
'value' => '0'
),
lang('Auto Payment') => array(
'type' => 'hidden',
'description' => lang('No description'),
'value' => '0'
),
lang('Form') => array(
'type' => 'hidden',
'description' => lang('Has a form to be loaded? 1 = YES, 0 = NO'),
'value' => '1'
)
);
return $variables;
}
public function credit($params)
{
return $this->user->lang("This payment gateway does not support refunds.");
}
function singlepayment($params)
{
$transactionId = $params['plugincustomfields']['paystack_transaction_id'];
$invoiceId = $params['invoiceNumber'];
$pricePaid = $params['invoiceTotal'];
if ($this->getVariable('Test Mode') == '1') {
$privateKey = $this->getVariable('Test Secret Key');
} else {
$privateKey = $this->getVariable('Live Secret Key');
}
try {
$paystack = new Yabacon\Paystack($privateKey);
$response = $paystack->transaction->verify(['reference' => $transactionId]);
} catch (Exception $e) {
CE_Lib::log(1, $e->getMessage());
return $this->user->lang("There was an error with PayStack.")." ".$e->getMessage();
}
$cPlugin = new Plugin($invoiceId, 'paystack', $this->user);
$cPlugin->m_TransactionID = $transactionId;
$cPlugin->setAction('charge');
$cPlugin->setAmount($pricePaid);
if ($response->data->status == 'success') {
$success = true;
$transaction = "Paystack Payment of {$pricePaid} was accepted";
$cPlugin->PaymentAccepted($pricePaid, $transaction);
} else {
$success = false;
$transaction = "Payment rejected - Reason: ".$error;
$cPlugin->PaymentRejected($transaction, false);
}
//Need to check to see if user is coming from signup
if ($params['isSignup'] == 1) {
if ($this->settings->get('Signup Completion URL') != '') {
if ($success === true) {
$returnURL = $this->settings->get('Signup Completion URL').'?success=1';
} else {
$returnURL = $this->settings->get('Signup Completion URL');
}
} else {
if ($success === true) {
$returnURL = CE_Lib::getSoftwareURL()."/order.php?step=complete&pass=1";
} else {
$returnURL = CE_Lib::getSoftwareURL()."/order.php?step=3";
}
}
} else {
if ($success === true) {
$returnURL = CE_Lib::getSoftwareURL()."/index.php?fuse=billing&paid=1&controller=invoice&view=invoice&id=".$invoiceId;
} else {
$returnURL = CE_Lib::getSoftwareURL()."/index.php?fuse=billing&cancel=1&controller=invoice&view=invoice&id=".$invoiceId;
}
}
header("Location: " . $returnURL);
}
public function getForm($args)
{
$this->view->amount = sprintf("%01.2f", round($args['invoiceBalanceDue'], 2)) * 100;
$this->view->currency = $args['currency'];
$this->view->from = $args['from'];
$this->view->termsConditions = $args['termsConditions'];
if ($this->getVariable('Test Mode') == '1') {
$this->view->publicKey = $this->getVariable('Test Public Key');
} else {
$this->view->publicKey = $this->getVariable('Live Public Key');
}
return $this->view->render('form.phtml');
}
}