def test_requestresponse_saving_in_charge_create(self): """Request respone objects are saving when invoking charge_create""" self.assertEqual(0, RequestResponse.objects.count()) settings.STRIPE_OUTCOME = 'PASS' reload(c_settings) # make an API api = StripeAPI( checkout=self.checkout, api_key='testkey') # our params params = { 'amount': 1000, 'currency': 'usd', 'card': 'stripeToken', 'description': 'test'} # make the call api.charge_create(**params) # now we have a request response object self.assertEqual(1, RequestResponse.objects.count())
def card(request): # get the checout checkout = request.session['cccheckout'] if request.method == 'POST': try: stripeToken = request.POST['stripeToken'] except KeyError: messages.error(request, 'You must enable JavaScript to pay with your card') return HttpResponseRedirect(reverse('stripe:card')) # make the api api = StripeAPI( checkout=checkout, api_key=c_settings.STRIPE[c_settings.STRIPE_MODE]['PRIVATE_KEY']) # make the params try: description = checkout.customer.email except AttributeError: description = checkout params = { 'amount': int(checkout.total_price() * 100), 'currency': 'usd', 'card': stripeToken, 'description': description} # make the api call response = api.charge_create(**params) # if the response was paid set the checkout to paid checkout.paid = response['paid'] checkout.save() if checkout.paid: # return the http response redirect try: url = reverse(c_settings.CCCHECKOUT_SUCCESS_URL) except NoReverseMatch: url = c_settings.CCCHECKOUT_SUCCESS_URL return HttpResponseRedirect(url) # not paid, add a messge messages.error(request, 'Your payment could not be taken, please try again') return render_to_response('cccheckout/payments/stripe/card.html', {}, context_instance=RequestContext(request))