ec_email_gift_certificate_order_failure

one of the documented procedures in this installation of the ACS
Usage:
ec_email_gift_certificate_order_failure   gift_certificate_id
What it does:
Use this to send out the "Gift Certificate Order Failure" email after it is determined that a previously inconclusive auth failed.
Defined in: /web/philip/tcl/ecommerce-email.tcl

Source code:


    
    set db [ns_db gethandle subquery]
    
    set selection [ns_db 1row $db "select g.purchased_by as user_id, u.email, g.recipient_email, g.amount, g.certificate_to, g.certificate_from, g.certificate_message
    from ec_gift_certificates g, users u
    where g.purchased_by=u.user_id
    and g.gift_certificate_id=$gift_certificate_id"]
    set_variables_after_query
    
    set system_name [ad_system_name]
    set system_url "[ec_insecure_url]"
    set customer_service_signature [ec_customer_service_signature]

    set amount_and_message_summary ""
    if { ![empty_string_p $certificate_to] } {
	append amount_and_message_summary "To:     $certificate_to\n"
    }
    append amount_and_message_summary "Amount: [ec_pretty_price $amount]\n"
    if { ![empty_string_p $certificate_from] } {
	append amount_and_message_summary "From:   $certificate_from\n"
    }
    if { ![empty_string_p $certificate_message] } {
	append amount_and_message_summary "Message:\n$certificate_message\n"
    }

    # have to get rid of ampersands in above variables because they 
    # mess up regsubs
    regsub -all "&" $system_name {\\&} system_name
    regsub -all "&" $system_url {\\&} system_url
    regsub -all "&" $recipient_email {\\&} recipient_email
    regsub -all "&" $amount_and_message_summary {\\&} amount_and_message_summary
    regsub -all "&" $customer_service_signature {\\&} customer_service_signature
    

    # Note: template #6 is defined to be the "Gift Certificate Order Failure" email
    set selection [ns_db 1row $db "select subject as email_subject, message as email_body, issue_type_list from ec_email_templates where email_template_id=6"]
    set_variables_after_query

    # and get rid of ctrl-M's in the body
    regsub -all "\r" $email_body "" email_body

    regsub -all "system_name_here" $email_body $system_name email_body
    regsub -all "system_url_here" $email_body $system_url email_body
    regsub -all "recipient_email_here" $email_body $recipient_email email_body
    regsub -all "amount_and_message_summary_here" $email_body $amount_and_message_summary email_body
    regsub -all "customer_service_signature_here" $email_body $customer_service_signature email_body

    ns_db dml $db "begin transaction"

    # create a customer service issue/interaction/action
    set user_identification_and_issue_id [ec_customer_service_simple_issue $db "" "automatic" "email" "[DoubleApos "To: $email\nFrom: [ad_parameter CustomerServiceEmailAddress ecommerce]\nSubject: $email_subject"]" "" $issue_type_list $email_body $user_id "" "f" $gift_certificate_id]

    set user_identification_id [lindex $user_identification_and_issue_id 0]
    set issue_id [lindex $user_identification_and_issue_id 1]

    # add a row to the automatic email log
    ns_db dml $db "insert into ec_automatic_email_log
    (user_identification_id, email_template_id, gift_certificate_id, date_sent)
    values
    ($user_identification_id, 6, $gift_certificate_id, sysdate)
    "

    ns_db dml $db "end transaction"

    set email_from [ec_customer_service_email_address $user_identification_id $issue_id]
   
    ec_sendmail_from_service "$email" "$email_from" "$email_subject" "$email_body"

    ns_db releasehandle $db


philg@mit.edu