Making WordPress.org


Ignore:
Timestamp:
02/12/2018 05:39:50 PM (8 years ago)
Author:
iandunn
Message:

WordCamp Payments: Replace stripe-php library with WordCamp Stripe client.

This is better because we don't have to worry about keeping it updated, it only has the functionality we're actually using, we won't end up with unit tests, etc inside a publicly accessible folder, etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/sponsor-payment-stripe.php

    r6601 r6602  
    55
    66namespace WordCamp\Budgets\Sponsor_Payment_Stripe;
     7use WordCamp\Utilities\Stripe_Client;
    78use WordCamp_Budgets;
     9use Exception;
    810
    911defined( 'WPINC' ) or die();
     
    189191            $wordcamp_site_url = set_url_scheme( esc_url_raw( get_blog_option( $wordcamp_site_id, 'home', '' ) ), 'https' );
    190192
    191             require_once( __DIR__ . '/stripe-php/init.php' );
    192             \Stripe\Stripe::setApiKey( $data['keys']['secret'] );
     193            $body = array(
     194                'amount'      => round( $payment_data['amount'], 2 ) * 100,
     195                'currency'    => $payment_data['currency'],
     196                'source'      => $_POST['stripeToken'],
     197                'description' => 'WordCamp Sponsorship: ' . $wordcamp_obj->post_title,
     198                'metadata'    => array(
     199                    'invoice_id'       => $payment_data['invoice_id'],
     200                    'wordcamp_id'      => $payment_data['wordcamp_id'],
     201                    'wordcamp_site_id' => $wordcamp_site_id,
     202                    'wordcamp_url'     => $wordcamp_site_url,
     203                ),
     204            );
    193205
    194206            try {
    195                 $charge = \Stripe\Charge::create( array(
    196                     'amount'      => round( $payment_data['amount'], 2 ) * 100,
    197                     'currency'    => $payment_data['currency'],
    198                     'source'      => $_POST['stripeToken'],
    199                     'description' => 'WordCamp Sponsorship: ' . $wordcamp_obj->post_title,
    200                     'metadata'    => array(
    201                         'invoice_id'       => $payment_data['invoice_id'],
    202                         'wordcamp_id'      => $payment_data['wordcamp_id'],
    203                         'wordcamp_site_id' => $wordcamp_site_id,
    204                         'wordcamp_url'     => $wordcamp_site_url,
    205                     ),
    206                 ) );
    207             } catch ( \Stripe\Error\Card $e ) {
    208                 $data['errors'][] = 'The card has been declined.';
    209                 return;
    210             } catch ( \Exception $e ) {
    211                 $data['errors'][] = 'An unknown error has occurred, please try again later.';
     207                $stripe = new Stripe_Client( $data['keys']['secret'] );
     208                $charge = $stripe->charge( $body );
     209            } catch ( Exception $exception ) {
     210                $data['errors'][] = "An error occurred, please try another card. If that doesn't work, please contact ". EMAIL_CENTRAL_SUPPORT .".";
    212211                return;
    213212            }
Note: See TracChangeset for help on using the changeset viewer.