forked from CodeCloudMe/StripeAnywhereAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
136 lines (99 loc) · 3.79 KB
/
index.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
// Tested on PHP 5.2, 5.3
// This snippet (and some of the curl code) due to the Facebook SDK.
if (!function_exists('curl_init')) {
throw new Exception('Stripe needs the CURL PHP extension.');
}
if (!function_exists('json_decode')) {
throw new Exception('Stripe needs the JSON PHP extension.');
}
if (!function_exists('mb_detect_encoding')) {
throw new Exception('Stripe needs the Multibyte String PHP extension.');
}
// Stripe singleton
require(dirname(__FILE__) . '/Stripe/Stripe.php');
// Utilities
require(dirname(__FILE__) . '/Stripe/Util.php');
require(dirname(__FILE__) . '/Stripe/Util/Set.php');
// Errors
require(dirname(__FILE__) . '/Stripe/Error.php');
require(dirname(__FILE__) . '/Stripe/ApiError.php');
require(dirname(__FILE__) . '/Stripe/ApiConnectionError.php');
require(dirname(__FILE__) . '/Stripe/AuthenticationError.php');
require(dirname(__FILE__) . '/Stripe/CardError.php');
require(dirname(__FILE__) . '/Stripe/InvalidRequestError.php');
// Plumbing
require(dirname(__FILE__) . '/Stripe/Object.php');
require(dirname(__FILE__) . '/Stripe/ApiRequestor.php');
require(dirname(__FILE__) . '/Stripe/ApiResource.php');
require(dirname(__FILE__) . '/Stripe/SingletonApiResource.php');
require(dirname(__FILE__) . '/Stripe/List.php');
// Stripe API Resources
require(dirname(__FILE__) . '/Stripe/Account.php');
require(dirname(__FILE__) . '/Stripe/Card.php');
require(dirname(__FILE__) . '/Stripe/Charge.php');
require(dirname(__FILE__) . '/Stripe/Customer.php');
require(dirname(__FILE__) . '/Stripe/Invoice.php');
require(dirname(__FILE__) . '/Stripe/InvoiceItem.php');
require(dirname(__FILE__) . '/Stripe/Plan.php');
require(dirname(__FILE__) . '/Stripe/Token.php');
require(dirname(__FILE__) . '/Stripe/Coupon.php');
require(dirname(__FILE__) . '/Stripe/Event.php');
require(dirname(__FILE__) . '/Stripe/Transfer.php');
require(dirname(__FILE__) . '/Stripe/Recipient.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://manage.stripe.com/account
Stripe::setApiKey("sk_live_YOUR_KEYHERE!!!!!");
// Get the credit card details submitted by the form
//$token = $_POST['stripeToken'];
extract($_REQUEST);
if(!isset($number)){
$response = array("status"=>"fail", "resp"=>"Please send CC number");
echo(json_encode($response));
return;
}
if(!isset($expMonth)){
$response = array("status"=>"fail", "resp"=>"Please send Expiration Month");
echo(json_encode($response));
return;
}
if(!isset($expYear)){
$response = array("status"=>"fail", "resp"=>"Please send Expiration Year");
echo(json_encode($response));
return;
}
if(!isset($cvc)){
$response = array("status"=>"fail", "resp"=>"Please send CVC");
echo(json_encode($response));
return;
}
if(!isset($amount)){
$response = array("status"=>"fail", "resp"=>"Please send amount");
echo(json_encode($response));
return;
}
if(!isset($description)){
$description="mobile app purchase";
}
$amount = intval($amount);
$token= array("number"=>$number, "exp_month"=>$expMonth, "exp_year"=>$expYear, "cvc"=>$cvc);
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = Stripe_Charge::create(array(
"amount" => $amount, // amount in cents, again
"currency" => "usd",
"card" => $token,
"description" => $description)
);
$response = array("status"=>"success", "resp"=>"Payment processed");
$jResponse = json_encode($response);
echo($jResponse);
//header( 'Location: http://thecoded.com/appfactory/register/accepted.html' ) ;
} catch(Stripe_CardError $e) {
// The card has been declined
$response = array("status"=>"fail", "resp"=>"Payment wasn't processed ");
$jResponse = json_encode($response);
echo($jResponse);
//header( 'Location: http://thecoded.com/appfactory/register/declined.html' ) ;
}
?>