lib/mpower/checkout/onsite_invoice.rb in mpower-1.0.8 vs lib/mpower/checkout/onsite_invoice.rb in mpower-1.0.9

- old
+ new

@@ -14,20 +14,12 @@ :confirm_token => confirm_token } result = http_json_request(MPower::Setup.opr_charge_base_url,payload) - case result["response_code"] - when "00" - @status = result["invoice_data"]["status"] - @customer = result["invoice_data"]["customer"] - @items = result["invoice_data"]["invoice"]["items"] - @taxes = result["invoice_data"]["invoice"]["taxes"] - @description = result["invoice_data"]["invoice"]["description"] - @custom_data = result["invoice_data"]["custom_data"] - @total_amount = result["invoice_data"]["invoice"]["total_amount"] - @receipt_url = result["invoice_data"]["receipt_url"] + if result["response_code"] == "00" + rebuild_invoice(result["invoice_data"]) @response_code = result["response_code"] @response_text = result["response_text"] true else @response_code = result["response_code"] @@ -35,54 +27,19 @@ false end end def create(account_alias) - invoice_data = { - :invoice => { - :items => @items, - :taxes => @taxes, - :total_amount => @total_amount, - :description => description - }, - :store => { - :name => @store.name, - :tagline => @store.tagline, - :postal_address => @store.postal_address, - :phone => @store.phone_number, - :logo_url => @store.logo_url, - :website_url => @store.website_url - }, - :custom_data => @custom_data, - :actions => { - :cancel_url => @cancel_url, - :return_url => @return_url - } - } payload = { - :invoice_data => invoice_data, + :invoice_data => build_invoice_payload, :opr_data => { :account_alias => account_alias } } result = http_json_request(MPower::Setup.opr_base_url,payload) - case result["response_code"] - when "00" - @token = result["token"] - @response_text = result["response_text"] - @response_code = result["response_code"] - @invoice_token = result["invoice_token"] - @status = MPower::SUCCESS - true - else - @response_text = result["response_text"] - @response_code = result["response_code"] - @invoice_url = nil - @status = MPower::FAIL - false - end + create_response(result) end end end end \ No newline at end of file