· 9 years ago · Nov 22, 2016, 04:42 PM
1<?php
2
3function huddlco_stripe_process_payment() {
4 if(isset($_POST['action']) && $_POST['action'] == 'stripe' && wp_verify_nonce($_POST['stripe_nonce'], 'stripe-nonce')) {
5
6 global $stripe_options;
7
8 // load the stripe libraries
9 require_once(STRIPE_BASE_DIR . '/lib/Stripe.php');
10
11 // Get the credit card details submitted by the form
12 $token = $_POST['stripeToken'];
13
14 // check if we are using test mode
15 if(isset($stripe_options['test_mode']) && $stripe_options['test_mode']) {
16 $secret_key = $stripe_options['test_secret_key'];
17 } else {
18 $secret_key = $stripe_options['live_secret_key'];
19 }
20
21 // attempt to charge the customer's card
22 try {
23 $charge = \Stripe\Charge::create(array(
24 "amount" => 1000, // Amount in cents
25 "currency" => "usd",
26 "source" => $token,
27 "description" => "Example charge"
28 ));
29 } catch(\Stripe\Error\Card $e) {
30 // The card has been declined
31 }
32 }
33}
34add_action('init', 'huddlco_stripe_process_payment');