def retrieve_billing_info(user): customer_id = user.customer_id if customer_id == '-1' or customer_id == '': return None try: devpay = devpayments.Client(DEVPAYMENTS_API_KEY) result = devpay.retrieveCustomer(id=customer_id) last4 = result.active_card.get('last4', '') usage = '' try: usage = result.next_recurring_charge.get('amount', '') except: pass bill_date = '' try: bill_date = result.next_recurring_charge.get('date', '') except: pass if last4 != '': last4 = "**** **** **** %s" % last4 return { 'first_name': user.first_name, 'last_name': user.last_name, 'cc_number': last4, 'usage': usage, 'bill_date': bill_date } except DevPayException as e: log_error_message(e.message) return None except Exception as e: log_error_message(e) return None
def report_usage(user, quantity, memo=""): devpay = devpayments.Client(DEVPAYMENTS_API_KEY) try: result = devpay.billCustomer(id=user.customer_id, amount=int(quantity), currency='usd') return result except Exception as e: log_error_message(e) return False
def _create_new_customer(): devpay = devpayments.Client(DEVPAYMENTS_API_KEY) try: result = devpay.createCustomer( mnemonic=_unpack_customer_info()['email'], card=_unpack_billing_info()) user.customer_id = result.id user.save() except DevPayException as e: return e.message return True
def update_devpayments_subscription(user): total_cents = sum([sub.price for sub in user.get_active_subscriptions()]) customer_id = user.customer_id devpay = devpayments.Client(DEVPAYMENTS_API_KEY) try: result = devpay.updateCustomer(id=user.customer_id, subscription={ 'amount': total_cents, 'per': 'month', 'currency': 'usd' }) return result except Exception as e: log_error_message(e) return False