示例#1
0
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")
示例#2
0
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")