def make_payment(content_object, request=None, transaction_opts={}):
    """"""
    
    trans = Transaction(content_object=content_object)
    trans.status = Transaction.PROCESSING
    trans.save()

    # Basic params, needed in all cases.
    params = {amount_name: u"%.2f" % trans.amount,
              "MerchantReference": trans.merchant_reference}

    # set up params for an interactive payment
    url_root = u"http://%s" % request.META['HTTP_HOST']
    params.update({"UrlFail": url_root + trans.get_failure_url(),
                   "UrlSuccess": url_root + trans.get_success_url()})
    
    params.update(transaction_opts)

    return begin_interactive(params)
Exemple #2
0
def make_payment(content_object, request=None, transaction_opts={}):
    """Main entry point. If we have a request we do it interactive, otherwise it's a batch/offline payment."""
    
    trans = Transaction(content_object=content_object)
    trans.status = Transaction.PROCESSING
    trans.save()

    # PxPost and PxPay have different element names.
    amount_name = "AmountInput" if request else "Amount"

    # Basic params, needed in all cases.
    params = {amount_name: u"%.2f" % trans.amount,
              "MerchantReference": trans.merchant_reference}

    if request:
        # set up params for an interactive payment
        url_root = u"http://%s" % request.META['HTTP_HOST']
        params.update({"UrlFail": url_root + trans.get_failure_url(),
                       "UrlSuccess": url_root + trans.get_success_url()})
        if getattr(content_object, "is_recurring", lambda: False)():
            assert hasattr(content_object, "set_billing_token")
            assert hasattr(content_object, "get_billing_token")
            params["EnableAddBillCard"] = "1"
    else:
        # set up for an offline/batch payment.
        params.update({"DpsBillingId": content_object.get_billing_token(),
                       "TxnId": trans.transaction_id})
    
    params.update(transaction_opts)

    if request:
        return begin_interactive(params)
    else:
        (success, result) = offline_payment(params)
        if success:
            status_updated = trans.set_status(Transaction.SUCCESSFUL)
            callback = getattr(content_object, "transaction_succeeded",
                               lambda *args: None)
        else:
            status_updated = trans.set_status(Transaction.FAILED)
            callback = getattr(content_object, "transaction_failed", 
                               lambda *args: None)
        trans.result = result
        trans.save()
        callback(trans, False, status_updated)
        return (success, trans)