Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form-2.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form-2.tcl 30 Jul 2005 22:17:00 -0000 1.9 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form-2.tcl 3 Aug 2005 22:46:40 -0000 1.10 @@ -798,6 +798,26 @@ } } + + if { [db_0or1row check_transaction { + select 1 + from dotlrn_ecommerce_transactions + where order_id = :order_id + }] } { + db_dml update_transaction_check { + update dotlrn_ecommerce_transactions + set method = 'cc', + internal_account = null + where order_id = :order_id + } + } else { + db_dml save_transaction_check { + insert into dotlrn_ecommerce_transactions + (order_id, method) + values + (:order_id, 'cc') + } + } } else { # Other payment methods # Just store it Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.tcl 30 Jul 2005 22:17:00 -0000 1.16 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-one-form.tcl 3 Aug 2005 22:46:40 -0000 1.17 @@ -582,6 +582,8 @@ lappend method_options [list "Invoice" invoice] } scholarship { + # Purchasing via scholarships should only be available to + # admins by logic, but this can be set in the param lappend method_options [list "Scholarship" scholarship] } } @@ -673,14 +675,27 @@ set method check } elseif { [lsearch $payment_methods internal_account] != -1 } { set method internal_account + } elseif { [lsearch $payment_methods cash] != -1 } { + set method internal_account + } elseif { [lsearch $payment_methods invoice] != -1 } { + set method internal_account + } elseif { [lsearch $payment_methods scholarship] != -1 } { + set method internal_account } } -on_submit { set form [rp_getform] set submit_url [ad_return_url] + regsub -nocase checkout-one-form $submit_url checkout-one-form-2 submit_url + if { $method == "scholarship" } { + # Go to page where one can select scholarships to purchase from + ad_returnredirect [export_vars -base checkout-scholarships { user_id {return_url $submit_url} }] + ad_script_abort + } + ad_returnredirect $submit_url ad_script_abort } Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.adp 3 Aug 2005 22:46:40 -0000 1.1 @@ -0,0 +1,31 @@ + + + + +
+

+ +

You have not granted any scholarship amount

+ + +

The scholarship granted does not cover the order amount

+
+ +

+ The scholarship granted exceeds the order amount.
+ The balance shall be granted to the user as a gift certificate. +

+
+ +

The scholarship covers the order amount

+
+
+ +

+ Back + + Continue Purchase via Other Method + + + Continue Checkout + Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.tcl 3 Aug 2005 22:46:40 -0000 1.1 @@ -0,0 +1,87 @@ +# packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-2.tcl + +ad_page_contract { + + Process scholarships + + @author Roel Canicula (roelmc@pldtdsl.net) + @creation-date 2005-08-02 + @arch-tag: f3382efc-34f6-4816-9fb6-3b9508b416df + @cvs-id $Id: checkout-scholarships-2.tcl,v 1.1 2005/08/03 22:46:40 roelc Exp $ +} { + {fund_id:integer,multiple {}} + return_url:notnull + user_id:integer,notnull +} -properties { +} -validate { +} -errors { +} + +set form [rp_getform] + +template::multirow create scholarships fund_id title description amount_left amount_granted valid_p message + +set total_amount 0 + +foreach one_fund_id $fund_id { + if { [db_0or1row scholarship { + select sf.* + from scholarship_fundi sf, + cr_items ci + where sf.revision_id = ci.live_revision + and sf.fund_id = :one_fund_id + }] } { + + if { [empty_string_p [set amount_to_grant [ns_set get $form "amount.${one_fund_id}"]]] } { + # Empty + template::multirow append scholarships $one_fund_id $title $description $amount 0 0 "Please enter an amount" + } else { + if { ! [string is double $amount_to_grant] } { + # Invalid value + template::multirow append scholarships $one_fund_id $title $description $amount 0 0 "You entered an invalid amount" + } else { + if { $amount < $amount_to_grant } { + template::multirow append scholarships $one_fund_id $title $description $amount 0 0 "You entered an amount greater than what the fund can accommodate" + + } else { + # Valid + template::multirow append scholarships $one_fund_id $title $description [expr $amount - $amount_to_grant] $amount_to_grant 1 "Granted" + set total_amount [expr $total_amount + $amount_to_grant] + } + } + } + + } +} + +template::list::create \ + -name scholarships \ + -multirow scholarships \ + -elements { + title { label Title } + description { label Description } + amount_left { label "Amount in Fund" } + amount_granted { label "Amount Granted" } + message { label "Comments" } + } + +# Assume there's a valid order_id +set user_session_id [ec_get_user_session_id] +set order_id [db_string get_order_id " + select order_id + from ec_orders + where user_session_id = :user_session_id + and order_state = 'in_basket'" -default ""] + +set price_shipping_gift_certificate_and_tax [ec_price_shipping_gift_certificate_and_tax_in_an_order $order_id] +set order_total_price_pre_gift_certificate [expr [lindex $price_shipping_gift_certificate_and_tax 0] + [lindex $price_shipping_gift_certificate_and_tax 1]] + +if { $total_amount >= $order_total_price_pre_gift_certificate } { + # Scholarship covers order + set next_url $return_url +} else { + set next_url [export_vars -base checkout-one-form] +} + +set back_url [export_vars -base checkout-scholarships { user_id return_url }] +set amountsub [expr $total_amount - $order_total_price_pre_gift_certificate] \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-3.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-3.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-3.tcl 3 Aug 2005 22:46:40 -0000 1.1 @@ -0,0 +1,17 @@ +# packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships-3.tcl + +ad_page_contract { + + Grant scholarship as gift certificate + + @author Roel Canicula (roelmc@pldtdsl.net) + @creation-date 2005-08-02 + @arch-tag: 035f8a0e-e0b2-4981-aa40-7d381e3eaadb + @cvs-id $Id: checkout-scholarships-3.tcl,v 1.1 2005/08/03 22:46:40 roelc Exp $ +} { + +} -properties { +} -validate { +} -errors { +} + Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.adp 3 Aug 2005 22:46:40 -0000 1.1 @@ -0,0 +1,3 @@ + + + Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.tcl 3 Aug 2005 22:46:40 -0000 1.1 @@ -0,0 +1,43 @@ +# packages/dotlrn-ecommerce/www/ecommerce/checkout-scholarships.tcl + +ad_page_contract { + + Purchase via scholarships + + @author Roel Canicula (roelmc@pldtdsl.net) + @creation-date 2005-08-02 + @arch-tag: 04002975-c572-48b8-8003-fa134bcc82d4 + @cvs-id $Id: checkout-scholarships.tcl,v 1.1 2005/08/03 22:46:40 roelc Exp $ +} { + return_url:notnull + user_id:integer,notnull +} -properties { +} -validate { +} -errors { +} + +template::list::create \ + -key fund_id \ + -name scholarships \ + -multirow scholarships \ + -bulk_actions {Purchase checkout-scholarships-2 Purchase} \ + -bulk_action_export_vars { user_id return_url } \ + -elements { + title { label "Title" } + description { label "Description" } + amount { label "Amount in Fund" } + grant_amount { + label "Amount to Grant" + display_template { + + } + } + } + +db_multirow scholarships scholarships { + select sf.* + from scholarship_fundi sf, + cr_items ci + where sf.revision_id = ci.live_revision +} { +} \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order-postgresql.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order-postgresql.xql 23 Jun 2005 12:28:21 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order-postgresql.xql 3 Aug 2005 22:46:40 -0000 1.2 @@ -47,9 +47,9 @@ insert into ec_financial_transactions - (transaction_id, order_id, transaction_amount, transaction_type, inserted_date) + (creditcard_id, transaction_id, order_id, transaction_amount, transaction_type, inserted_date) values - (:transaction_id, :order_id, :transaction_amount, 'charge', current_timestamp) + (:creditcard_id, :transaction_id, :order_id, :transaction_amount, 'charge', current_timestamp) Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order.tcl 6 Jul 2005 05:03:23 -0000 1.5 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/finalize-order.tcl 3 Aug 2005 22:46:40 -0000 1.6 @@ -4,9 +4,9 @@ (1) put this order into the 'confirmed' state (2) try to authorize the user's credit card info and either - (a) redirect them to a thank you page, or - (b) redirect them to a "please fix your credit card info" - page + (a) redirect them to a thank you page, or + (b) redirect them to a "please fix your credit card info" + page @author @creation-date @@ -249,6 +249,8 @@ if {$hard_goods_cost > 0} { + ns_log notice "DEBUG:: hard" + # The order contains hard goods that come at a cost. if {$soft_goods_cost > 0} { @@ -257,7 +259,7 @@ # cost. if {$applied_certificate_amount >= [expr $soft_goods_cost + $soft_goods_tax]} { - + # The applied certificates cover the cost of the soft # goods. @@ -286,11 +288,13 @@ set transaction_id [db_nextval ec_transaction_id_sequence] set transaction_amount [expr $hard_goods_cost + $hard_goods_tax + $hard_goods_shipping + $hard_goods_shipping_tax + $order_shipping + $order_shipping_tax - \ [expr $applied_certificate_amount - $soft_goods_cost - $soft_goods_tax]] - db_dml insert_financial_transaction " + if { ![empty_string_p $creditcard_id] } { + db_dml insert_financial_transaction " insert into ec_financial_transactions - (transaction_id, order_id, transaction_amount, transaction_type, inserted_date) + (creditcard_id, transaction_id, order_id, transaction_amount, transaction_type, inserted_date) values - (:transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + (:creditcard_id, :transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + } array set response [ec_creditcard_authorization $order_id $transaction_id] set result $response(response_code) @@ -355,11 +359,13 @@ set transaction_amount [expr $soft_goods_cost + $soft_goods_tax - \ [expr $applied_certificate_amount - [expr $hard_goods_cost + $hard_goods_tax + $hard_goods_shipping + $hard_goods_shipping_tax + \ $order_shipping + $order_shipping_tax]]] - db_dml insert_financial_transaction " + if { ![empty_string_p $creditcard_id] } { + db_dml insert_financial_transaction " insert into ec_financial_transactions - (transaction_id, order_id, transaction_amount, transaction_type, inserted_date) + (creditcard_id, transaction_id, order_id, transaction_amount, transaction_type, inserted_date) values - (:transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + (:creditcard_id, :transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + } array set response [ec_creditcard_authorization $order_id $transaction_id] set result $response(response_code) @@ -459,11 +465,13 @@ set transaction_id [db_nextval ec_transaction_id_sequence] set transaction_amount [expr $soft_goods_cost + $soft_goods_tax - $applied_certificate_amount] - db_dml insert_financial_transaction " + if { ![empty_string_p $creditcard_id] } { + db_dml insert_financial_transaction " insert into ec_financial_transactions - (transaction_id, order_id, transaction_amount, transaction_type, inserted_date) + (creditcard_id, transaction_id, order_id, transaction_amount, transaction_type, inserted_date) values - (:transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + (:creditcard_id, :transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + } array set response [ec_creditcard_authorization $order_id $transaction_id] set result $response(response_code) @@ -486,11 +494,13 @@ set transaction_amount [expr $hard_goods_cost + $hard_goods_tax + $hard_goods_shipping + $hard_goods_shipping_tax + $order_shipping + $order_shipping_tax + \ $soft_goods_cost + $soft_goods_tax - $transaction_amount] set transaction_id [db_nextval ec_transaction_id_sequence] - db_dml insert_financial_transaction " + if { ![empty_string_p $creditcard_id] } { + db_dml insert_financial_transaction " insert into ec_financial_transactions - (transaction_id, order_id, transaction_amount, transaction_type, inserted_date) + (creditcard_id, transaction_id, order_id, transaction_amount, transaction_type, inserted_date) values - (:transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + (:creditcard_id, :transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + } array set response [ec_creditcard_authorization $order_id $transaction_id] set result $response(response_code) @@ -640,11 +650,13 @@ set transaction_id [db_nextval ec_transaction_id_sequence] set transaction_amount [expr $hard_goods_cost + $hard_goods_tax + $hard_goods_shipping + $hard_goods_shipping_tax + $order_shipping + $order_shipping_tax - \ [expr $applied_certificate_amount - $soft_goods_cost - $soft_goods_tax]] - db_dml insert_financial_transaction " + if { ![empty_string_p $creditcard_id] } { + db_dml insert_financial_transaction " insert into ec_financial_transactions - (transaction_id, order_id, transaction_amount, transaction_type, inserted_date) + (creditcard_id, transaction_id, order_id, transaction_amount, transaction_type, inserted_date) values - (:transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + (:creditcard_id, :transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + } array set response [ec_creditcard_authorization $order_id $transaction_id] set result $response(response_code) @@ -740,60 +752,70 @@ ec_update_state_to_authorized $order_id ad_returnredirect $return_url - + ad_script_abort } else { # The certificates only partially cover the cost of the # soft goods. Create a new financial transaction set transaction_id [db_nextval ec_transaction_id_sequence] set transaction_amount [expr $soft_goods_cost + $soft_goods_tax - $applied_certificate_amount] - db_dml insert_financial_transaction " + + if { ![empty_string_p $creditcard_id] } { + db_dml insert_financial_transaction " insert into ec_financial_transactions - (transaction_id, order_id, transaction_amount, transaction_type, inserted_date) + (creditcard_id, transaction_id, order_id, transaction_amount, transaction_type, inserted_date) values - (:transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" + (:creditcard_id, :transaction_id, :order_id, :transaction_amount, 'charge', sysdate)" - array set response [ec_creditcard_authorization $order_id $transaction_id] - set result $response(response_code) - set transaction_id $response(transaction_id) - if { [string equal $result "authorized"] } { - ec_email_new_order $order_id + array set response [ec_creditcard_authorization $order_id $transaction_id] + set result $response(response_code) + set transaction_id $response(transaction_id) + if { [string equal $result "authorized"] } { + ec_email_new_order $order_id + + # Change the order state from 'confirmed' to + # 'authorized'. - # Change the order state from 'confirmed' to - # 'authorized'. + ec_update_state_to_authorized $order_id - ec_update_state_to_authorized $order_id + # Record the date & time of the authorization and + # schedule the transaction for settlement. - # Record the date & time of the authorization and - # schedule the transaction for settlement. - - db_dml schedule_settlement " + db_dml schedule_settlement " update ec_financial_transactions set authorized_date = sysdate, to_be_captured_p = 't', to_be_captured_date = sysdate where transaction_id = :transaction_id" - # Mark the transaction now, rather than waiting for - # the scheduled procedures to mark the transaction. + # Mark the transaction now, rather than waiting for + # the scheduled procedures to mark the transaction. - array set response [ec_creditcard_marking $transaction_id] - set mark_result $response(response_code) - set pgw_transaction_id $response(transaction_id) - if { [string equal $mark_result "invalid_input"]} { - set problem_details " + array set response [ec_creditcard_marking $transaction_id] + set mark_result $response(response_code) + set pgw_transaction_id $response(transaction_id) + if { [string equal $mark_result "invalid_input"]} { + set problem_details " When trying to mark the transaction for the items that don't require shipment (transaction $transaction_id) at [ad_conn url], the following result occurred: $mark_result" - db_dml record_marking_problem " + db_dml record_marking_problem " insert into ec_problems_log (problem_id, problem_date, problem_details, order_id) values (ec_problem_id_sequence.nextval, sysdate, :problem_details, :order_id)" - } elseif {[string equal $mark_result "success"]} { - db_dml update_marked_date " + } elseif {[string equal $mark_result "success"]} { + db_dml update_marked_date " update ec_financial_transactions set marked_date = sysdate where transaction_id = :pgw_transaction_id" + } + ad_returnredirect $return_url + ad_script_abort } + } else { + # Gift cert covers cost, no cc transaction needed, + # authorize immediately + ec_update_state_to_authorized $order_id ad_returnredirect $return_url + ad_script_abort } if {[string equal $result "failed_authorization"] || [string equal $result "no_recommendation"] } {