Send mail when payment clears + Simple admin

weedoo - March 24, 2008 - 21:27
Project:SaleMail
Version:5.x-3.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I wanted the system to send a mail when payment is cleared and not when checkout is pressed, because I didn't know if the payment was made or not... here is my fix + a simple and basic admin

<?php
/**
* Implementation of hook_help().
*/
function salemail_help($section = 'admin/help#salemail') {
  switch (
$section) {
    case
'admin/help#salemail':
     
// Here is some help.
     
return t('The Salemail module allows you to send an email to the specified email address when a payment is cleared.');
  }
}


/**
* Implementation of hook_ec_settings().
*/
function salemail_ec_settings() {

 
$output = '';

 
$form['settings'] = array(
   
'#type' => 'fieldset',
   
'#title' => t('Main settings'),
     
'#collapsible' => FALSE,
     
'#collapsed' => FALSE,

  );
 
 
// ACTIVATED
 
$form['settings']['salemail_active'] = array(
   
'#type' => 'radios',
   
'#title' => t('Enable Salemail'),
   
'#default_value' => variable_get('salemail_active', 0),
   
'#options' => array(t('Disabled'), t('Enabled')),
   
'#description' => t("Enable or disable transaction notifications.  If enabled, the specified person will receive an email each time a payment is completed."),
  );

 
// EMAIL ADDRESS
 
$form['settings']['salemail_email'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Email'),
   
'#default_value' => variable_get('salemail_email', variable_get("site_mail", ini_get("sendmail_from"))),
   
'#size' => 20,
   
'#maxlength' => 255,
   
'#description' => t('An invoice email will be sent to this email address upon payment completion.'),
  );

  return
system_settings_form($form);
}

/**
* Implementation of hook_menu() - for salemail callback
*/
function salemail_menu($may_cache) {

 
$items = array();
  if (
$may_cache) {
   
$items[] = array(
     
'path' => 'admin/ecsettings/salemail',
     
'title' => 'Salemail',
     
'description' => t('Allow specified email address to be noticed when a payment in complete.'),
     
'callback' => 'drupal_get_form',
     
'callback arguments' => array('salemail_ec_settings'),
     
'access' => user_access('administer store'),
     
'type' => MENU_NORMAL_ITEM,
    );
  }

  return
$items;
}

/**
* Implementation of hook_ecommerceapi() - for salemail callback
*/
function salemail_ecommerceapi(&$txn, $op) {

 
//If the review screen has been submitted then send an email]
  //Note that ec4 supports post_process as an operation.
 
if ($op == 'on payment completion') {
   
   
$active = variable_get("salemail_active", 0);
    if (
$active) {
           
//Send an email  
       
$to = variable_get("salemail_email", variable_get("site_mail", ini_get("sendmail_from")));
       
ec_mail_send_mid(variable_get(MAILVAR_SALEMAIL, 0), $to, &$txn);
    }
   
  }
 
}
?>

Perhaps you might be interested in some part of it.

Thanks for the core !

AttachmentSize
salemail.txt8.76 KB
 
 

Drupal is a registered trademark of Dries Buytaert.