-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstripe_connect.php
51 lines (42 loc) · 1.65 KB
/
stripe_connect.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
<?php
require_once 'config.php';
require_once 'utilities.php';
require_once 'vendor/autoload.php';
require_once 'mongo.php';
$error = get_parameter('error');
$error_description = get_parameter('error_description');
$scope = get_parameter('scope');
$code = get_parameter('code');
if ($scope && $code) {
$post = array(
'client_secret' => $secret_key,
'code' => $code,
'grant_type' => 'authorization_code'
);
// We got the scope and code. We'll exchane this with the SPK and AT by running a curl function
$res = json_decode(postToCurl($stripe_token_url, $post));
if (isset($res->error) || isset($res->error_description)) {
$s = "Error: ".$res->error." - ".$res->error_description;
} else {
$accessToken = $res->access_token;
$pubKey = $res->stripe_publishable_key;
$stripe_user = $res->stripe_user_id;
$mongo = new MongoInvoice();
$collection = $mongo->getCollection();
$results = $collection->find([ 'su' => $stripe_user ]);
// Everytime we need to check SPK and AT for all invoices of a user, in case of possible overrides or invokes
foreach ($results as $old_invoice_model) {
if (($old_invoice_model['at'] != $accessToken) || ($old_invoice_model['spk'] != $pubKey) ) {
$mongo->update($old_invoice_model['_id']->{'$id'}, [
'$set' => [
'at' => $accessToken,
'spk' => $pubKey
]
]);
}
}
}
} else if ($error || $error_description) {
$s = "Error: ".$error." - ".$error_description;
}
require_once 'index.html';