def post(self): first_name = self.request.get('first_name') last_name = self.request.get('last_name') card = CreditCard( number = self.request.get('cc'), month = self.request.get('month'), year = "20"+self.request.get('year'), first_name = first_name, last_name = last_name, code = '' ) name = first_name + " " + last_name gateway = AimGateway(auth_net_login_id, auth_net_trans_key) gateway.use_test_mode = False gateway.use_test_url = False if "KLUG" in last_name: gateway.use_test_mode = True amount = float(int(random.random()*2000))/100 dollar_amount = '$%.2f' % amount response = gateway.sale(amount, card) d = Donation(amount=amount, transaction_id=response.trans_id, status=response.status_strings[response.status], status_code=response.status, name=name) d.put() self.response.out.write(json.dumps({"trans_id": response.trans_id, "amount": amount, "dollar_amount": dollar_amount, "status": response.status_strings[response.status], "status_code": response.status, "message": response.message}))
def process_payment_form(request): if request.POST: BillingForm = BillingInformationForm(request.POST) PersonalForm = PersonalInformationForm(request.POST) if BillingForm.is_valid(): #TODO (Klein): Do you want to save the CreditCard Object into the database? card = CreditCard( number = BillingForm.cleaned_data['card_number'], month = BillingForm.cleaned_data['expiration_month'], year = BillingForm.cleaned_data['expiration_year'], first_name = BillingForm.cleaned_data['first_name'], last_name = BillingForm.cleaned_data['last_name'], code = BillingForm.cleaned_data['security_code'] ) #TODO (Klein): Need to glue this Address Object into current site address = Address( first_name = PersonalForm.cleaned_data['first_name'], last_name = PersonalForm.cleaned_data['last_name'], company = PersonalForm.cleaned_data['company'], address = PersonalForm.cleaned_data['address'], city = PersonalForm.cleaned_data['city'], state_province = PersonalForm.cleaned_data['state'], country = PersonalForm.cleaned_data['country'], zipcode = PersonalForm.cleaned_data['zipcode'], phone = PersonalForm.cleaned_data['phone'], ) #TODO (Klein): Need to glue this Customer Object into current site customer = Customer( cust_id = '1234', email = 'CUSTOMER EMAIL', ip = '255.255.255.255', billing_address = address, shipping_address = address ) # Creating a gateway model and turning on debugging for testing purposes gateway = AimGateway('93T7v7AV6fr5', '3647Q9NA8qVHgdh9') gateway.use_test_mode = True gateway.use_test_url = True # use gateway.authorize() for an "authorize only" transaction # TODO (Klein): Change "1.00" to whatever the client charges for subscriptions response = gateway.sale(1.00, card, customer=customer) if response.status == response.APPROVED: # this is where you store data from the response object into # your models. The response.trans_id would be used to capture, # void, or credit the sale later. return HttpResponseRedirect('/order_success/') else: status = "%s - %s" % (response.status_strings[response.status], response.message) BillingForm._errors[forms.forms.NON_FIELD_ERRORS] = BillingForm.error_class([status]) else: billinginfo = BillingInformationForm() personalinfo = PersonalInformationForm() return render_to_response('orderform.html', {'billinginfo': billinginfo, 'personalinfo': personalinfo}, context_instance=RequestContext(request))
def run_authnet_trans(amt, card_info, cust_info=None, address=None, trans_id=None): # use gateway.authorize() for an "authorize only" transaction # ensures all transactions done on local servers or the dev server are in test mode if MODE == 'live': gateway = AimGateway('3r34zx5KELcc', '29wm596EuWHG72PB') gateway.use_test_mode = False else: gateway = AimGateway('8waT6w553B9A', '4PaadH8578MbC42T') gateway.use_test_url = True # gateway.use_test_mode = True # number, month, year, first_name, last_name, code card = CreditCard(**card_info) if not trans_id: if cust_info: address = Address(**address) customer = AuthCustomer(**cust_info) customer.billing_address = address customer.shipping_address = address response = gateway.sale(str(amt), card, customer=customer) else: response = gateway.sale(str(amt), card) else: response = gateway.credit(str(trans_id), str(amt), card) if response.status == response.APPROVED: # this is where you store data from the response object into # your models. The response.trans_id would be used to capture, # void, or credit the sale later. success = True status = "Authorize Request: %s</br>Transaction %s = %s: %s" % ( gateway.get_last_request().url, response.trans_id, response.status_strings[response.status], response.message) else: success = False status = "%s - %s" % (response.status_strings[response.status], response.message) #form._errors[forms.forms.NON_FIELD_ERRORS] = form.error_class([status]) return { 'success': success, 'status': status, 'trans_id': response.trans_id }
def post(self): first_name = self.request.get('first_name') last_name = self.request.get('last_name') card = CreditCard(number=self.request.get('cc'), month=self.request.get('month'), year="20" + self.request.get('year'), first_name=first_name, last_name=last_name, code='') name = first_name + " " + last_name gateway = AimGateway(auth_net_login_id, auth_net_trans_key) gateway.use_test_mode = False gateway.use_test_url = False if "KLUG" in last_name: gateway.use_test_mode = True amount = float(int(random.random() * 2000)) / 100 dollar_amount = '$%.2f' % amount response = gateway.sale(amount, card) d = Donation(amount=amount, transaction_id=response.trans_id, status=response.status_strings[response.status], status_code=response.status, name=name) d.put() self.response.out.write( simplejson.dumps({ "trans_id": response.trans_id, "amount": amount, "dollar_amount": dollar_amount, "status": response.status_strings[response.status], "status_code": response.status, "message": response.message }))
def run_authnet_trans(amt, card_info, cust_info=None, address=None, trans_id=None): # use gateway.authorize() for an "authorize only" transaction # ensures all transactions done on local servers or the dev server are in test mode if MODE == 'live': gateway = AimGateway('3r34zx5KELcc', '29wm596EuWHG72PB') gateway.use_test_mode = False else: gateway = AimGateway('8waT6w553B9A', '4PaadH8578MbC42T') gateway.use_test_url = True # gateway.use_test_mode = True # number, month, year, first_name, last_name, code card = CreditCard(**card_info) if not trans_id: if cust_info: address = Address(**address) customer = AuthCustomer(**cust_info) customer.billing_address = address customer.shipping_address = address response = gateway.sale(str(amt), card, customer=customer) else: response = gateway.sale(str(amt), card) else: response = gateway.credit(str(trans_id), str(amt), card) if response.status == response.APPROVED: # this is where you store data from the response object into # your models. The response.trans_id would be used to capture, # void, or credit the sale later. success = True status = "Authorize Request: %s</br>Transaction %s = %s: %s" % (gateway.get_last_request().url,response.trans_id, response.status_strings[response.status], response.message) else: success = False status = "%s - %s" % (response.status_strings[response.status], response.message) #form._errors[forms.forms.NON_FIELD_ERRORS] = form.error_class([status]) return {'success': success, 'status': status, 'trans_id': response.trans_id}
city = 'Fakeville', state_province = 'TX', country = 'US', postal_code = '12345', phone = '(555) 555-5555' ) customer = Customer( cust_id = '1234', email = '*****@*****.**', ip = '255.255.255.255', billing_address = address, shipping_address = address ) gateway = AimGateway('6mZxu88KF89', '4J89zqLr5Te9t9JN') gateway.use_test_mode = True gateway.use_test_url = True response = gateway.sale(1.00, card, customer=customer) if response.status == response.APPROVED: for key, value in response.gateway_data.iteritems(): print "%s = %s" % (key, value) else: sys.exit("%s %s" % (response.status_strings[response.status], response.message)) print "Transaction %s = %s (%d): %s" % (response.trans_id, response.status_strings[response.status], response.status, response.message)