How to update billing plan with new plan?

mrkarim
Shopify Partner
8 0 0

I have added one billing plan but I have two more. How can I give to my client to choose to update or downgrade the plans and update the plan based on the selection?

 

Which API should I call to create a plan?

Which API should I call to get plans? 

Which API should I call to update the plan?

 

It is nodejs app. 

Reply 1 (1)

KevSig
Shopify Partner
6 0 0

Hey Mrkarim, 

 

This is the code I wrote in python to update an existing subscription with a discount, maybe it is helpful to you 

!pip install ShopifyAPI pandas
import shopify
import urllib.request
import json
import pandas as pd

merchant_token = 'xxxxxxxxxxxxxxxxxxxxxxxx'
merchant = 'xxxx.myshopify.com'

def shopify_client():
    api_session = shopify.Session(merchant,'2024-01',token)
    shopify.ShopifyResource.activate_session(api_session)
    client = shopify.GraphQL()
    print(client)
    return client

client = shopify_client()

# Define the mutation query
mutation = """
mutation AppSubscriptionCreate($name: String!, $lineItems: [AppSubscriptionLineItemInput!]!, $returnUrl: URL!) {
  appSubscriptionCreate(name: $name, returnUrl: $returnUrl, lineItems: $lineItems) {
    userErrors {
      field
      message
    }
    confirmationUrl
    appSubscription {
      id
    }
  }
}
"""

# Define the mutation variables
variables = {
    "name": "Discount plan name ",
    "returnUrl": "your app auth url",
    "lineItems": [
        {
            "plan": {
                "appRecurringPricingDetails": {
                    "price": {
                        "amount": xx,
                        "currencyCode": "USD"
                    },
                    "discount": {
                        "value": {
                            "amount": xx
                        }
                    },
                    "interval": "EVERY_30_DAYS"
                }
            }
        }
    ],
    "replacementBehavior": "APPLY_IMMEDIATELY"
}

# Execute the mutation
response = client.execute(mutation, variables)
data = json.loads(response)

# Process the response data
print(data)