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_setexpresscheckout_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) # make the setExpressCheckout call api.setExpressCheckout() # we now have a token self.assertTrue(api.token)
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_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())
def test_setexpresscheckout_token_borked(self): """ensure setExpressCheckout works as expected when everything goes according to plan""" # set bork mode & reload settings ORIGINAL_OUTCOME = settings.PAYPAL_OUTCOME settings.PAYPAL_OUTCOME = 'BORK' reload(c_settings) # get the api api = PaypalExpressCheckout(checkout=self.checkout) # make the setExpressCheckout call api.setExpressCheckout() # we now have no token self.assertFalse(api.token) # set it back settings.PAYPAL_OUTCOME = ORIGINAL_OUTCOME reload(c_settings)
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)
def test_setcheckout_with_discount(self): """test the set checkout with discounts""" # add a discount d = DiscountCode() d.type = DiscountCode.PERCENTAGE d.discount = Decimal('50.00') d.code = 'TEST' d.save() self.checkout.discount = d self.checkout.save() # get the api api = PaypalExpressCheckout(checkout=self.checkout) # make the setExpressCheckout call api.setExpressCheckout() # we now have a token self.assertTrue(api.token) # remove the discount self.checkout.discount = None self.checkout.save()
def test__parse_response(self): """Ensure _parse_response fails gracefully and with some meaning""" api = PaypalExpressCheckout(checkout=self.checkout) # go for an all out fail response = api._parse_response('') # we get something meaningful back self.assertEqual({'error': 'response could not be parsed'}, response) # pass something that can be parsed qs = 'foo=a&bar=b&baz=c' response = api._parse_response(qs) self.assertEqual(response, { 'foo': 'a', 'bar': 'b', 'baz': 'c' }) # now pass the same thing with ampersands added to throw the parse off qs = '&foo=a&bar=b&baz=c&' response = api._parse_response(qs) self.assertEqual(response, { 'foo': 'a', 'bar': 'b', 'baz': 'c' })