Exemplo n.º 1
0
    def process_response(self, res):
        from r2.models import Account
        fullname = res.merchantcustomerid.contents[0]
        name = res.description.contents[0]
        customer_id = int(res.customerprofileid.contents[0])
        acct = Account._by_name(name)

        # make sure we are updating the correct account!
        if acct.name == name:
            CustomerID.set(acct, customer_id)
        else:
            raise AuthorizeNetException, \
                  "account name doesn't match authorize.net account"

        # parse the ship-to list, and make sure the Account is up todate
        ship_to = []
        for profile in res.findAll("shiptolist"):
            a = Address.fromXML(profile)
            ShippingAddress.add(acct, a.customerAddressId)
            ship_to.append(a)

        # parse the payment profiles, and ditto
        profiles = []
        for profile in res.findAll("paymentprofiles"):
            a = Address.fromXML(profile)
            cc = CreditCard.fromXML(profile.payment)
            payprof = PaymentProfile(a, cc, int(a.customerPaymentProfileId))
            PayID.add(acct, a.customerPaymentProfileId)
            profiles.append(payprof)

        return acct, Profile(acct, profiles, ship_to)
Exemplo n.º 2
0
Arquivo: api.py Projeto: eerock/reddit
    def process_response(self, res):
        from r2.models import Account

        fullname = res.merchantcustomerid.contents[0]
        name = res.description.contents[0]
        customer_id = int(res.customerprofileid.contents[0])
        acct = Account._by_name(name)

        # make sure we are updating the correct account!
        if acct.name == name:
            CustomerID.set(acct, customer_id)
        else:
            raise AuthorizeNetException, "account name doesn't match authorize.net account"

        # parse the ship-to list, and make sure the Account is up todate
        ship_to = []
        for profile in res.findAll("shiptolist"):
            a = Address.fromXML(profile)
            ShippingAddress.add(acct, a.customerAddressId)
            ship_to.append(a)

        # parse the payment profiles, and ditto
        profiles = []
        for profile in res.findAll("paymentprofiles"):
            a = Address.fromXML(profile)
            cc = CreditCard.fromXML(profile.payment)
            payprof = PaymentProfile(a, cc, int(a.customerPaymentProfileId))
            PayID.add(acct, a.customerPaymentProfileId)
            profiles.append(payprof)

        return acct, Profile(acct, profiles, ship_to)
Exemplo n.º 3
0
Arquivo: api.py Projeto: eerock/reddit
 def process_error(self, res):
     if self.is_error_code(res, Errors.DUPLICATE_RECORD):
         # D'oh.  We lost one
         m = self.re_lost_id.match(res.find("text").contents[0]).groups()
         CustomerID.set(self._user, m[0])
     # otherwise, we might have sent a user that already had a customer ID
     cust_id = CustomerID.get_id(self._user)
     if cust_id:
         return cust_id
     return AuthorizeNetRequest.process_error(self, res)
Exemplo n.º 4
0
 def process_error(self, res):
     if self.is_error_code(res, Errors.DUPLICATE_RECORD):
         # D'oh.  We lost one
         m = self.re_lost_id.match(res.find("text").contents[0]).groups()
         CustomerID.set(self._user, m[0])
     # otherwise, we might have sent a user that already had a customer ID
     cust_id = CustomerID.get_id(self._user)
     if cust_id:
         return cust_id
     return AuthorizeNetRequest.process_error(self, res)
Exemplo n.º 5
0
def get_or_create_customer_profile(user):
    profile_id = CustomerID.get_id(user._id)
    if not profile_id:
        profile_id = api.create_customer_profile(merchant_customer_id=user._fullname, description=user.name)
        CustomerID.set(user, profile_id)

    profile = api.get_customer_profile(profile_id)

    if not profile or profile.merchantCustomerId != user._fullname:
        raise ValueError("error getting customer profile")

    for payment_profile in profile.paymentProfiles:
        PayID.add(user, payment_profile.customerPaymentProfileId)

    return profile
Exemplo n.º 6
0
def get_or_create_customer_profile(user):
    profile_id = CustomerID.get_id(user._id)
    if not profile_id:
        profile_id = api.create_customer_profile(
            merchant_customer_id=user._fullname, description=user.name)
        CustomerID.set(user, profile_id)

    profile = api.get_customer_profile(profile_id)

    if not profile or profile.merchantCustomerId != user._fullname:
        raise ValueError("error getting customer profile")

    for payment_profile in profile.paymentProfiles:
        PayID.add(user, payment_profile.customerPaymentProfileId)

    return profile
Exemplo n.º 7
0
 def process_error(self, res):
     if self.is_error_code(res, Errors.DUPLICATE_RECORD):
         # authorize.net has a record for this customer but we don't. get
         # the correct id from the error message and update our db
         matches = self.re_lost_id.match(res.find("text").contents[0])
         if matches:
             match_groups = matches.groups()
             CustomerID.set(self._user, match_groups[0])
             g.log.debug("Updated missing authorize.net id for user %s" % self._user._id)
         else:
             # could happen if the format of the error message changes.
             msg = ("Failed to fix duplicate authorize.net profile id. "
                    "re_lost_id regexp may need to be updated. Response: %r" 
                    % res)
             raise AuthorizeNetException(msg)
     # otherwise, we might have sent a user that already had a customer ID
     cust_id = CustomerID.get_id(self._user)
     if cust_id:
         return cust_id
     return AuthorizeNetRequest.process_error(self, res)
Exemplo n.º 8
0
 def process_error(self, res):
     if self.is_error_code(res, Errors.DUPLICATE_RECORD):
         # authorize.net has a record for this customer but we don't. get
         # the correct id from the error message and update our db
         matches = self.re_lost_id.match(res.find("text").contents[0])
         if matches:
             match_groups = matches.groups()
             CustomerID.set(self._user, match_groups[0])
             g.log.debug("Updated missing authorize.net id for user %s" % self._user._id)
         else:
             # could happen if the format of the error message changes.
             msg = ("Failed to fix duplicate authorize.net profile id. "
                    "re_lost_id regexp may need to be updated. Response: %r" 
                    % res)
             raise AuthorizeNetException(msg)
     # otherwise, we might have sent a user that already had a customer ID
     cust_id = CustomerID.get_id(self._user)
     if cust_id:
         return cust_id
     return AuthorizeNetRequest.process_error(self, res)
Exemplo n.º 9
0
Arquivo: api.py Projeto: eerock/reddit
 def process_response(self, res):
     customer_id = int(res.customerprofileid.contents[0])
     CustomerID.set(self._user, customer_id)
     return customer_id
Exemplo n.º 10
0
 def process_response(self, res):
     customer_id = int(res.customerprofileid.contents[0])
     CustomerID.set(self._user, customer_id)
     return customer_id