· 9 years ago · Feb 03, 2017, 02:46 PM
1<?php
2 $modx->log(xPDO::LOG_LEVEL_ERROR,'stripe-test begin');
3
4 $token = $_GET["stripeToken"];
5 $modx->log(xPDO::LOG_LEVEL_ERROR,$token);
6
7 $amount = $modx->resource->getTVValue(’classTuition’);
8 $modx->log(xPDO::LOG_LEVEL_ERROR,$amount);
9
10 $pagetitle = $modx->resource->getTVValue(’pagetitle’);
11 $modx->log(xPDO::LOG_LEVEL_ERROR,$pagetitle);
12 $secret_key = 'sk_test_JCKnNgUHieT6BXPxv6FUuwMr';
13
14 try {
15 require_once ($modx->getOption('core_path').'components/vendor/stripe/stripe-php/init.php');
16 \Stripe\Stripe::setApiKey($secret_key);
17 $charge = \Stripe\Charge::create(array(
18 "amount" => $amount,
19 "currency" => "usd",
20 "source" => $token,
21 "description" => "Description thing"
22 ));
23 if ($charge->paid == true) {
24 $modx->log(xPDO::LOG_LEVEL_ERROR,'payment worked, yay');
25 return true;
26 } else {
27 $modx->log(xPDO::LOG_LEVEL_ERROR,'payment didnt work, bummer');
28 return false;
29 }
30 } catch (\Stripe\Error\Card $e) {
31 $e_json = $e->getJsonBody();
32 $err = $e_json['error'];
33 $errors['stripe'] = $err['message'];
34 $modx->log(xPDO::LOG_LEVEL_ERROR,$err['message']);
35 } catch (\Stripe\Error\ApiConnection $e) {
36 } catch (\Stripe\Error\InvalidRequest $e) {
37 } catch (\Stripe\Error\Api $e) {
38 } catch (\Stripe\Error\Base $e) {
39 }
40 $modx->log(xPDO::LOG_LEVEL_ERROR,'stripe-test end');
41 return true;