def do_credit_guard_trx(params): provider_url = BILLING_INFO['url'] params.update(BILLING_INFO) params.update({ 'may_be_duplicate' : "0", 'currency' : "ILS", 'request_id' : get_unique_id(), 'terminal_number' : BILLING_INFO["terminal_number_no_CVV"] }) c = Context(params) t = get_template("credit_guard_transaction.xml") rendered_payload = t.render(c) logging.info("CREDIT GUARD TRX - payload: %s" % rendered_payload) payload = str("user=%s&password=%s&int_in=%s" % (BILLING_INFO["username"], BILLING_INFO["password"], urlquote_plus(rendered_payload))) result = safe_fetch(provider_url, method="POST", payload=payload, deadline=50) logging.info("CREDIT GUARD TRX - response: %s" % result.content if result else "fetch failed") if not result: return None else: result = result.content if params["language"] == "Heb": result = result.decode("utf-8").encode("hebrew") xml = minidom.parseString(result) return xml
def get_transaction_id(lang_code, mpi_data): data = ALL_QUERY_FIELDS.copy() # unique_id = get_unique_id() # # save passenger in the session # request.session[unique_id] = passenger data.update(mpi_data) data.update({ "terminal": BILLING_INFO["terminal_number"], "uniqueID": get_unique_id(), # this must be passed, although currently not used "amount": 0, "currency": "ILS", "transactionType": "Debit", "creditType": "RegularCredit", "transactionCode": "Phone", "validationType": "Verify", "langID": (lang_code or settings.LANGUAGE_CODE).upper(), "timestamp": datetime.now().replace(microsecond=0).isoformat() #"2011-10-22T15:44:53" #default_tz_now().isoformat() }) # encode data without using urlencode data = "&".join(["%s=%s" % i for i in data.items()]) logging.info(data) notify = not has_caller("run_billing_service_test") res = safe_fetch(BILLING_INFO["transaction_url"], method='POST', payload=data, deadline=50, notify=notify) if not res: return None elif res.content.startswith("--"): logging.error("No transaction ID received: %s" % res.content) return None else: return res.content
def setup_flat_rate_rules(request): if request.method == 'POST': form = FlatRateRuleSetupForm(request.POST) if form.is_valid(): logging.info("Uploading flat rate pricing rules...") country = form.cleaned_data["country"] data = form.cleaned_data["csv"].encode('utf-8') memcache_key = get_unique_id() memcache.set(memcache_key, data) logging.info("Read data") flat_rate_async(country.id, memcache_key) return HttpResponse("OK") else: form = FlatRateRuleSetupForm() return render_to_response("flat_rate_rules_setup.html", locals(), context_instance=RequestContext(request))
def do_J5(token, amount, card_expiration, billing_transaction, callback_args=None): billing_transaction.change_status(BillingStatus.PENDING, BillingStatus.PROCESSING) lang_code = get_language_code_for_credit_guard(billing_transaction.order.language_code) params = { 'card_id' : token, 'card_expiration' : card_expiration, 'total' : amount, 'billing_transaction_id' : billing_transaction.id, 'request_id' : get_unique_id(), 'validation' : "Verify", 'language' : lang_code } if settings.DEV: # bypass authorization if running on test server params.update({"auth_number": "0000000"}) result = do_credit_guard_trx(params) if not result: billing_transaction.comments = "CreditGuard transaction failed" billing_transaction.change_status(BillingStatus.PROCESSING, BillingStatus.FAILED) #calls save billing_failed_signal.send(sender="do_J5", obj=billing_transaction) return HttpResponse("OK") status_code = get_text_from_element(result, "status") billing_transaction.provider_status = status_code auth_number = get_text_from_element(result, "authNumber") transaction_id = get_text_from_element(result, "tranId") billing_transaction.transaction_id = transaction_id if int(status_code): # failed message = get_text_from_element(result, "message") billing_transaction.comments = message billing_transaction.change_status(BillingStatus.PROCESSING, BillingStatus.FAILED) #calls save billing_failed_signal.send(sender="do_J5", obj=billing_transaction) else: billing_transaction.auth_number = auth_number billing_transaction.change_status(BillingStatus.PROCESSING, BillingStatus.APPROVED) #calls save if billing_transaction.order.change_status(old_status=PENDING, new_status=APPROVED): billing_approved_signal.send(sender="do_J5", obj=billing_transaction, callback_args=callback_args) billing_transaction.charge() # setup J4 else: # order is not PENDING (it can be marked as IGNORED when submitting to algorithm) billing_transaction.comments = _("We are sorry but booking for the selected time is closed, please choose a different time.<br/>Your billing information was saved, you will not be asked to provide it again.") billing_transaction.change_status(BillingStatus.PROCESSING, BillingStatus.FAILED) #calls save logging.info("J5 FAILED: order status is %s (expected PENDING)" % billing_transaction.order.get_status_label()) return HttpResponse("OK")
def do_J4(token, amount, card_expiration, billing_transaction): if billing_transaction.status == BillingStatus.CANCELLED or billing_transaction.order.status in [IGNORED, CANCELLED, FAILED]: return HttpResponse("Cancelled") billing_transaction.change_status(BillingStatus.APPROVED, BillingStatus.PROCESSING) lang_code = get_language_code_for_credit_guard(billing_transaction.order.language_code) params = { 'card_id' : token, 'card_expiration' : card_expiration, 'total' : amount, 'billing_transaction_id' : billing_transaction.id, 'request_id' : get_unique_id(), 'validation' : "AutoComm", 'auth_number' : billing_transaction.auth_number, 'language' : lang_code } result = do_credit_guard_trx(params) if not result: billing_transaction.comments = "CreditGuard transaction failed" billing_transaction.change_status(BillingStatus.PROCESSING, BillingStatus.FAILED) #calls save billing_failed_signal.send(sender="do_J4", obj=billing_transaction) return HttpResponse("OK") status_code = get_text_from_element(result, "status") billing_transaction.provider_status = status_code auth_number = get_text_from_element(result, "authNumber") transaction_id = get_text_from_element(result, "tranId") billing_transaction.transaction_id = transaction_id if int(status_code): message = get_text_from_element(result, "message") billing_transaction.comments = message billing_transaction.change_status(BillingStatus.PROCESSING, BillingStatus.FAILED) #calls save billing_failed_signal.send(sender="do_J4", obj=billing_transaction) else: billing_transaction.auth_number = auth_number billing_transaction.change_status(BillingStatus.PROCESSING, BillingStatus.CHARGED) #calls save billing_transaction.order.change_status(new_status=CHARGED) billing_charged_signal.send(sender="do_J4", obj=billing_transaction) return HttpResponse("OK")
def run_maintenance_task(request): base_name = 'maintenance-task' name = request.GET.get("name", base_name) task = taskqueue.Task(url=reverse(maintenance_task), name=name) q = taskqueue.Queue('maintenance') response = HttpResponse("Task Added") try: q.add(task) except TombstonedTaskError: response = HttpResponseRedirect( url_with_querystring(reverse(run_maintenance_task), name="%s-%s" % (base_name, get_unique_id()))) except TaskAlreadyExistsError: response = HttpResponse("Task not added: TaskAlreadyExistsError") except DuplicateTaskNameError: response = HttpResponse("Task not added: DuplicateTaskNameError") return response
def get_transaction_id(lang_code, mpi_data): data = ALL_QUERY_FIELDS.copy() # unique_id = get_unique_id() # # save passenger in the session # request.session[unique_id] = passenger data.update(mpi_data) data.update({ "terminal": BILLING_INFO["terminal_number"], "uniqueID": get_unique_id(), # this must be passed, although currently not used "amount": 0, "currency": "ILS", "transactionType": "Debit", "creditType": "RegularCredit", "transactionCode": "Phone", "validationType": "Verify", "langID": (lang_code or settings.LANGUAGE_CODE).upper(), "timestamp": datetime.now().replace(microsecond=0).isoformat( ) #"2011-10-22T15:44:53" #default_tz_now().isoformat() }) # encode data without using urlencode data = "&".join(["%s=%s" % i for i in data.items()]) logging.info(data) notify = not has_caller("run_billing_service_test") res = safe_fetch(BILLING_INFO["transaction_url"], method='POST', payload=data, deadline=50, notify=notify) if not res: return None elif res.content.startswith("--"): logging.error("No transaction ID received: %s" % res.content) return None else: return res.content