Index: openacs-4/packages/ecommerce/www/admin/orders/items-return-2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/orders/items-return-2.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/orders/items-return-2.adp 18 Aug 2008 09:53:32 -0000 1.1 @@ -0,0 +1,18 @@ + + @title;noquote@ + @context;noquote@ +

@title@

+ +
+ @export_form_vars_html;noquote@ + + + + + @items_to_print;noquote@ +
ItemPrice to RefundShipping to Refund
+

Base shipping charge to refund: + + (out of @base_shipping_html@)

+
+
Index: openacs-4/packages/ecommerce/www/admin/orders/items-return-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/orders/items-return-2.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/ecommerce/www/admin/orders/items-return-2.tcl 9 Aug 2008 10:33:13 -0000 1.10 +++ openacs-4/packages/ecommerce/www/admin/orders/items-return-2.tcl 18 Aug 2008 09:53:32 -0000 1.11 @@ -26,7 +26,6 @@ } # The customer service rep must be logged on - set customer_service_rep [ad_get_user_id] if {$customer_service_rep == 0} { set return_url "[ad_conn url]?[export_entire_form_as_url_vars]" @@ -35,7 +34,6 @@ } # Make sure they haven't already inserted this refund - if { [db_string get_refund_count " select count(*) from ec_refunds @@ -51,7 +49,6 @@ # They must have either checked "All items" and none of the rest, or # at least one of the rest and not "All items". They also need to have # shipment_date filled in - if { [info exists all_items_p] && [info exists item_id] } { incr exception_count append exception_text "
  • Please either check off \"All items\" or check off some of the items, but not both." @@ -66,16 +63,10 @@ ad_script_abort } -append doc_body " - [ad_admin_header "Specify refund amount"] +set title "Specify refund amount" +set context [list [list index "Orders / Shipments / Refunds"] $title] -

    Specify refund amount

    - - [ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index" "Orders"] [list "one?[export_url_vars order_id]" "One"] "Mark Items Returned"] -
    " - -set shipping_refund_percent [ad_parameter -package_id [ec_id] ShippingRefundPercent ecommerce] - +set shipping_refund_percent [parameter -package_id [ec_id] -parameter ShippingRefundPercent] if { ![info exists all_items_p] } { set item_id_list $item_id set sql [db_map all_items_select] @@ -88,54 +79,30 @@ # added to the order, thereby causing the query for all items to # return one more item), only the items that they confirm here should # be recorded as part of this return. - if { [info exists all_items_p] } { set item_id_list [list] } set items_to_print "" db_foreach get_return_item_list $sql { - if { [info exists all_items_p] } { - lappend item_id_list $item_id + lappend item_id_list $item_id } - append items_to_print " - - $product_name + append items_to_print "$product_name (out of [ec_pretty_pure_price $price_charged]) - (out of [ec_pretty_pure_price $shipping_charged]) - " + (out of [ec_pretty_pure_price $shipping_charged])" } -append doc_body " -
    - [export_form_vars refund_id order_id item_id_list received_back_datetime reason_for_return] -
    - - - - - $items_to_print -
    ItemPrice to RefundShipping to Refund
    " +set export_form_vars_html [export_form_vars refund_id order_id item_id_list received_back_datetime reason_for_return] # Although only one refund may be done on an item, multiple refunds # may be done on the base shipping cost, so show shipping_charged - # shipping_refunded. - -set base_shipping [db_string base_shipping_select " - select nvl(shipping_charged,0) - nvl(shipping_refunded,0) +set base_shipping [db_string base_shipping_select "select nvl(shipping_charged,0) - nvl(shipping_refunded,0) from ec_orders where order_id=:order_id"] -append doc_body " -

    Base shipping charge to refund: - - (out of [ec_pretty_pure_price $base_shipping])

    -
    +set base_shipping_to_refund [format "%0.2f" [expr $base_shipping * $shipping_refund_percent]] -
    - - [ad_admin_footer]" - -doc_return 200 text/html $doc_body +set base_shipping_html [ec_pretty_pure_price $base_shipping] Index: openacs-4/packages/ecommerce/www/admin/orders/items-return-3.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/orders/items-return-3.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/orders/items-return-3.adp 18 Aug 2008 09:53:32 -0000 1.1 @@ -0,0 +1,44 @@ + + @title;noquote@ + @context;noquote@ +

    @title@

    + + + @export_form_vars_html;noquote@ + +

    Total refund amount: @total_amount_to_refund@ (price: @total_price_to_refund_html@, shipping: @total_shipping_to_refund_html@, tax: @total_tax_to_refund_html@)

    +
      +
    • @certificate_amount_to_reinstate_html@ will be reinstated in gift certificates.
    • +
    • @cash_amount_to_refund_html@ will be refunded to the customer's credit card.
    • +
    + + +

    Please re-enter the credit card number of the card used for this order:

    + + + + + + + + + + + + + + + + +
    @creditcard_widget_html;noquote@
    Ending in:xxxxxxxxxxxx@creditcard_last_four@
    Expires:@card_expiration@
    Billing address:@billing_street@
    + @billing_city@, @billing_state@ @billing_zip@
    + @billing_country@
    +
    + @export_form_vars_2_html;noquote@ + +@export_form_vars_cc_type_html;noquote@ +@export_form_vars_last_4_html;noquote@ +
    + +
    + Index: openacs-4/packages/ecommerce/www/admin/orders/items-return-3.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/orders/items-return-3.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/ecommerce/www/admin/orders/items-return-3.tcl 9 Aug 2008 10:33:13 -0000 1.6 +++ openacs-4/packages/ecommerce/www/admin/orders/items-return-3.tcl 18 Aug 2008 09:53:32 -0000 1.7 @@ -178,70 +178,27 @@ set billing_country "" } -append doc_body " - [ad_admin_header "Refund Totals"] +set title "Refund Totals" +set context [list [list index "Orders / Shipments / Refunds"] $title] -

    Refund Totals

    +set export_form_vars_html "[export_entire_form] [export_form_vars cash_amount_to_refund certificate_amount_to_reinstate]" - [ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index" "Orders"] [list "one?[export_url_vars order_id]" "One"] "Refund Totals"] +set total_amount_to_refund_html [ec_pretty_pure_price $total_amount_to_refund] +set total_price_to_refund_html [ec_pretty_pure_price $total_price_to_refund] +set total_shipping_to_refund_html [ec_pretty_pure_price $total_shipping_to_refund] +set total_tax_to_refund_html [ec_pretty_pure_price $total_tax_to_refund] -
    -
    - [export_entire_form] - [export_form_vars cash_amount_to_refund certificate_amount_to_reinstate] -
    -

    Total refund amount: [ec_pretty_pure_price $total_amount_to_refund] (price: [ec_pretty_pure_price $total_price_to_refund], shipping: [ec_pretty_pure_price $total_shipping_to_refund], tax: [ec_pretty_pure_price $total_tax_to_refund])

    -
      -
    • [ec_pretty_pure_price $certificate_amount_to_reinstate] will be reinstated in gift certificates.
      -
    • [ec_pretty_pure_price $cash_amount_to_refund] will be refunded to the customer's credit card.
      -
    " +set certificate_amount_to_reinstate_html [ec_pretty_pure_price $certificate_amount_to_reinstate] +set cash_amount_to_refund_html [ec_pretty_pure_price $cash_amount_to_refund] # Request the credit card number to be re-entered if it is no longer # on file, yet there is money to refund. - -if { [empty_string_p $creditcard_number] && $cash_amount_to_refund > 0 } { - append doc_body " -

    Please re-enter the credit card number of the card used for this order:

    - - - - -
    - - - - - - - - - - - - - - - -
    - [ec_creditcard_widget $creditcard_type disabled]
    Ending in:xxxxxxxxxxxx$creditcard_last_four
    Expires:$card_expiration
    Billing address:$billing_street
    - $billing_city, $billing_state $billing_zip
    - $billing_country
    -
    " +set request_creditcard [expr { [empty_string_p $creditcard_number] && $cash_amount_to_refund > 0 } ] +if { $request_credit_card } { + set creditcard_widget_html [ec_creditcard_widget $creditcard_type disabled] } else { - append doc_body " - [export_form_vars creditcard_id creditcard_number]" + set export_form_vars_2_html [export_form_vars creditcard_id creditcard_number] } -append doc_body " - [export_form_vars creditcard_type]" -append doc_body " -
    -
    - [export_form_vars creditcard_last_four] -
    - -
    -
    -[ad_admin_footer]" - -doc_return 200 text/html $doc_body +set export_form_vars_cc_type_html [export_form_vars creditcard_type] +set export_form_vars_last_4_html [export_form_vars creditcard_last_four] Index: openacs-4/packages/ecommerce/www/admin/orders/items-return-4.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/orders/items-return-4.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/orders/items-return-4.adp 18 Aug 2008 09:53:32 -0000 1.1 @@ -0,0 +1,7 @@ + + @title;noquote@ + @context;noquote@ +

    @title@

    + + @results_explanation;noquote@ +

    Back to order @order_id@

    Index: openacs-4/packages/ecommerce/www/admin/orders/items-return-4.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/orders/items-return-4.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/packages/ecommerce/www/admin/orders/items-return-4.tcl 16 Aug 2008 12:56:18 -0000 1.8 +++ openacs-4/packages/ecommerce/www/admin/orders/items-return-4.tcl 18 Aug 2008 09:53:32 -0000 1.9 @@ -51,20 +51,14 @@ set customer_service_rep [ad_get_user_id] # Get rid of spaces and dashes - regsub -all -- "-" $creditcard_number "" creditcard_number regsub -all -- " " $creditcard_number "" creditcard_number -# Error checking: unless the credit card number is in the database or -# if the total amount to refund is $0.00 the credit card number needs -# to be re-entered. - set exception_count 0 set exception_text "" # Make sure that this refund hasn't been processed before. (Double # click prevention.) - if { [db_string get_refund_id_check " select count(*) from ec_refunds @@ -74,78 +68,65 @@ return } +# Error checking: unless the credit card number is in the database or +# if the total amount to refund is $0.00 the credit card number needs +# to be re-entered. + # Check if money needs to be refunded and if the credit card number is # still on file. - if { [expr $cash_amount_to_refund] > 0 } { # Make sure that all the credit card information is there. - if {![info exists creditcard_id] || ([info exists creditcard_id] && [empty_string_p $creditcard_id])} { - incr exception_count - append exception_text " -
  • - You forgot to provide the creditcard that was used to purchase the items to be returned. -
  • " + incr exception_count + append exception_text "
  • The refund requires using the creditcard that was used to purchase the items to be returned.
  • " } if {![info exists creditcard_type] || ([info exists creditcard_type] && [empty_string_p $creditcard_type])} { - incr exception_count - append exception_text " -
  • - You forgot to provide type of the creditcard that was used to purchase the items to be returned. -
  • " + incr exception_count + append exception_text "
  • The refund requires using the creditcard that was used to purchase the items to be returned.
  • " } if {![info exists creditcard_number] || ([info exists creditcard_number] && [empty_string_p $creditcard_number])} { - incr exception_count - append exception_text " -
  • - You forgot to provide card number of the creditcard that was used to purchase the items to be returned. -
  • " + incr exception_count + append exception_text "
  • The refund requires using the creditcard that was used to purchase the items to be returned.
  • " } if {![info exists creditcard_last_four] || ([info exists creditcard_last_four] && [empty_string_p $creditcard_last_four])} { - incr exception_count - append exception_text " -
  • - You forgot to provide card number of the creditcard that was used to purchase the items to be returned. -
  • " + incr exception_count + append exception_text "
  • The refund requires using the creditcard that was used to purchase the items to be returned.
  • " } - # The credit card has been re-entered. Check that the number is - # correct. + # The credit card has been re-entered. Check that the number is correct. if { [regexp {[^0-9]} $creditcard_number] } { - incr exception_count - append exception_text "
  • The credit card number contains invalid characters.
  • " + incr exception_count + append exception_text "
  • The credit card number contains invalid characters.
  • " } if {[string length $creditcard_number] > 4 && ![string match *$creditcard_last_four $creditcard_number]} { - incr exception_count - append exception_text "
  • The last for digits of the credit card number do not match the digits on file.
    + incr exception_count + append exception_text "
  • The last for digits of the credit card number do not match the digits on file.
    Make sure to enter the card number of the credit card that was used to pay for the order.
  • " } if {[info exists creditcard_type]} { - # Make sure the credit card number matches the credit card - # type # and that the number has the right number of digits. + # Make sure the credit card number matches the credit card + # type # and that the number has the right number of digits. - set additional_count_and_text [ec_creditcard_precheck $creditcard_number $creditcard_type] + set additional_count_and_text [ec_creditcard_precheck $creditcard_number $creditcard_type] - set exception_count [expr $exception_count + [lindex $additional_count_and_text 0]] - append exception_text [lindex $additional_count_and_text 1] + set exception_count [expr $exception_count + [lindex $additional_count_and_text 0]] + append exception_text [lindex $additional_count_and_text 1] } } if { $exception_count > 0 } { ad_return_complaint $exception_count $exception_text return } - # Done with error checking # 2. Put records into ec_refunds, individual items, the order, and # ec_financial_transactions - db_dml update_cc_number_incctable " update ec_creditcards set creditcard_number=:creditcard_number @@ -161,7 +142,6 @@ # This is annoying (doing these selects before each insert), # but that's how it goes because we don't want to refund more # tax than was actually paid even if the tax rates changed - set price_bind_variable $price_to_refund($item_id) set shipping_bind_variable $shipping_to_refund($item_id) @@ -170,9 +150,8 @@ from ec_items where item_id=:item_id" -# torben diagnostics note: following calls for ec_tax, but ec_tax does not exist. set price_tax_to_refund [ec_min $price_tax_charged [db_string get_tax_charged " - select ec_tax(:price_bind_variable,0,:order_id) + select ec_tax(:price_bind_variable,0,:order_id) from dual"]] set shipping_tax_to_refund [ec_min $shipping_tax_charged [db_string get_tax_shipping_to_refund " @@ -224,55 +203,52 @@ order by transaction_id limit 1"]} { - # Create a single refund financial transaction. + # Create a single refund financial transaction. + set refund_transaction_id [db_nextval ec_transaction_id_sequence] - set refund_transaction_id [db_nextval ec_transaction_id_sequence] + # Authorize.net is an example of a payment gateway that requires + # the original transaction to be settled before it accepts refunds + # for the transaction. Unfortunately there is no automated way to + # find out if the transaction has been settled. - # Authorize.net is an example of a payment gateway that requires - # the original transaction to be settled before it accepts refunds - # for the transaction. Unfortunately there is no automated way to - # find out if the transaction has been settled. + # However, transactions are settled once a day (by all gateways) + # thus it is safe to assume that transactions are settled within + # 24 hours after they have been marked for settlement. - # However, transactions are settled once a day (by all gateways) - # thus it is safe to assume that transactions are settled within - # 24 hours after they have been marked for settlement. - - # make sure date does not choke on decimal times - regsub -- {\.[0-9]+$} $marked_date "" marked_date - set 24hr [expr 24 * 60 * 60] - set time_since_marking [expr [clock seconds] - [clock scan $marked_date]] - if { $time_since_marking > $24hr } { - set scheduled_hour [clock format [clock scan $marked_date] -format "%Y-%m-%d %H:%M:%S" -gmt true] - } else { - - # It is too early to perform the refund now. First the - # original transaction needs to be settled by the payment - # gateway. Schedule the refund for 24 hours after the original - # transaction was marked for settlement. The procedure - # ec_unrefunded_transactions will then perform the shortly - # after the scheduled hour. - - set scheduled_hour [clock format [expr [clock scan $marked_date] + $24hr] -format "%Y-%m-%d %H:%M:%S" -gmt true] - } -# torben diagnostics note: following insert does not make it into ec_financial_transactions. - db_dml insert_refund_transaction " + # make sure date does not choke on decimal times + regsub -- {\.[0-9]+$} $marked_date "" marked_date + set 24hr [expr 24 * 60 * 60] + set time_since_marking [expr [clock seconds] - [clock scan $marked_date]] + if { $time_since_marking > $24hr } { + set scheduled_hour [clock format [clock scan $marked_date] -format "%Y-%m-%d %H:%M:%S" -gmt true] + } else { + + # It is too early to perform the refund now. First the + # original transaction needs to be settled by the payment + # gateway. Schedule the refund for 24 hours after the original + # transaction was marked for settlement. The procedure + # ec_unrefunded_transactions will then perform the shortly + # after the scheduled hour. + + set scheduled_hour [clock format [expr [clock scan $marked_date] + $24hr] -format "%Y-%m-%d %H:%M:%S" -gmt true] + } + + db_dml insert_refund_transaction " insert into ec_financial_transactions (transaction_id, refunded_transaction_id, order_id, refund_id, creditcard_id, transaction_amount, transaction_type, inserted_date, to_be_captured_date) values (:refund_transaction_id, :charged_transaction_id, :order_id, :refund_id, :creditcard_id, :refund_amount, 'refund', sysdate, :scheduled_hour)" - # Record the amount that was refunded of the charge transaction. - - db_dml record_refunded_amount " + # Record the amount that was refunded of the charge transaction. + db_dml record_refunded_amount " update ec_financial_transactions set refunded_amount = coalesce(refunded_amount, 0) + :refund_amount where transaction_id = :charged_transaction_id" - # Set the amount to be refunded to zero to indicate that - # no more refunds are needed. - - set refund_amount 0 - } elseif {[db_0or1row select_unrefunded_charge_transaction " + # Set the amount to be refunded to zero to indicate that + # no more refunds are needed. + set refund_amount 0 + } elseif { [db_0or1row select_unrefunded_charge_transaction " select transaction_id as charged_transaction_id, (transaction_amount - coalesce(refunded_amount, 0)) as unrefunded_amount, marked_date from ec_financial_transactions where order_id = :order_id @@ -281,136 +257,130 @@ and marked_date is not null and failed_p = 'f' order by (transaction_amount - coalesce(refunded_amount, 0)) desc - limit 1"]} { - - if { $unrefunded_amount >= $refund_amount } { + limit 1"] } { + + if { $unrefunded_amount >= $refund_amount } { - # Create refund financial transaction for the refund - # amount. + # Create refund financial transaction for the refund amount. + set refund_transaction_id [db_nextval ec_transaction_id_sequence] - set refund_transaction_id [db_nextval ec_transaction_id_sequence] + # Authorize.net is an example of a payment gateway that requires + # the original transaction to be settled before it accepts refunds + # for the transaction. Unfortunately there is no automated way to + # find out if the transaction has been settled. - # Authorize.net is an example of a payment gateway that requires - # the original transaction to be settled before it accepts refunds - # for the transaction. Unfortunately there is no automated way to - # find out if the transaction has been settled. + # However, transactions are settled once a day (by all gateways) + # thus it is safe to assume that transactions are settled within + # 24 hours after they have been marked for settlement. - # However, transactions are settled once a day (by all gateways) - # thus it is safe to assume that transactions are settled within - # 24 hours after they have been marked for settlement. + set 24hr [expr 24 * 60 * 60] + set time_since_marking [expr [clock seconds] - [clock scan $marked_date]] + if { $time_since_marking > $24hr } { + set scheduled_hour [clock format [clock scan $marked_date] -format "%Y-%m-%d %H:%M:%S" -gmt true] + } else { + + # It is too early to perform the refund now. First the + # original transaction needs to be settled by the payment + # gateway. Schedule the refund for 24 hours after the original + # transaction was marked for settlement. The procedure + # ec_unrefunded_transactions will then perform the shortly + # after the scheduled hour. + set scheduled_hour [clock format [expr [clock scan $marked_date] + $24hr] -format "%Y-%m-%d %H:%M:%S" -gmt true] + } - set 24hr [expr 24 * 60 * 60] - set time_since_marking [expr [clock seconds] - [clock scan $marked_date]] - if { $time_since_marking > $24hr } { - set scheduled_hour [clock format [clock scan $marked_date] -format "%Y-%m-%d %H:%M:%S" -gmt true] - } else { - - # It is too early to perform the refund now. First the - # original transaction needs to be settled by the payment - # gateway. Schedule the refund for 24 hours after the original - # transaction was marked for settlement. The procedure - # ec_unrefunded_transactions will then perform the shortly - # after the scheduled hour. - - set scheduled_hour [clock format [expr [clock scan $marked_date] + $24hr] -format "%Y-%m-%d %H:%M:%S" -gmt true] - } - - db_dml insert_refund_transaction " + db_dml insert_refund_transaction " insert into ec_financial_transactions (transaction_id, refunded_transaction_id, order_id, refund_id, creditcard_id, transaction_amount, transaction_type, inserted_date, to_be_captured_date) values (:refund_transaction_id, :charged_transaction_id, :order_id, :refund_id, :creditcard_id, :refund_amount, 'refund', current_timestamp, :scheduled_hour)" - # Record the amount that was refunded of the charge transaction. + # Record the amount that was refunded of the charge transaction. - db_dml record_refunded_amount " + db_dml record_refunded_amount " update ec_financial_transactions set refunded_amount = coalesce(refunded_amount, 0) + :refund_amount where transaction_id = :charged_transaction_id" - # Set the amount to be refunded to zero to indicate that - # no more refunds are needed. + # Set the amount to be refunded to zero to indicate that + # no more refunds are needed. - set refund_amount 0 - } else { + set refund_amount 0 + } else { + + # Create refund financial transaction for the unrefunded + # amount of the charge transaction. - # Create refund financial transaction for the unrefunded - # amount of the charge transaction. + set refund_transaction_id [db_nextval ec_transaction_id_sequence] - set refund_transaction_id [db_nextval ec_transaction_id_sequence] + # Authorize.net is an example of a payment gateway that requires + # the original transaction to be settled before it accepts refunds + # for the transaction. Unfortunately there is no automated way to + # find out if the transaction has been settled. - # Authorize.net is an example of a payment gateway that requires - # the original transaction to be settled before it accepts refunds - # for the transaction. Unfortunately there is no automated way to - # find out if the transaction has been settled. + # However, transactions are settled once a day (by all gateways) + # thus it is safe to assume that transactions are settled within + # 24 hours after they have been marked for settlement. - # However, transactions are settled once a day (by all gateways) - # thus it is safe to assume that transactions are settled within - # 24 hours after they have been marked for settlement. + set 24hr [expr 24 * 60 * 60] + set time_since_marking [expr [clock seconds] - [clock scan $marked_date]] + if { $time_since_marking > $24hr } { + set scheduled_hour [clock format [clock scan $marked_date] -format "%Y-%m-%d %H:%M:%S" -gmt true] + } else { - set 24hr [expr 24 * 60 * 60] - set time_since_marking [expr [clock seconds] - [clock scan $marked_date]] - if { $time_since_marking > $24hr } { - set scheduled_hour [clock format [clock scan $marked_date] -format "%Y-%m-%d %H:%M:%S" -gmt true] - } else { + # It is too early to perform the refund now. First the + # original transaction needs to be settled by the payment + # gateway. Schedule the refund for 24 hours after the original + # transaction was marked for settlement. The procedure + # ec_unrefunded_transactions will then perform the shortly + # after the scheduled hour. + set scheduled_hour [clock format [expr [clock scan $marked_date] + $24hr] -format "%Y-%m-%d %H:%M:%S" -gmt true] + } - # It is too early to perform the refund now. First the - # original transaction needs to be settled by the payment - # gateway. Schedule the refund for 24 hours after the original - # transaction was marked for settlement. The procedure - # ec_unrefunded_transactions will then perform the shortly - # after the scheduled hour. - - set scheduled_hour [clock format [expr [clock scan $marked_date] + $24hr] -format "%Y-%m-%d %H:%M:%S" -gmt true] - } - - db_dml insert_unrefund_transaction " + db_dml insert_unrefund_transaction " insert into ec_financial_transactions (transaction_id, refunded_transaction_id, order_id, refund_id, creditcard_id, transaction_amount, transaction_type, inserted_date, to_be_captured_date) values (:refund_transaction_id, :charged_transaction_id, :order_id, :refund_id, :creditcard_id, :unrefunded_amount, 'refund', sysdate, :scheduled_hour)" - # Record the amount that was refunded of the charge transaction. + # Record the amount that was refunded of the charge transaction. - db_dml record_unrefunded_amount " + db_dml record_unrefunded_amount " update ec_financial_transactions set refunded_amount = coalesce(refunded_amount, 0) + :unrefunded_amount where transaction_id = :charged_transaction_id" - # Subtract the amount of the new refund transaction - # from the total amount to be refunded. + # Subtract the amount of the new refund transaction + # from the total amount to be refunded. - set refund_amount [expr $refund_amount - $unrefunded_amount] - } + set refund_amount [expr $refund_amount - $unrefunded_amount] + } } } # 3. do the gift certificate reinstatements (start with ones that # expire furthest in to future) - if { $certificate_amount_to_reinstate > 0 } { set certificate_amount_used [db_string get_gc_amount_used " select ec_order_gift_cert_amount(:order_id) from dual"] if { $certificate_amount_used < $certificate_amount_to_reinstate } { - set errorstring " + set errorstring " We were unable to reinstate the customer's gift certificate balance because the amount to be reinstated was larger than the original amount used. This shouldn't have happened unless there was a programming error or unless the database was incorrectly updated manually. This transaction was aborted (refund_id $refund_id), i.e. no refund was given to the customer." - db_dml record_reinstate_problem " + db_dml record_reinstate_problem " insert into ec_problems_log (problem_id, problem_date, problem_details, order_id) values (ec_problem_id_sequence.nextval, sysdate, :errorstring, :order_id)" - ad_return_error " -

    Gift Certificate Error" "We were unable to reinstate the customer's gift certificate balance because the amount - to be reinstated was larger than the original amount used. This shouldn't have happened unless there was a programming error - or unless the database was incorrectly updated manually.

    + ad_return_error "Gift Certificate Error" "

    We were unable to reinstate the customer's gift certificate balance because the amount + to be reinstated was larger than the original amount used. This shouldn't have happened unless there was a programming error + or unless the database was incorrectly updated manually.

    This transaction has been aborted, i.e. no refund has been given to the customer. This has been logged in the problems log.

    " - return + return } # Go through and reinstate certificates in order; it's not so bad @@ -424,15 +394,15 @@ group by u.gift_certificate_id, c.expires order by expires desc, gift_certificate_id desc" { - if {$certificate_amount_to_reinstate > 0} { - db_dml reinstate_gift_certificate " + if {$certificate_amount_to_reinstate > 0} { + db_dml reinstate_gift_certificate " insert into ec_gift_certificate_usage (gift_certificate_id, order_id, amount_reinstated, reinstated_date) values (:gift_certificate_id, :order_id, least(to_number(:certificate_amount_to_reinstate), to_number(:reinstateable_amount)) , sysdate)" - set $certificate_amount_to_reinstate [expr $certificate_amount_to_reinstate - \ - [expr ($certificate_amount_to_reinstate > $reinstateable_amount) ? $reinstateable_amount : $certificate_amount_to_reinstate]] - } + set $certificate_amount_to_reinstate [expr $certificate_amount_to_reinstate - \ + [expr ($certificate_amount_to_reinstate > $reinstateable_amount) ? $reinstateable_amount : $certificate_amount_to_reinstate]] + } } } @@ -450,70 +420,64 @@ and failed_p = 'f'" { set now [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S" -gmt true] - if { [dt_interval_check $to_be_captured_date $now] > 0} { + if { [dt_interval_check $to_be_captured_date $now] > 0} { - array set response [ec_creditcard_return $transaction_id] - set refund_status $response(response_code) - set pgw_transaction_id $response(transaction_id) - if { $refund_status == "failure" || $refund_status == "invalid_input" } { - set errorstring "Refund transaction $transaction_id for [ec_pretty_pure_price $transaction_amount] of refund $refund_id at [ad_conn url], resulted in: $refund_status" - db_dml insert_cc_refund_problem " + array set response [ec_creditcard_return $transaction_id] + set refund_status $response(response_code) + set pgw_transaction_id $response(transaction_id) + if { $refund_status == "failure" || $refund_status == "invalid_input" } { + set errorstring "Refund transaction $transaction_id for [ec_pretty_pure_price $transaction_amount] of refund $refund_id at [ad_conn url], resulted in: $refund_status" + db_dml insert_cc_refund_problem " insert into ec_problems_log (problem_id, problem_date, problem_details, order_id) values (ec_problem_id_sequence.nextval, sysdate, :errorstring, :order_id)" - append results_explanation "

    Refund transaction $transaction_id for [ec_pretty_pure_price $transaction_amount] did not occur. + append results_explanation "

    Refund transaction $transaction_id for [ec_pretty_pure_price $transaction_amount] did not occur. We have made a record of this in the problems log so that the situation can be corrected manually.

    " - } elseif { $refund_status == "inconclusive" } { + } elseif { $refund_status == "inconclusive" } { - # Set the to_be_captured_date so that the scheduled - # procedure ec_unrefunded_transactions will retry the - # transaction. + # Set the to_be_captured_date so that the scheduled + # procedure ec_unrefunded_transactions will retry the + # transaction. - append results_explanation "

    The results of refund transaction $transaction_id for [ec_pretty_pure_price $transaction_amount] were inconclusive + append results_explanation "

    The results of refund transaction $transaction_id for [ec_pretty_pure_price $transaction_amount] were inconclusive (perhaps due to a communications failure between us and the payment gateway). A program will keep trying to complete this refund transaction and the problems log will be updated if it the refund transaction cannot be completed.

    " - } else { + } else { - # Refund successful + # Refund successful - db_dml update_ft_set_success " + db_dml update_ft_set_success " update ec_financial_transactions set refunded_date=sysdate where transaction_id=:pgw_transaction_id" append results_explanation "

    Refund transaction $pgw_transaction_id for [ec_pretty_pure_price $transaction_amount] is complete!

    ";# - } - } else { + } + } else { + + # It is too early to perform the refund now. First the + # original transaction needs to be settled by the payment + # gateway. - # It is too early to perform the refund now. First the - # original transaction needs to be settled by the payment - # gateway. - - append results_explanation "

    Refund transaction $transaction_id for [ec_pretty_pure_price $transaction_amount] is scheduled for a later time. + append results_explanation "

    Refund transaction $transaction_id for [ec_pretty_pure_price $transaction_amount] is scheduled for a later time. Refunds can not be processed before the transaction charging the credit card has been completed by the gateway. Transactions are completed with 24 hours after marking. Therefore the refund transaction has been scheduled for $to_be_captured_date

    " - } + } } if_no_rows { - set page_title "No credit card refund needed." - set results_explanation "No credit card refund was necessary because the entire amount was refunded to the gift certificates the customer used when purchasing the order." + set page_title "No credit card refund needed." + set results_explanation "No credit card refund was necessary because the entire amount was refunded to the gift certificates the customer used when purchasing the order." } } else { set page_title "No credit card refund needed." set results_explanation "No credit card refund was necessary because the entire amount was refunded to the gift certificates the customer used when purchasing the order." } -append doc_body " - [ad_admin_header $page_title] +if { [info exists page_title } { + set title $page_title +} else { + set title "Refund Complete" +} +set context [list [list index "Orders / Shipments / Refunds"] $title] -

    $page_title

    - - [ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index" "Orders"] [list "one?[export_url_vars order_id]" "One"] "Refund Complete"] -
    -
    - $results_explanation - Back to Order $order_id -
    - [ad_admin_footer]" - -doc_return 200 text/html $doc_body +set order_url "one?[export_url_vars order_id]" Index: openacs-4/packages/ecommerce/www/admin/orders/items-return.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/orders/items-return.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/orders/items-return.adp 18 Aug 2008 09:53:32 -0000 1.1 @@ -0,0 +1,14 @@ + + @title;noquote@ + @context;noquote@ +

    @title@

    + +
    +@export_form_vars_html;noquote@ +

    Date received back: @date_received_back_html;noquote@

    +

    Please check off the items that were received back:

    + @items_for_return_html;noquote@ +

    Reason for return (if known):

    + +
    +
    Index: openacs-4/packages/ecommerce/www/admin/orders/items-return.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/orders/items-return.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/ecommerce/www/admin/orders/items-return.tcl 9 Mar 2004 00:59:50 -0000 1.5 +++ openacs-4/packages/ecommerce/www/admin/orders/items-return.tcl 18 Aug 2008 09:53:32 -0000 1.6 @@ -15,48 +15,22 @@ ad_require_permission [ad_conn package_id] admin # In case they reload this page after completing the refund process: - if { [db_string doubleclick_select " select count(*) from ec_items_refundable where order_id=:order_id"] == 0 } { ad_return_complaint 1 " -
  • This order doesn't contain any refundable items; perhaps you are using an old form. Return to the order." +
  • This order doesn't contain any refundable items; perhaps you are using an old form. Return to the order.
  • " return } -doc_body_append " - [ad_admin_header "Mark Items Returned"] +set title "Mark Items Returned" +set context [list [list index "Orders / Shipments / Refunds"] $title] -

    Mark Items Returned

    - - [ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index" "Orders"] [list "one?order_id=$order_id" "One Order"] "Mark Items Returned"] -
    " - # Generate the new refund_id to prevent reusing this form. - set refund_id [db_nextval refund_id_sequence] -doc_body_append " -
    - [export_form_vars order_id refund_id] - -
    -

    Date received back: [ad_dateentrywidget received_back_date] [ec_timeentrywidget received_back_time]

    - -

    Please check off the items that were received back:

    -
    - [ec_items_for_fulfillment_or_return $order_id "f"] -
    - -

    Reason for return (if known):

    -
    - -
    -
    - -
    -
    - - [ad_admin_footer]" +set export_form_vars_html [export_form_vars order_id refund_id] +set date_received_back_html "[ad_dateentrywidget received_back_date] [ec_timeentrywidget received_back_time]" +set items_for_return_html "[ec_items_for_fulfillment_or_return $order_id "f"]"