Add metadata in 7.x-3.x-dev #10

Open
mattbk wants to merge 16 commits from add-metadata-endracing-7.x-3.1 into 7.x-3.x-dev
4 changed files with 37 additions and 9 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

3
.gitignore vendored
View File

@ -1,2 +1 @@
*.patch
*.patch

View File

@ -6,10 +6,3 @@ dependencies[] = libraries
package = Ubercart - payment package = Ubercart - payment
core = 7.x core = 7.x
php = 5.3 php = 5.3
; Information added by Drupal.org packaging script on 2019-09-13
version = "7.x-3.1+1-dev"
core = "7.x"
project = "uc_stripe"
datestamp = "1568380086"

View File

@ -436,6 +436,20 @@ function uc_stripe_settings_form() {
'#description' => 'Show "powered by Stripe" in checkout.', '#description' => 'Show "powered by Stripe" in checkout.',
'#default_value' => variable_get('uc_stripe_poweredby', FALSE), '#default_value' => variable_get('uc_stripe_poweredby', FALSE),
); );
$form['uc_stripe_settings']['uc_stripe_metadata_titles'] = array(
'#type' => 'checkbox',
'#title' => t('Metadata: Title'),
'#description' => t('Include order item title(s) in Stripe metadata.'),
'#default_value' => variable_get('uc_stripe_metadata_titles', FALSE),
);
$form['uc_stripe_settings']['uc_stripe_metadata_models'] = array(
'#type' => 'checkbox',
'#title' => t('Metadata: Model'),
'#description' => t('Include item model(s) (SKU(s)) in Stripe metadata.'),
'#default_value' => variable_get('uc_stripe_metadata_models', FALSE),
);
return $form; return $form;
} }
@ -603,6 +617,7 @@ function uc_stripe_charge($order_id, $amount, $data) {
"currency" => strtolower($order->currency), "currency" => strtolower($order->currency),
"customer" => $stripe_customer_id, "customer" => $stripe_customer_id,
"description" => t("Order #@order_id", array("@order_id" => $order_id)), "description" => t("Order #@order_id", array("@order_id" => $order_id)),
"metadata" => make_metadata($order),
"payment_method" => $stripe_payment_method_id, "payment_method" => $stripe_payment_method_id,
"payment_method_types" => ['card'], "payment_method_types" => ['card'],
"confirm" => true, "confirm" => true,
@ -1001,6 +1016,7 @@ function _uc_stripe_confirm_payment(){
$params = array( $params = array(
'payment_method' => $data['payment_method_id'], 'payment_method' => $data['payment_method_id'],
"description" => t("Order #@order_id", array("@order_id" => $order_id)), "description" => t("Order #@order_id", array("@order_id" => $order_id)),
"metadata" => make_metadata($order),
'amount' => $amount, 'amount' => $amount,
'currency' => strtolower($order->currency), 'currency' => strtolower($order->currency),
'confirmation_method' => 'manual', 'confirmation_method' => 'manual',
@ -1077,6 +1093,7 @@ function _uc_stripe_create_stripe_customer($order, $payment_method_id = NULL){
$params = array( $params = array(
'description' => "OrderID: {$order->order_id}", 'description' => "OrderID: {$order->order_id}",
"metadata" => make_metadata($order),
'email' => "$order->primary_email" 'email' => "$order->primary_email"
); );
@ -1103,6 +1120,25 @@ function _uc_stripe_create_stripe_customer($order, $payment_method_id = NULL){
} }
function make_metadata($order){
//Get item titles and models
foreach($order->products as $item){
$titles[] = $item->title;
$models[] = $item->model;
}
$metadata = array();
if (!empty($models) and variable_get('uc_stripe_metadata_models', FALSE)) {
$metadata['models'] = implode(";", $models);
}
if (!empty($titles) and variable_get('uc_stripe_metadata_titles', FALSE)) {
$metadata['titles'] = implode(";", $titles);
}
return $metadata;
}
/** /**
* *
* @param string $stripe_id * @param string $stripe_id