def add_customer_profile(self): """Add the customer profile on payment gateway """ if self.id and (not self.customer_profile_id): # check if this user already has a customer profile, # if so, no need to create a new one. cp_id_list = RecurringPayment.objects.filter(user=self.user).exclude( customer_profile_id='' ).values_list('customer_profile_id', flat=True) if cp_id_list: self.customer_profile_id = cp_id_list[0] self.save() else: # create a customer profile on payment gateway cp = CIMCustomerProfile() d = {'email': self.user.email, 'customer_id': str(self.id)} success, response_d = cp.create(**d) print success, response_d if success: self.customer_profile_id = response_d['customer_profile_id'] self.save() else: if response_d["message_code"] == 'E00039': p = re.compile('A duplicate record with ID (\d+) already exists.', re.I) match = p.search(response_d['message_text']) if match: self.customer_profile_id = match.group(1) self.save()
def add_customer_profile(self): """Add the customer profile on payment gateway """ if self.id and (not self.customer_profile_id): # check if this user already has a customer profile, # if so, no need to create a new one. cp_id_list = RecurringPayment.objects.filter( user=self.user).exclude(customer_profile_id='').values_list( 'customer_profile_id', flat=True) if cp_id_list: self.customer_profile_id = cp_id_list[0] self.save() else: # create a customer profile on payment gateway cp = CIMCustomerProfile() d = {'email': self.user.email, 'customer_id': str(self.id)} success, response_d = cp.create(**d) print success, response_d if success: self.customer_profile_id = response_d[ 'customer_profile_id'] self.save() else: if response_d["message_code"] == 'E00039': p = re.compile( 'A duplicate record with ID (\d+) already exists.', re.I) match = p.search(response_d['message_text']) if match: self.customer_profile_id = match.group(1) self.save()
def manage_payment_info( request, recurring_payment_id, template_name="recurring_payments/authnet/cim_manage_payment_iframe2.html" ): """ Add or edit payment info. """ rp = get_object_or_404(RecurringPayment, pk=recurring_payment_id) gateway_error = False # only admin or user self can access this page if not request.user.profile.is_superuser and request.user.id <> rp.user.id: raise Http403 if hasattr(settings, 'AUTHNET_CIM_TEST_MODE') and settings.AUTHNET_CIM_TEST_MODE: test_mode = 'true' form_post_url = "https://test.authorize.net/profile/manage" else: test_mode = 'false' form_post_url = "https://secure.authorize.net/profile/manage" if not rp.customer_profile_id: # customer_profile is not available yet for this customer, create one now cp = CIMCustomerProfile() d = { 'email': rp.user.email, 'description': rp.description, 'customer_id': str(rp.id) } success, response_d = cp.create(**d) if success: rp.customer_profile_id = response_d['customer_profile_id'] rp.save() else: gateway_error = True #payment_profiles = PaymentProfile.objects.filter(recurring_payment=rp, status=1, status_detail='active') # get the token from payment gateway for this customer (customer_profile_id=4356210) token = "" if not gateway_error: hosted_profile_page = CIMHostedProfilePage(rp.customer_profile_id) success, response_d = hosted_profile_page.get() if not success: gateway_error = True else: token = response_d['token'] return render_to_response(template_name, { 'token': token, 'test_mode': test_mode, 'form_post_url': form_post_url, 'rp': rp, 'gateway_error': gateway_error }, context_instance=RequestContext(request))
def manage_payment_info(request, recurring_payment_id, template_name="recurring_payments/authnet/cim_manage_payment_iframe2.html"): """ Add or edit payment info. """ rp = get_object_or_404(RecurringPayment, pk=recurring_payment_id) gateway_error = False # only admin or user self can access this page if not request.user.profile.is_superuser and request.user.id <> rp.user.id: raise Http403 if hasattr(settings, 'AUTHNET_CIM_TEST_MODE') and settings.AUTHNET_CIM_TEST_MODE: test_mode = 'true' form_post_url = "https://test.authorize.net/profile/manage" else: test_mode = 'false' form_post_url = "https://secure.authorize.net/profile/manage" if not rp.customer_profile_id: # customer_profile is not available yet for this customer, create one now cp = CIMCustomerProfile() d = {'email': rp.user.email, 'description': rp.description, 'customer_id': str(rp.id)} success, response_d = cp.create(**d) if success: rp.customer_profile_id = response_d['customer_profile_id'] rp.save() else: gateway_error = True #payment_profiles = PaymentProfile.objects.filter(recurring_payment=rp, status=1, status_detail='active') # get the token from payment gateway for this customer (customer_profile_id=4356210) token = "" if not gateway_error: hosted_profile_page = CIMHostedProfilePage(rp.customer_profile_id) success, response_d = hosted_profile_page.get() if not success: gateway_error = True else: token = response_d['token'] return render_to_response(template_name, {'token': token, 'test_mode': test_mode, 'form_post_url': form_post_url, 'rp': rp, 'gateway_error': gateway_error }, context_instance=RequestContext(request))