Skip to content

Commit

Permalink
Hello world.
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinSainton committed Apr 19, 2014
1 parent b0c69d6 commit 217e1e0
Show file tree
Hide file tree
Showing 40 changed files with 6,108 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ Stripe
======

Premium Stripe Payment Gateway for the 2.0 Payment Gateway API in WP eCommerce.

## Note ##

This plugin is freely available on GitHub for developers to test, utilize and contribute to. We would ask, however, that if you do end up using our plugin on a production website, be sure to purchase a license to it at [our website](http://getshopped.org/premium-upgrades/payment-gateways/stripe-payment-gateway-wp-e-commerce/).
25 changes: 25 additions & 0 deletions Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
== Description ==


This plugin will add the Stripe gateway to your list of payment gateways in WP e-Commerce.


== Installation ==


1.). Upload the folder 'wpec-stripe' to the '/wp-content/plugins/' directory or use the plugin up loader in the Wordpress dashboard. ( Plugins -> add new -> upload )

2.). Activate the Stripe Payment Gateway for WP e-Commerce through the 'Plugins' menu in WordPress.

3.) The Stripe Gateway will appear in your list of payment gateways in Settings -> Store -> Payments.

4.) Put your Stripe API key into the setting box and the gateway will be good to go.


== Support ==

If you have any problems, questions or suggestions please raise a Premium Support topic from the links below.

Documentation: http://docs.getshopped.org/

Premium Support: http://getshopped.org/resources/premium-support/
54 changes: 54 additions & 0 deletions includes/checkout-fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

function pw_wpsc_stripe_checkout_fields() {
global $gateway_checkout_form_fields;

if ( in_array( 'wpsc_stripe', (array) get_option( 'custom_gateway_options' ) ) ) {

$curryear = date( 'Y' );
$years = '';
//generate year options
for ( $i = 0; $i < 10; $i++ ) {
$years .= "<option value='" . $curryear . "'>" . $curryear . "</option>\r\n";
$curryear++;
}

ob_start();
?>
</br>
<tr>
<td class="wpsc_CC_details"> <?php _e( 'Credit Card Number *', 'wpsc' ); ?></td>
<td>
<input type="text" value='' name="card_number" />
</td>
</tr>
<tr>
<td class='wpsc_cc_details'><?php _e( 'Credit Card Expiry *', 'wpsc' ); ?></td>
<td>
<select class='wpsc_ccBox' name='expiry[month]'>
<option value='01'>01</option>
<option value='02'>02</option>
<option value='03'>03</option>
<option value='04'>04</option>
<option value='05'>05</option>
<option value='06'>06</option>
<option value='07'>07</option>
<option value='08'>08</option>
<option value='09'>09</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
</select>
<select class='wpsc_ccBox' name='expiry[year]'>
<?php echo $years; ?>
</select>
</td>
</tr>
<tr>
<td class='wpsc_CC_details'><?php _e( 'CVC *', 'wpsc' ); ?></td>
<td><input type='text' size='4' value='' maxlength='4' name='card_code' /></td>
</tr>
<?php
$gateway_checkout_form_fields['wpsc_stripe'] = ob_get_clean();
}
}
101 changes: 101 additions & 0 deletions includes/gateway-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
function pw_wpsc_stripe_settings_form() {
global $wpdb;

$stripe_live_secret_key = get_option( 'wpsc_stripe_live_key' );
$stripe_test_secret_key = get_option( 'wpsc_stripe_test_key' );
$payment_mode = get_option( 'wpsc_stripe_payment_mode' );

// make sure the stores currency is supported by Stripe

if ( ( isset ( $stripe_live_secret_key ) && $stripe_live_secret_key != '' ) || ( isset ( $stripe_test_secret_key ) && $stripe_test_secret_key != '' ) ) {
include_once(PW_WPSC_PLUGIN_DIR . '/stripe/Stripe.php');

$curr_supported = false;
$currency_code = $wpdb->get_var( "SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST .
"` WHERE `id`='" . get_option( 'currency_type' ) . "' LIMIT 1" );

$secret_key = $payment_mode == 'test' ? $stripe_test_secret_key : $stripe_live_secret_key;
Stripe::setApiKey($secret_key);
$account_info = Stripe_Account::retrieve();

if (in_array(strtolower($currency_code), $account_info->currencies_supported) ) {
$curr_supported = true;
}
}

$output = "<tr>\n\r
<td>Stripe Live Secret Key</td>
<td><input type='text' size='30' value='" . $stripe_live_secret_key . "' name='wpsc_stripe_live_key' /></td>
</tr>
<tr>
<td>Stripe Test Secret Key</td>
<td><input type='text' size='30' value='" . $stripe_test_secret_key . "' name='wpsc_stripe_test_key' /></td>
</tr>
<tr>
<td>Test Mode?</td>
<td>
<select name='wpsc_stripe_payment_mode'>
<option value='test' " . selected('test', $payment_mode, false) . ">Test mode</option>
<option value='live' " . selected('live', $payment_mode, false) . ">Live Mode</option>
</select>
</td>
</tr>\n\r";

if( $stripe_live_secret_key == '' || $stripe_test_secret_key == '' )
{
$output .='
<tr>
<td colspan="2">
<strong style="color:red;"> '.__( 'Please enter API info to validate store currency against Stripe account', 'wpsc' ). ' </strong>
</td>
</tr>
';

} elseif ( ! $curr_supported ) {
$output .='
<tr>
<td>
<strong style="color:red;">'. __( 'Your Selected Currency is not supported by Stripe,
to use Stripe, go the the store general settings and under &quot;Currency Type&quot; select one
of the currencies listed on the right.', 'wpsc' ) .' </strong>
</td>
<td>
<ul>';
$country_list = $wpdb->get_results( "SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST .
"` WHERE `code` IN( 'USD','CAD') ORDER BY `country` ASC" ,'ARRAY_A');
foreach($country_list as $country){
$output .= '<li>'. $country['country'].'</li>';
}
$output .= '</ul>
</td>
</tr>';
} else {
$output .='
<tr>
<td colspan="2">
<strong style="color:green;"> '.__( 'Your Selected Currency will work with Stripe', 'wpsc' ). ' </strong>
</td>
</tr>
';
}

return $output;
}

