def save(self, request, cart, contact, payment_module, data=None): """Save the order and the credit card information for this orderpayment""" form_presave.send(CreditPayShipForm, form=self) if data is None: data = self.cleaned_data assert (data) super(CreditPayShipForm, self).save(request, cart, contact, payment_module, data=data) if self.orderpayment: op = self.orderpayment.capture cc = CreditCardDetail(orderpayment=op, expire_month=data['month_expires'], expire_year=data['year_expires'], credit_type=data['credit_type']) cc.storeCC(data['credit_number']) cc.save() # set ccv into cache cc.ccv = data['ccv'] self.cc = cc form_postsave.send(CreditPayShipForm, form=self)
def save(self, request, cart, contact, payment_module, data=None): form_presave.send(SimplePayShipForm, form=self) if data is None: data = self.cleaned_data self.order = get_or_create_order(request, cart, contact, data) if payment_module: processor_module = payment_module.MODULE.load_module('processor') processor = processor_module.PaymentProcessor(payment_module) self.orderpayment = processor.create_pending_payment(order=self.order) else: self.orderpayment = None form_postsave.send(SimplePayShipForm, form=self)
def save(self, request, *args, **kwargs): form_presave.send(PaymentContactInfoForm, form=self) contactid = super(PaymentContactInfoForm, self).save(*args, **kwargs) contact = Contact.objects.get(pk=contactid) cart = kwargs.get('cart', None) if not cart: cart = Cart.objects.from_request(request) if not cart.customer: cart.customer = contact cart.save() self.order = get_or_create_order(request, cart, contact, self.cleaned_data) form_postsave.send(PaymentContactInfoForm, form=self) return contactid
def save(self, request, cart, contact, payment_module, data=None): """Save the order and the credit card information for this orderpayment""" form_presave.send(CreditPayShipForm, form=self) if data is None: data = self.cleaned_data assert(data) super(CreditPayShipForm, self).save(request, cart, contact, payment_module, data=data) if self.orderpayment: op = self.orderpayment.capture cc = CreditCardDetail(orderpayment=op, expire_month=data['month_expires'], expire_year=data['year_expires'], credit_type=data['credit_type']) cc.storeCC(data['credit_number']) cc.save() # set ccv into cache cc.ccv = data['ccv'] self.cc = cc form_postsave.send(CreditPayShipForm, form=self)
def save_info(self, contact=None, **kwargs): """Save the contact info into the database. Checks to see if contact exists. If not, creates a contact and copies in the address and phone number.""" if not contact: customer = Contact() log.debug('creating new contact') else: customer = contact log.debug('Saving contact info for %s', contact) data = self.cleaned_data.copy() country = data['country'] if not isinstance(country, Country): country = Country.objects.get(pk=country) data['country'] = country data['country_id'] = country.id shipcountry = data['ship_country'] if not isinstance(shipcountry, Country): shipcountry = Country.objects.get(pk=shipcountry) data['ship_country'] = shipcountry data['ship_country_id'] = shipcountry.id organization_name = data.pop('organization', None) if organization_name: org = Organization.objects.by_name(organization_name, create=True) customer.organization = org else: # in case customer wants to remove organization name from their profile customer.organization = None for field in customer.__dict__.keys(): try: setattr(customer, field, data[field]) except KeyError: pass if not customer.role: customer.role = ContactRole.objects.get(pk='Customer') customer.save() # we need to make sure we don't blindly add new addresses # this isn't ideal, but until we have a way to manage addresses # this will force just the two addresses, shipping and billing # TODO: add address management like Amazon. bill_address = customer.billing_address if not bill_address: bill_address = AddressBook(contact=customer) changed_location = False address_keys = bill_address.__dict__.keys() for field in address_keys: if (not changed_location) and field in ('state', 'country_id', 'city'): if getattr(bill_address, field) != data[field]: changed_location = True try: setattr(bill_address, field, data[field]) except KeyError: pass bill_address.is_default_billing = True copy_address = data['copy_address'] ship_address = customer.shipping_address try: setattr(ship_address, "addressee", data.get('ship_addressee', "")) setattr(bill_address, "addressee", data.get('addressee', "")) except AttributeError: pass # If we are copying the address and one isn't in place for shipping # copy it if not getattr(ship_address, "addressee", False) and copy_address: try: ship_address.addressee = bill_address.addressee except AttributeError: pass # Make sure not to overwrite a custom ship to name if copy_address and getattr(ship_address, "addressee", "") == getattr( bill_address, "addressee", ""): # make sure we don't have any other default shipping address if ship_address and ship_address.id != bill_address.id: ship_address.delete() bill_address.is_default_shipping = True bill_address.save() # If we have different ship to and bill to names, preserve them if not copy_address or getattr(ship_address, "addressee", "") != getattr( bill_address, "addressee", ""): if not ship_address or ship_address.id == bill_address.id: ship_address = AddressBook() for field in address_keys: ship_field = 'ship_' + field if (not changed_location) and field in ('state', 'country_id', 'city'): if getattr(ship_address, field) != data[ship_field]: changed_location = True try: setattr(ship_address, field, data[ship_field]) except KeyError: pass ship_address.is_default_shipping = True ship_address.is_default_billing = False ship_address.contact = customer ship_address.save() if not customer.primary_phone: phone = PhoneNumber() phone.primary = True else: phone = customer.primary_phone phone.phone = data['phone'] phone.contact = customer phone.save() form_postsave.send(ContactInfoForm, object=customer, formdata=data, form=self) if changed_location: signals.satchmo_contact_location_changed.send(self, contact=customer) return customer.id
def save_info(self, contact=None, **kwargs): """Save the contact info into the database. Checks to see if contact exists. If not, creates a contact and copies in the address and phone number.""" if not contact: customer = Contact() log.debug('creating new contact') else: customer = contact log.debug('Saving contact info for %s', contact) data = self.cleaned_data.copy() country = data['country'] if not isinstance(country, Country): country = Country.objects.get(pk=country) data['country'] = country data['country_id'] = country.id shipcountry = data['ship_country'] if not isinstance(shipcountry, Country): shipcountry = Country.objects.get(pk=shipcountry) data['ship_country'] = shipcountry data['ship_country_id'] = shipcountry.id organization_name = data.pop('organization', None) if organization_name: org = Organization.objects.by_name(organization_name, create=True) customer.organization = org else: # in case customer wants to remove organization name from their profile customer.organization = None for field in customer.__dict__.keys(): try: setattr(customer, field, data[field]) except KeyError: pass if not customer.role: customer.role = ContactRole.objects.get(pk='Customer') customer.save() # we need to make sure we don't blindly add new addresses # this isn't ideal, but until we have a way to manage addresses # this will force just the two addresses, shipping and billing # TODO: add address management like Amazon. bill_address = customer.billing_address if not bill_address: bill_address = AddressBook(contact=customer) changed_location = False address_keys = bill_address.__dict__.keys() for field in address_keys: if (not changed_location) and field in ('state', 'country_id', 'city'): if getattr(bill_address, field) != data[field]: changed_location = True try: setattr(bill_address, field, data[field]) except KeyError: pass bill_address.is_default_billing = True copy_address = data['copy_address'] ship_address = customer.shipping_address try: setattr(ship_address, "addressee",data.get('ship_addressee', "")) setattr(bill_address, "addressee",data.get('addressee', "")) except AttributeError: pass # If we are copying the address and one isn't in place for shipping # copy it if not getattr(ship_address, "addressee", False) and copy_address: try: ship_address.addressee = bill_address.addressee except AttributeError: pass # Make sure not to overwrite a custom ship to name if copy_address and getattr(ship_address, "addressee", "") == getattr(bill_address, "addressee", ""): # make sure we don't have any other default shipping address if ship_address and ship_address.id != bill_address.id: ship_address.delete() bill_address.is_default_shipping = True bill_address.save() # If we have different ship to and bill to names, preserve them if not copy_address or getattr(ship_address, "addressee", "") != getattr(bill_address, "addressee", ""): if not ship_address or ship_address.id == bill_address.id: ship_address = AddressBook() for field in address_keys: ship_field = 'ship_' + field if (not changed_location) and field in ('state', 'country_id', 'city'): if getattr(ship_address, field) != data[ship_field]: changed_location = True try: setattr(ship_address, field, data[ship_field]) except KeyError: pass ship_address.is_default_shipping = True ship_address.is_default_billing = False ship_address.contact = customer ship_address.save() if not customer.primary_phone: phone = PhoneNumber() phone.primary = True else: phone = customer.primary_phone phone.phone = data['phone'] phone.contact = customer phone.save() form_postsave.send(ContactInfoForm, object=customer, formdata=data, form=self) if changed_location: signals.satchmo_contact_location_changed.send(self, contact=customer) return customer.id