def test_paymentrequestresponse_saving(self):
     """ensure that every request generates a RequestResponse"""
     # we have none
     self.assertEqual(0, RequestResponse.objects.count())
     # get the api
     api = PaypalExpressCheckout(checkout=self.checkout)
     # make the setExpressCheckout call
     api.setExpressCheckout()
     # we have one
     self.assertEqual(1, RequestResponse.objects.count())
     # make the expresscheckout payment
     api.doExpressCheckout()
     # we have two
     self.assertEqual(2, RequestResponse.objects.count())
Пример #2
0
def do_express_checkout(request):
    """calls the do_express_checkout method"""
    # get the checkout
    checkout = request.session['cccheckout']
    # if there is no token and PayerId then go no further and return to payment
    try:
        token = request.GET['token']
        payerid = request.GET['PayerID']
    except KeyError:
        return HttpResponseRedirect(reverse('cccheckout:payment'))
    # now make the API
    api = PaypalExpressCheckout(checkout=checkout,
                        token=token,
                        payerid=payerid)
    # do the express checkout
    response =  api.doExpressCheckout()
    if response:
        # mark as paid and save session
       checkout.paid = True
       checkout.save()
       request.session.save()
       # send the signal
       signals.checkout_paid.send(sender=None, request=request)
       # return the http response redirect
       try:
           url = reverse(c_settings.CCCHECKOUT_SUCCESS_URL)
       except NoReverseMatch:
           url = c_settings.CCCHECKOUT_SUCCESS_URL 
       return HttpResponseRedirect(url)
    # response was fail
    messages.error(request, api.error)
    return HttpResponseRedirect(reverse('cccheckout:payment'))
 def test_doexpresscheckout_token_working(self):
     """ensure setExpressCheckout works as expected when everything goes
     according to plan"""
     settings.PAYPAL_OUTCOME = 'PASS'
     reload(c_settings)
     # get the api
     api = PaypalExpressCheckout(
             checkout=self.checkout,
             token='asasdsadas',
             payerid='asdasdsad')
     # make the setExpressCheckout call and the return is True
     self.assertTrue(api.doExpressCheckout())
 def test_doexpresscheckout_token_borked(self):
     """ensure setExpressCheckout works as expected when everything goes
     according to plan"""
     # save the setting for later
     ORIGINAL_OUTCOME = settings.PAYPAL_OUTCOME
     settings.PAYPAL_OUTCOME = 'BORK'
     reload(c_settings)
     # make the API again, this time with details
     api = PaypalExpressCheckout(
             checkout=self.checkout,
             token='asasdsadas',
             payerid='asdasdsad')
     # make the setExpressCheckout call and the return is False 
     self.assertFalse(api.doExpressCheckout())
     # set it back
     settings.PAYPAL_OUTCOME = ORIGINAL_OUTCOME
     reload(c_settings)