コード例 #1
0
def existing_payment_source(existing_customer: Customer,
                            source_token: str) -> Customer:
    """
    If Customer does not have an existing Payment Source and has not been Deleted:
        - Set the Customer's payment source to the new token
        - return the updated Customer
    Else
        - return the provided customer
    :param existing_customer:
    :param source_token:
    :return:
    """
    if not existing_customer.get("sources"):
        if not existing_customer.get("deleted"):
            existing_customer = vendor.modify_customer(
                customer_id=existing_customer["id"],
                source_token=source_token,
                idempotency_key=utils.get_indempotency_key(),
            )
            logger.info("add source", existing_customer=existing_customer)
        else:
            logger.info(
                "stripe customer is marked as deleted. cannot add source.")
    logger.debug("existing payment source",
                 existing_customer=existing_customer)
    return existing_customer
コード例 #2
0
def existing_payment_source(existing_customer: Customer, source_token: str) -> Customer:
    if not existing_customer.get("sources"):
        if not existing_customer.get("deleted"):
            existing_customer = Customer.modify(
                existing_customer["id"], source=source_token
            )
            logger.info("add source", existing_customer=existing_customer)
        else:
            logger.info("existing source deleted")
    return existing_customer
コード例 #3
0
ファイル: customer.py プロジェクト: thelonewolff/subhub
def existing_payment_source(existing_customer: Customer,
                            source_token: str) -> Customer:
    if not existing_customer.get("sources"):
        if not existing_customer.get("deleted"):
            existing_customer = vendor.modify_customer(
                customer_id=existing_customer["id"],
                source_token=source_token,
                idempotency_key=utils.get_indempotency_key(),
            )
            logger.info("add source", existing_customer=existing_customer)
        else:
            logger.info("existing source deleted")
    return existing_customer
コード例 #4
0
def has_existing_plan(customer: Customer, plan_id: str) -> bool:
    """
    Check if user has the existing plan in an active or trialing state.
    :param customer:
    :param plan_id:
    :return: True if user has existing plan, otherwise False
    """
    if customer.get("subscriptions"):
        for item in customer["subscriptions"]["data"]:
            if item["plan"]["id"] == plan_id and item["status"] in [
                "active",
                "trialing",
            ]:
                return True
    return False