-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstripe.php
112 lines (90 loc) · 4.77 KB
/
stripe.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
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
<?php
function stripe_config() {
$configarray = array(
"FriendlyName" => array("Type" => "System", "Value"=>"Stripe"),
"public_live_key" => array("FriendlyName" => "Live Publishable Key", "Type" => "text", "Size" => "20", "Description" => "Available from Stripe's website at <a href='https://manage.stripe.com/account/apikeys' title='Stripe API Keys'>this link</a>.", ),
"private_live_key" => array("FriendlyName" => "Live Secret Key", "Type" => "text", "Size" => "20", "Description" => "Available from Stripe's website at <a href='https://manage.stripe.com/account/apikeys' title='Stripe API Keys'>this link</a>.", ),
"public_test_key" => array("FriendlyName" => "Test Publishable Key", "Type" => "text", "Size" => "20", "Description" => "Available from Stripe's website at <a href='https://manage.stripe.com/account/apikeys' title='Stripe API Keys'>this link</a>.", ),
"private_test_key" => array("FriendlyName" => "Test Secret Key", "Type" => "text", "Size" => "20", "Description" => "Available from Stripe's website at <a href='https://manage.stripe.com/account/apikeys' title='Stripe API Keys'>this link</a>." , ),
"problememail" => array("FriendlyName" => "Problem Report Email", "Type" => "text", "Size" => "20", "Description" => "Enter an email that the gateway can send a message to should an alert or other serious processing problem arise.", ),
"testmode" => array("FriendlyName" => "Test Mode", "Type" => "yesno", "Description" => "Tick this to make all transactions use your test keys above.", ),
);
return $configarray;
}
function stripe_link($params) {
# Invoice Variables
$invoiceid = $params['invoiceid'];
$description = $params["description"];
$amount = $params['amount']; # Format: ##.##
// Perform lookup to see if the invoice is for a recurring service
use WHMCS\Database\Capsule;
if (file_exists('../../dbconnect.php')) {
include '../../dbconnect.php';
} else if (file_exists('../../init.php')) {
include '../../init.php';
} else {
die('[ERROR] In modules/gateways/stripe.php: include error: Cannot find dbconnect.php or init.php');
}
$result = Capsule::table('tblinvoiceitems')->select('relid, amount, description')->where('type', 'Hosting')->where('invoiceid', $invoiceid)->first();
$relid = $result->relid;
$subscribe_price = $result->amount;
$plan_name = $result->description;
if ($relid != 0 || $relid != "") {
$wording = "Pay Once";
} else {
$wording = "Pay Now";
}
if ($subscribe_price != $amount) { // Tell the payment processing page that they user needs to come back and pay their one time fees, such as a domain name, that were not covered as part of the subscription
$warning = "true";
} else {
$warning = "false";
}
# Enter your code submit to the gateway...
$code = '<form method="post" action="ccpay.php">
<input type="hidden" name="description" value="'.$description.'" />
<input type="hidden" name="invoiceid" value="'.$invoiceid.'" />
<input type="hidden" name="amount" value="'.$amount.'" />
<input type="hidden" name="frominvoice" value="true" />
<input type="hidden" name="payfreq" value="otp" />
<input type="hidden" name="multiple" value="'.$warning.'" />
<input type="submit" value="'.$wording.'" />
</form>';
if ($relid != 0 || $relid != "") {
$code .= '<form method="post" action="ccpay.php">
<input type="hidden" name="description" value="'.$description.'" />
<input type="hidden" name="invoiceid" value="'.$invoiceid.'" />
<input type="hidden" name="amount" value="'.$subscribe_price.'" />
<input type="hidden" name="total_amount" value="'.$amount.'" />
<input type="hidden" name="frominvoice" value="true" />
<input type="hidden" name="payfreq" value="recur" />
<input type="hidden" name="planname" value="'.$plan_name.'" />
<input type="hidden" name="planid" value="'.$relid.'" />
<input type="hidden" name="multiple" value="'.$warning.'" />
<input type="submit" value="Set up Automatic Payment" />
</form>';
}
return $code;
}
/* This method use to make payment refund */
function stripe_refund($params) {
require_once('stripe/Stripe.php');
$gatewaytestmode = $params["testmode"];
if ($gatewaytestmode == "on") {
\Stripe\Stripe::setApiKey($params['private_test_key']);
} else {
\Stripe\Stripe::setApiKey($params['private_live_key']);
}
# Invoice Variables
$transid = $params['transid'];
# Perform Refund
try {
$ch = \Stripe\Refund::create(array(
"charge" => $transid
));
return array("status"=>"success","transid"=>$ch["id"],"rawdata"=>$ch);
} catch (Exception $e) {
$response['error'] = $e->getMessage();
return array("status"=>"error","rawdata"=>$response['error']);
}
}
?>