Permalink
Browse files

Fixed some further coder issues, fixed line lengths.

  • Loading branch information...
1 parent 4a9a72d commit ca4f098d0401cd8b8d84ff43ec1626c78f4b2cfc @victorquinn committed Nov 13, 2011
Showing with 82 additions and 38 deletions.
  1. +44 −11 README.txt
  2. +1 −1 css/uc_stripe.css
  3. +0 −1 uc_stripe.info
  4. +18 −18 uc_stripe.install
  5. +19 −7 uc_stripe.module
View
@@ -1,12 +1,19 @@
+This is an Ubercart payment gateway module for Stripe.
-This is an Ubercart payment gateway module for Stripe. It includes integration with the Ubercart Recurring Payments module for subscriptions.
+It includes integration with the Ubercart Recurring Payments
+module for subscriptions.
-Currently this module is only compatible with Drupal 6. Support for Drupal 7 planned, but not yet started.
+Currently this module is only compatible with Drupal 6.
+Support for Drupal 7 planned, but not yet started.
!! IMPORTANT !!
===============
-This module is a work in progress and as such has not been extensively tested in a production environment. DO NOT INSTALL THIS IN A PRODUCTION ENVIRONMENT. If you want to help test, please do, but do not use it for anything mission critical until it has been tested further.
+This module is a work in progress and as such has not been
+extensively tested in a production environment. DO NOT INSTALL
+THIS IN A PRODUCTION ENVIRONMENT. If you want to help test,
+please do, but do not use it for anything mission critical
+until it has been tested further.
Installation and Setup
======================
@@ -17,26 +24,52 @@ b) Visit your Ubercart Store Administration page, Configuration
section, and enable the gateway under the Payment Gateways.
(admin/store/settings/payment/edit/gateways)
-c) On this page, provide the following settings:
+c) On this page, provide the following settings:
- Your Stripe API key, private
-d) Download and install the latest version of the [PHP Stripe library](https://github.com/stripe/stripe-php). Put it in sites/all/libraries/stripe such that the path to Stripe.php is sites/all/libraries/stripe/lib/Stripe.php
+d) Download and install the latest version of the PHP Stripe
+library (https://github.com/stripe/stripe-php. Put it in
+sites/all/libraries/stripe such that the path to Stripe.php
+is sites/all/libraries/stripe/lib/Stripe.php
-e) If you are using recurring payments, install version 2.x of the [Ubercart Recurring module](http://drupal.org/project/uc_recurring) and set up as described below
+e) If you are using recurring payments, install version 2.x
+of the Ubercart Recurring module:
+http://drupal.org/project/uc_recurring
+and set up as described below
Recurring Payments Setup
========================
-First, you'll need the [Ubercart Recurring module](http://drupal.org/project/uc_recurring) installed. It is not listed as a dependency for this Stripe payment module because this module could be used without recurring payments. But it is a dependency to use the recurring payments piece of this module.
-
-Create a product in your Drupal site. After creating that product, edit it and click on the "Features" tab. Under "Add a new feature," select "Recurring fee" and click add. In order for this to work with Stripe, you must select the "Applicable SKU." This will create the subscription plan in Stripe (provided of course that you have your API keys set up). Then, later, when a user purchases this product, they will get added as "Customers" to this "Plan."
+First, you'll need the Ubercart Recurring module:
+http://drupal.org/project/uc_recurring installed. It is not
+listed as a dependency for this Stripe payment module because
+this module could be used without recurring payments.
+But it is a dependency to use the recurring payments piece of
+this module.
+
+Create a product in your Drupal site. After creating that
+product, edit it and click on the "Features" tab. Under
+"Add a new feature," select "Recurring fee" and click add.
+In order for this to work with Stripe, you must select the
+"Applicable SKU." This will create the subscription plan in
+Stripe (provided of course that you have your API keys set up).
+Then, later, when a user purchases this product, they will get
+added as "Customers" to this "Plan."
Notes:
-- Stripe doesn't have a way to set the number of billing periods. So basically people are subscribed or unsubscribed, not subscribed for 12 months then done. We hope to add the ability to change this later, but we would have to do it on our end. So for example, we would have to keep track of the time since the subscription started in Drupal and send Stripe a request when that time is up.
+- Stripe doesn't have a way to set the number of billing periods.
+So basically people are subscribed or unsubscribed, not
+subscribed for 12 months then done. We hope to add the
+ability to change this later, but we would have to do it
+on our end. So for example, we would have to keep track of
+the time since the subscription started in Drupal and send
+Stripe a request when that time is up.
Todo
====
-- Enable set number of billing periods. So the system will keep track of the time and then shoot of a request to Stripe via cron to cancel the subscription once the billing period is up.
+- Enable set number of billing periods. So the system will
+keep track of the time and then shoot of a request to Stripe
+via cron to cancel the subscription once the billing period is up.
View
@@ -25,4 +25,4 @@
a.poweredbylink:hover {
text-decoration: none;
-}
+}
View
@@ -4,6 +4,5 @@ dependencies[] = uc_payment
dependencies[] = uc_credit
dependencies[] = libraries
package = Ubercart - payment
-version = 6.x-1.x-dev
core = 6.x
php = 5.0
View
@@ -6,7 +6,7 @@
*/
/**
- * Implementation of hook_install()
+ * Implements hook_install().
*/
function uc_stripe_install() {
drupal_install_schema('uc_stripe');
@@ -17,60 +17,60 @@ function uc_stripe_install() {
}
/**
- * Implementation of hook_uninstall()
+ * Implements hook_uninstall().
*/
function uc_stripe_uninstall() {
drupal_uninstall_schema('uc_stripe');
}
/**
- * Implementation of hook_schema()
+ * Implements hook_schema().
*/
function uc_stripe_schema() {
$schema = array();
$schema['uc_recurring_stripe'] = array(
- 'description' => t('Stores customer ids and plan names for Stripe subscriptions.'),
+ 'description' => 'Stores customer ids and plan names for Stripe subscriptions.',
'fields' => array(
'rfid' => array(
- 'description' => t('The recurring fee id.'),
+ 'description' => 'The recurring fee id.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'active' => array(
- 'description' => t('Whether or not this subscription is currently active.'),
+ 'description' => 'Whether or not this subscription is currently active.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
- 'description' => t('The uid of this user.'),
+ 'description' => 'The uid of this user.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'order_id' => array(
- 'description' => t('The order_id of the purchase.'),
+ 'description' => 'The order_id of the purchase.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
- 'description' => t('The nid of this subscription product.'),
+ 'description' => 'The nid of this subscription product.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'customer_id' => array(
- 'description' => t('The Stripe customer id.'),
+ 'description' => 'The Stripe customer id.',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => '',
),
'plan_id' => array(
- 'description' => t('The corresponding plan id.'),
+ 'description' => 'The corresponding plan id.',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
@@ -83,14 +83,14 @@ function uc_stripe_schema() {
}
/**
- * Implementation of hook_update_N()
+ * Implements hook_update_N().
*
* Added order_id to schema.
*/
function uc_stripe_update_6101() {
$ret = array();
db_add_field($ret, 'uc_recurring_stripe', 'order_id', array(
- 'description' => t('The order_id of the purchase.'),
+ 'description' => 'The order_id of the purchase.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
@@ -100,14 +100,14 @@ function uc_stripe_update_6101() {
}
/**
- * Implementation of hook_update_N()
+ * Implements hook_update_N().
*
* Added active to schema to indicate subscription status.
*/
function uc_stripe_update_6102() {
$ret = array();
db_add_field($ret, 'uc_recurring_stripe', 'active', array(
- 'description' => t('Whether or not this subscription is currently active.'),
+ 'description' => 'Whether or not this subscription is currently active.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
@@ -117,18 +117,18 @@ function uc_stripe_update_6102() {
}
/**
- * Implementation of hook_update_N()
+ * Implements hook_update_N().
*
* Added nid of subscription object.
*/
function uc_stripe_update_6103() {
$ret = array();
db_add_field($ret, 'uc_recurring_stripe', 'nid', array(
- 'description' => t('The nid of this subscription product.'),
+ 'description' => 'The nid of this subscription product.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
)
);
return $ret;
-}
+}
View
@@ -42,7 +42,7 @@ function uc_stripe_recurring_info() {
'charge' => UC_RECURRING_MENU_DEFAULT,
'edit' => UC_RECURRING_MENU_DEFAULT,
'cancel' => UC_RECURRING_MENU_DEFAULT,
- ), // Use the default user operation defined in uc_recurring.
+ ),
);
return $items;
}
@@ -65,7 +65,7 @@ function uc_stripe_form_uc_cart_checkout_form_alter(&$form, &$form_state) {
if (variable_get('uc_stripe_poweredby', FALSE)) {
drupal_add_css(drupal_get_path('module', 'uc_stripe') . '/css/uc_stripe.css');
$message = "<a href='https://stripe.com' target='_blank' class='poweredbylink'><div class='poweredbystripe'>";
- $message .= "powered by " . theme('image', drupal_get_path('module', 'uc_stripe') . '/images/logo_bare.png', 'powered by Stripe', 'powered by Stripe');
+ $message .= t("powered by") . " " . theme('image', drupal_get_path('module', 'uc_stripe') . '/images/logo_bare.png', 'powered by Stripe', 'powered by Stripe');
$message .= "</div></a>";
$form['panes']['payment']['poweredbystripe'] = array(
'#type' => 'markup',
@@ -149,6 +149,13 @@ function uc_stripe_cart_item($op, &$item) {
* Callback Functions, Forms, and Tables
* *****************************************************************************/
+/**
+ * Validate the product feature save. Basically, ensure
+ * everything is Stripe compatible. Some options are
+ * not Stripe compatible and we have stripped out the UI
+ * but we double check to ensure the user has not attempted
+ * to circumvent those measures.
+ */
function uc_stripe_product_feature_validate($form, &$form_state) {
// First, ensure the user has selected a SKU
@@ -178,7 +185,8 @@ function uc_stripe_product_feature_validate($form, &$form_state) {
$form['fee']['fee_amount']['#value'] = $form_state['values']['product_price'];
}
- // We want to programmatically create a Stripe subscription plan for this item.
+ // We want to programmatically create a Stripe subscription plan
+ // for this item.
if (!_uc_stripe_load_api()) {
form_set_error('', "There was a problem loading the Stripe API. Recurring feature could not be created. Please ensure the API is in sites/all/libraries/stripe.");
return FALSE;
@@ -357,6 +365,9 @@ function uc_stripe_charge($order_id, $amount, $data) {
/* uc_recurring callbacks */
+/**
+ * Process the recurring fee transaction.
+ */
function uc_stripe_process($order, &$fee) {
global $user;
$plan_id = str_replace('/', '_', $fee->data['model']);
@@ -389,15 +400,16 @@ function uc_stripe_process($order, &$fee) {
}
}
- // If no match, this recurring item doesn't correlate to any Stripe subscription plan
+ // If no match, this recurring item doesn't correlate to any
+ // Stripe subscription plan
if (!$match) {
watchdog('uc_stripe', "The sku for the Recurring Fee object doesn't match any Stripe plans.");
return FALSE;
}
- // Tricky to find the nid of the recurring product from a cart of other things.
- // Note, this will only work with a single subscription item in the cart. If
- // more, it throws an error.
+ // Tricky to find the nid of the recurring product from a cart of
+ // other things. Note, this will only work with a single
+ // subscription item in the cart. If more, it throws an error.
foreach ($order->products as $product) {
if (db_result(db_query("SELECT nid FROM {uc_product_features} WHERE fid = 'recurring' AND nid = %d", $product->nid))) {

0 comments on commit ca4f098

Please sign in to comment.