function pw_wpsc_save_stripe_settings() {

$options = array(
'wpsc_stripe_live_key',
'wpsc_stripe_test_key',
'wpsc_stripe_payment_mode'
);

foreach ( $options as $option ) {
if ( ! empty( $_POST[ $option ] ) ) {
update_option( $option, sanitize_text_field( $_POST[ $option ] ) );
}
}

return true;
}
124 changes: 124 additions & 0 deletions includes/stripe-functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

function pw_wpsc_check_stripe_plan_exists( $plan_id ) {
global $rcp_options;

require_once(PW_WPSC_PLUGIN_DIR . '/stripe/Stripe.php');

$stripe_live_secret_key = get_option( 'wpsc_stripe_live_key' );
$stripe_test_secret_key = get_option( 'wpsc_stripe_test_key' );
$payment_mode = get_option( 'wpsc_stripe_payment_mode' );

$secret_key = $payment_mode == 'test' ? $stripe_test_secret_key : $stripe_live_secret_key;

Stripe::setApiKey( $secret_key );

try {
$plan = Stripe_Plan::retrieve($plan_id);
return true;
} catch (Exception $e) {
return false;
}
}

function pw_wpsc_create_stripe_plan($plan_name, $plan_id, $price, $duration_unit) {

require_once(PW_WPSC_PLUGIN_DIR . '/stripe/Stripe.php');

$stripe_live_secret_key = get_option( 'wpsc_stripe_live_key' );
$stripe_test_secret_key = get_option( 'wpsc_stripe_test_key' );
$payment_mode = get_option( 'wpsc_stripe_payment_mode' );

$secret_key = $payment_mode == 'test' ? $stripe_test_secret_key : $stripe_live_secret_key;

// get all subscription level info for this plan
$price = $price * 100;

Stripe::setApiKey($secret_key);

try {
Stripe_Plan::create(array(
"amount" => $price,
"interval" => $duration_unit,
"name" => $plan_name,
"currency" => 'usd',
"id" => $plan_id
)
);
// plann successfully created
return true;

} catch (Exception $e) {
// there was a problem
echo '<pre>'; print_r($e); echo '</pre>';exit;
return false;
}
}

function pw_wpsc_cancel_stripe( $user_id ) {

require_once(PW_WPSC_PLUGIN_DIR . '/stripe/Stripe.php');

$stripe_live_secret_key = get_option( 'wpsc_stripe_live_key' );
$stripe_test_secret_key = get_option( 'wpsc_stripe_test_key' );
$payment_mode = get_option( 'wpsc_stripe_payment_mode' );

$secret_key = $payment_mode == 'test' ? $stripe_test_secret_key : $stripe_live_secret_key;

Stripe::setApiKey($secret_key);

$customer_id = pw_wpsc_get_stripe_customer_id($user_id);

try {

$cu = Stripe_Customer::retrieve( $customer_id );
$cu->cancelSubscription(array('at_period_end' => true));

} catch(Exception $e) {
wp_die('<pre>' . $e . '</pre>', 'Error');
}
}

function pw_wpsc_stripe_set_as_customer($user_id = null, $customer) {

if ( ! $user_id ) {
global $user_ID;
$user_id = $user_ID;
}

update_user_meta($user_id, '_pw_stripe_is_customer', 'yes');
update_user_meta($user_id, '_pw_stripe_user_id', $customer->id);

}

function pw_wpsc_stripe_is_customer($user_id = null) {

if(!$user_id) {
global $user_ID;
$user_id = $user_ID;
}

if(get_user_meta($user_id, '_pw_stripe_is_customer', true) == 'yes') {
return true;
}
return false;
}

// gets the Stripe customer ID from a WP user ID
function pw_wpsc_get_stripe_customer_id($user_id) {
return get_user_meta($user_id, '_pw_stripe_user_id', true);
}

// gets the user object from a Stripe customer ID string
function pw_stripe_get_user_id($customer_id) {
$user = get_users(
array(
'meta_key' => '_pw_stripe_user_id',
'meta_value' => $customer_id,
'number' => 1
)
);
if($user)
return $user[0];
return false;
}
Loading

0 comments on commit 217e1e0

Please sign in to comment.