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)
def add_payment_method(user, address, credit_card, validate=False): profile_id = CustomerID.get_id(user._id) payment_method_id = api.create_payment_profile(profile_id, address, credit_card, validate) if payment_method_id: PayID.add(user, payment_method_id) return payment_method_id
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)
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
def auth_transaction(amount, user, payment_method_id, link, campaign_id): if payment_method_id not in PayID.get_ids(user._id): return None, "invalid payment method" profile_id = CustomerID.get_id(user._id) invoice = "T%dC%d" % (link._id, campaign_id) try: transaction_id = api.create_authorization_hold(profile_id, payment_method_id, amount, invoice, request.ip) except api.DuplicateTransactionError as e: transaction_id = e.transaction_id try: bid = Bid.one(transaction_id, campaign=campaign_id) except NotFound: bid = Bid._new(transaction_id, user, payment_method_id, link._id, amount, campaign_id) g.log.error("%s on campaign %d" % (e.message, campaign_id)) return transaction_id, None except api.TransactionError as e: return None, e.message bid = Bid._new(transaction_id, user, payment_method_id, link._id, amount, campaign_id) return transaction_id, None
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
def auth_transaction(user, campaign_id, link_id, amount, payment_method_id, references): if payment_method_id not in PayID.get_ids(user._id): return None, "invalid payment method" profile_id = CustomerID.get_id(user._id) invoice = "T%dC%d" % (link_id, campaign_id) references['pay_id'] = payment_method_id try: authorize_response = api.create_authorization_hold( profile_id, payment_method_id, amount, invoice, request.ip) AuthorizeTransaction._new(authorize_response, **references) except api.DuplicateTransactionError as e: transaction_id = e.transaction_id try: bid = Bid.one(transaction_id, campaign=campaign_id) except NotFound: bid = Bid._new(transaction_id, user, payment_method_id, link_id, amount, campaign_id) g.log.error("%s on campaign %d" % (e.message, campaign_id)) return transaction_id, None except api.TransactionError as e: authorize_response = e.authorize_response AuthorizeTransaction._new(authorize_response, **references) return None, e.message bid = Bid._new(authorize_response.trans_id, user, payment_method_id, link_id, amount, campaign_id) return authorize_response.trans_id, None
def auth_transaction(amount, user, payment_method_id, link, campaign_id): if payment_method_id not in PayID.get_ids(user._id): return None, "invalid payment method" profile_id = CustomerID.get_id(user._id) invoice = "T%dC%d" % (link._id, campaign_id) try: transaction_id = api.create_authorization_hold( profile_id, payment_method_id, amount, invoice, request.ip) except api.DuplicateTransactionError as e: transaction_id = e.transaction_id try: bid = Bid.one(transaction_id, campaign=campaign_id) except NotFound: bid = Bid._new(transaction_id, user, payment_method_id, link._id, amount, campaign_id) g.log.error("%s on campaign %d" % (e.message, campaign_id)) return transaction_id, None except api.TransactionError as e: return None, e.message bid = Bid._new(transaction_id, user, payment_method_id, link._id, amount, campaign_id) return transaction_id, None
def auth_transaction(user, campaign_id, link_id, amount, payment_method_id, references): if payment_method_id not in PayID.get_ids(user._id): return None, "invalid payment method" profile_id = CustomerID.get_id(user._id) invoice = "T%dC%d" % (link_id, campaign_id) references["pay_id"] = payment_method_id try: authorize_response = api.create_authorization_hold(profile_id, payment_method_id, amount, invoice, request.ip) AuthorizeTransaction._new(authorize_response, **references) except api.DuplicateTransactionError as e: transaction_id = e.transaction_id try: bid = Bid.one(transaction_id, campaign=campaign_id) except NotFound: bid = Bid._new(transaction_id, user, payment_method_id, link_id, amount, campaign_id) g.log.error("%s on campaign %d" % (e.message, campaign_id)) return transaction_id, None except api.TransactionError as e: authorize_response = e.authorize_response AuthorizeTransaction._new(authorize_response, **references) return None, e.message bid = Bid._new(authorize_response.trans_id, user, payment_method_id, link_id, amount, campaign_id) return authorize_response.trans_id, None
def auth_transaction(amount, user, payid, thing, campaign, test=None): # use negative pay_ids to identify freebies, coupons, or anything # that doesn't require a CC. if payid < 0: trans_id = -thing._id # update previous freebie transactions if we can try: bid = Bid.one(thing_id=thing._id, transaction=trans_id, campaign=campaign) bid.bid = amount bid.auth() except NotFound: bid = Bid._new(trans_id, user, payid, thing._id, amount, campaign) return bid.transaction, "" elif int(payid) in PayID.get_ids(user): order = Order(invoiceNumber="T%dC%d" % (thing._id, campaign)) success, res = _make_transaction(ProfileTransAuthOnly, amount, user, payid, order=order, test=test) if success: if test: return auth_transaction(amount, user, -1, thing, campaign, test=test) else: Bid._new(res.trans_id, user, payid, thing._id, amount, campaign) return res.trans_id, "" elif res is None: # we are in test mode! return auth_transaction(amount, user, -1, thing, test=test) # duplicate transaction, which is bad, but not horrible. Log # the transaction id, creating a new bid if necessary. elif res.trans_id and (res.response_code, res.response_reason_code) == (3, 11): g.log.error("Authorize.net duplicate trans %d on campaign %d" % (res.trans_id, campaign)) try: Bid.one(res.trans_id, campaign=campaign) except NotFound: Bid._new(res.trans_id, user, payid, thing._id, amount, campaign) return res.trans_id, res.response_reason_text
def auth_transaction(amount, user, payid, thing, campaign, test=None): # use negative pay_ids to identify freebies, coupons, or anything # that doesn't require a CC. if payid < 0: trans_id = -thing._id # update previous freebie transactions if we can try: bid = Bid.one(thing_id=thing._id, transaction=trans_id, campaign=campaign) bid.bid = amount bid.auth() except NotFound: bid = Bid._new(trans_id, user, payid, thing._id, amount, campaign) return bid.transaction, "" elif int(payid) in PayID.get_ids(user): order = Order(invoiceNumber="T%dC%d" % (thing._id, campaign)) success, res = _make_transaction(ProfileTransAuthOnly, amount, user, payid, order=order, test=test) if success: if test: return auth_transaction(amount, user, -1, thing, campaign, test = test) else: Bid._new(res.trans_id, user, payid, thing._id, amount, campaign) return res.trans_id, "" elif res is None: # we are in test mode! return auth_transaction(amount, user, -1, thing, test=test) # duplicate transaction, which is bad, but not horrible. Log # the transaction id, creating a new bid if necessary. elif res.trans_id and (res.response_code, res.response_reason_code) == (3,11): g.log.error("Authorize.net duplicate trans %d on campaign %d" % (res.trans_id, campaign)) try: Bid.one(res.trans_id, campaign=campaign) except NotFound: Bid._new(res.trans_id, user, payid, thing._id, amount, campaign) return res.trans_id, res.response_reason_text
def process_error(self, res): if self.is_error_code(res, Errors.RECORD_NOT_FOUND): PayID.delete(self._user, self.customerPaymentProfileId) return GetCustomerPaymentProfileRequest.process_error(self, res)
def process_response(self, res): PayID.delete(self._user, self.customerPaymentProfileId) return True
def delete_payment_method(user, payment_method_id): profile_id = CustomerID.get_id(user._id) success = api.delete_payment_profile(profile_id, payment_method_id) if success: PayID.delete(user, payment_method_id)
def process_response(self, res): # add the id to the user object in case something has gone wrong PayID.add(self._user, self.customerPaymentProfileId) return PaymentProfile.fromXML(res.paymentprofile)
def process_response(self, res): pay_id = int(res.customerpaymentprofileid.contents[0]) PayID.add(self._user, pay_id) return pay_id