Skip to content

Instantly share code, notes, and snippets.

@AhmedAbouelkher
Last active November 20, 2021 19:06
Show Gist options
  • Save AhmedAbouelkher/f350d7e30cdf43e5c661e3241eb23d3c to your computer and use it in GitHub Desktop.
Save AhmedAbouelkher/f350d7e30cdf43e5c661e3241eb23d3c to your computer and use it in GitHub Desktop.

Update 20-11-2021

Manual Subscription

  • create manual subscription: POST /manual/subscriptions

Body

{
    "kid": "user_kid",
    "metadata": {
        "daily_classic_coffee_count": 1,
        "daily_specialty_coffee_count": 1,
        "total_classic_coffee_count": 365,
        "total_specialty_coffee_count": 365,
        "name": "Installment Subscription"
    },
    "interval": "yearly",
    "fixed_credit": false,
    "active": true,
    "out_of_credits": false,
    "subscription_id": "subscription_givin_id",
    "payment_method_id": "971525619098_2021-11-20_17--15--33",
    "period_start": "2021-11-20",
    "period_end": "2022-11-20",
    "payment": {
        "amount_due": 3540.00,
        "amount_paid": 3540.00
    }
}

interval: yearly or monthly

fixed_credit, out_of_credits and active are false, false and true respectively.

  • delete manual subscription: DELETE /manual/subscriptions/:id

Url Params

-- id: subscription id.

  • fetch manual subscriptions: GET /manual/subscriptions

Query params

-- subscription_id

-- kid


Update 18-11-2021

Coupon

  • Fetch all coupons: GET /coupon
  • Delete a coupon by code: DELETE /coupon/:code
  • Update a coupon by code: PUT /coupon/:code body:
{
    "active": false,
    "interval": "yearly"
}
  • Create new coupon: POST /coupon body:
{
    "code": "coupon_unique_code_name", 
    "percent_off": 25,
    "max_limit": 1,
    "expiry": "2021-11-30",
    "applies_to": [
        "classic_coffee",
        "specialty_coffee"
    ],
    "interval": "monthly"
}

applies_to must be a value in [classic_coffee, specialty_coffee].

interval must be either monthly or yearly.

coupon code equals id on Stripe dashboard.

When creating a coupon on Stripe dashboard the default interval is yearly, if you want to change the default interval value, you must call the Update a coupon by code api with the new interval.

Subscription

to create a new subscription using the newly created coupon use Create new Subscription api and add coupon_id string field and a value of the coupon id/code.


Update 7-11-2021

Zoho new request object

"field_name": data type

{
    "kid": String,
    "subscription_id": String,
    "interval": String,
    "payment_method_id": String,
    "total_paid": Number,
    
    "name": String,
    "coupon_id": String,
    "daily_classic_coffee_count": Number,
    "daily_specialty_coffee_count":Number,
    "total_classic_coffee_count":Number,
    "total_specialty_coffee_count":Number,

    "user_metadata": Object,
    "created_at": DateTime,
}

 const user_metadata = {
        first_name: user.first_name || '',
        last_name: user.last_name || '',
        phone_number: user.phone_number,
        kid: user.kid,
        birth_date: user.birth_date || '',
        email: user.email || '',
        emirate: user.emirate || ''
  }

Manual Subscription

request body:

{
    "metadata" : {
        "daily_classic_coffee_count" : 2,
        "daily_specialty_coffee_count" : 0,
        "total_classic_coffee_count" : 60,
        "total_specialty_coffee_count" : 0,
        "name" : "Subscription 16"
    },
    "interval" : "yearly",
    "fixed_credit" : false,
    "active" : true,
    "out_of_credits" : false,
    "subscription_id" : "sub_1Js77vL4r9sVX2wgzkU8MdJO",
    "kid" : "kid-041-04568540",
    "customer_id" : "cus_KVInzhxKyGUw5E",
    "payment_method_id" : "pm_1Jr6JHL4r9sVX2wg5gzeXGQF",
    "period_start": "2005-10-21",
    "period_end": "2005-10-21",
    "payment" : {
        "amount_due" : 73800,
        "amount_paid" : 73800
    }
}

Update 4-11-2021

Subscription

  • Create new Subscription: POST: /payment/api/cutomer/subscription/create

NEW request body:

{
    "payment_method_id": "payment method id from stripe",
    "interval": "monthly", //yearly
    "coupon_id": "the is of your pomo code id",
    "products": [
        {
            "id": "classic_coffee",
            "quantity": 1
        },
        {
            "id": "specialty_coffee",
            "quantity": 1
        }
    ],
    "metadata": {
        "name": "Subscription 16"
    }
}

Update 26-10-2021

Subscription

  • Create new Subscription: POST: /payment/api/cutomer/subscription/create

NEW request body:

{
    "payment_method_id": "pm_1JmhvTL4r9sVX2wga6KH4mQk",
    "interval": "yearly", //or: monthly
    "promo_code_id": "promo_code", // promo code -> code
    "products": [
        {
            "id": "specialy_cup",
            "quantity": 1 // = daily_specialty_coffee_count
        },
        {
            "id": "classic_cup",
            "quantity": 1 // = daily_classic_coffee_count
        }
    ],
    "metadata": {
        "name": "New subscription",
        "daily_specialty_coffee_count": 1,
        "daily_classic_coffee_count": 1
    }
}

Migrations

Card

Changed to be payment_methods

  • Fetch all customer payment methods: GET /payment/api/cutomer/payment_methods
  • Fetch payment method with id: GET /payment/api/cutomer/payment_methods/:id
  • Add new Payment method to customer: POST /payment/api/cutomer/payment_methods/add
  • Delete/Datatch payment method from customer: DELETE /payment/api/cutomer/payment_methods/:id

Subscription

  • Fetch customer's subscription details: GET: /payment/api/cutomer/subscription/:id
  • Fetch customer's subscriptions: GET: /payment/api/cutomer/subscription
  • Cancel customer's subscription: DELETE /payment/api/cutomer/subscription/:id
  • Create new Subscription: POST: /payment/api/cutomer/subscription/create
{
    "payment_method_id": "pm_1JmhvTL4r9sVX2wga6KH4mQk",
    "products": [
        {
            "id": "prod_KQrleXUoFL7vnZ",
            "unit_amount_decimal": 500,
            "quantity": 5
        }
    ],
    "metadata": {
        "name": "Sub 5",
        "dailyClassicCoffeeCount": 5,
        "dailySpecialtyCoffeeCount": 10
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment