Пример #1
0
def google_checkout(context):
    '''inclusion tag, fetches the redirect url from google checkout
    to complete the checkout process'''
    require(context, *split('return_url'))
    test_mode = getattr(settings, 'MERCHANT_TEST_MODE', True)
    context['test_mode'] = test_mode
    if test_mode:
        image_url = BUTTON_SANDBOX_URL
    else:
        image_url = BUTTON_URL

    dest_url = get_checkout_url(context)

    return {'image_url': image_url, 'dest_url': dest_url}
Пример #2
0
def google_checkout(context):
    '''inclusion tag, fetches the redirect url from google checkout
    to complete the checkout process'''
    require(context, *split('return_url'))
    test_mode = getattr(settings, 'MERCHANT_TEST_MODE', True)
    context['test_mode'] = test_mode
    if test_mode:
        image_url = BUTTON_SANDBOX_URL
    else:
        image_url = BUTTON_URL
    
    dest_url = get_checkout_url(context)
    
    return {'image_url': image_url, 
            'dest_url': dest_url}
Пример #3
0
def paypal_buy(context):
    """render paypal form to buy item"""
    require(context, *split("notify_url return_url cancel_return amount item_name invoice"))

    params = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": context["amount"],
        "item_name": context["item_name"],
        "invoice": context["invoice"],
        "notify_url": context["notify_url"],
        "return_url": context["return_url"],
        "cancel_return": context["cancel_return"],
    }

    form = PayPalPaymentsForm(initial=params)
    return {"form": form, "test_mode": getattr(settings, "MERCHANT_TEST_MODE", True)}
Пример #4
0
def google_checkout_form(context):
    '''inclusion tag to render a form that will be submitted to google
    checkout API'''
    require(context, *split('return_url item_name amount'))
    test_mode = getattr(settings, 'MERCHANT_TEST_MODE', True)
    context['test_mode'] = test_mode
    if test_mode:
        url = F_SANDBOX_URL
        image_url = BUTTON_SANDBOX_URL
    else:
        url = F_URL
        image_url = BUTTON_URL
    
    cart_xml = _build_xml_shopping_cart(context)
    cart = base64.b64encode(cart_xml)
    signature = base64.b64encode(get_hmac_signature(cart_xml))
    
    return {'url': url, 
            'image_url': image_url, 
            'cart': cart,
            'signature': signature,
            'form_submit': True,
            }
Пример #5
0
def google_checkout_form(context):
    '''inclusion tag to render a form that will be submitted to google
    checkout API'''
    require(context, *split('return_url item_name amount'))
    test_mode = getattr(settings, 'MERCHANT_TEST_MODE', True)
    context['test_mode'] = test_mode
    if test_mode:
        url = F_SANDBOX_URL
        image_url = BUTTON_SANDBOX_URL
    else:
        url = F_URL
        image_url = BUTTON_URL

    cart_xml = _build_xml_shopping_cart(context)
    cart = base64.b64encode(cart_xml)
    signature = base64.b64encode(get_hmac_signature(cart_xml))

    return {
        'url': url,
        'image_url': image_url,
        'cart': cart,
        'signature': signature,
        'form_submit': True,
    }
Пример #6
0
def rbs_buy(context):
    require(context, *('cart_id amount').split())
    test_mode = getattr(settings, "MERCHANT_TEST_MODE", True)
    secret_key = getattr(settings, "RBS_MD5_SECRET_KEY", None)
    
    form_data = {}
    if test_mode:
        rbs_hosted_url = getattr(settings, "RBS_HOSTED_URL_TEST", "https://select-test.wp3.rbsworldpay.com/wcc/purchase")
        form_data['instId'] = settings.RBS_INSTALLTION_ID_TEST
    else:
        rbs_hosted_url = getattr(settings, "RBS_HOSTED_URL_LIVE", "https://secure.wp3.rbsworldpay.com/wcc/purchase")
        form_data['instId'] = settings.RBS_INSTALLTION_ID_LIVE

    form_data['cartId'] = context['cart_id']
    form_data['amount'] = context["amount"]
    form_data['desc'] = context.get('description', '')
    form_data['currency'] = context.get('currency', 'USD')

    is_recurring = context.get('is_recurring', False)
    if is_recurring:
        billing_interval_unit_map = {
            'day': 1,
            'week': 2,
            'month': 3,
            'year': 4,
        }
        
        form_data['futurePayType'] = 'regular'
        form_data['option'] = 0
        # input number_of_payments is inlucding first month
        # The first payment cannot happen on the day the agreement is set up. 
        # If you want an immediate payment then you can include a standard 
        # payment in the submission to RBS WorldPay.
        form_data['noOfPayments'] = context.get('number_of_payments', 11)
        form_data['intervalUnit'] = billing_interval_unit_map[context.get('billing_interval_unit', 'month').lower()]
        form_data['intervalMult'] = context.get('billing_interval_multiplier', 1)
        if (form_data['intervalUnit'] == 1 and form_data['intervalMult'] < 14) or \
           (form_data['intervalUnit'] == 2 and form_data['intervalMult'] < 2):
            raise TypeError('Minimum billing interval has to be atleast 2 weeks.')
        # same as billing interval unit
        # so that the recurring billing will start after the specified billing innterval
        # as the first interval payment is processed using normal purchase
        form_data['startDelayUnit'] = form_data['intervalUnit']
        # same as billing interval multiplier
        form_data['startDelayMult'] = form_data['intervalMult']
        form_data['normalAmount'] = context.get('recurring_amount', form_data['amount'])
    
    if secret_key:
        md5 = hashlib.md5()
        form_data['signatureFields'] = 'instId:amount:cartId'
        md5.update('%s:%s:%s:%s' % (secret_key, form_data['instId'], form_data['amount'], form_data['cartId']))
        form_data['signature'] = md5.hexdigest()
    
    form_data['testMode'] = 100 if test_mode else 0
    
    form = RBSHostedPaymentForm(initial=form_data)
    
    return {
        'form': form, 
        'rbs_hosted_url': rbs_hosted_url,
    }