Subscription Id is not being received in Chargebee response when transaction is created

Modified on: Fri, 4 Nov, 2022 at 5:44 PM

Scope

Why subscription ID is not generated for the non-recurring addon via API?

Subscription Id is not being received in Chargebee response when the transaction is created


 

Summary

A subscription ID will only be generated if the Charges & One-time charges (PC 2.0) or Non-recurring addons (PC 1.0) are linked to a subscription via API/UI. Adding Non-recurring addons/Charges/One-time Charges from the Customer details page (UI) or by using Create invoice for items and one-time charges API only with customer ID will create charges for the customer and therefore subscription ID will not be present on this event.

Entities that can be linked to customer ID or subscription ID

PC 1.0 - Non-recurring addon

PC 2.0 - Charge, One-time charge


Solution

non-recurring addon (PC 1.0) is a product or service that has been modeled into Chargebee that does not renew with the subscription though it is linked to it. This can be linked to a subscription or to the customer


Charge (PC 2.0) represents products or services that are non-recurring, either purchased once immediately or scheduled for purchase on specific events which can also be attached to customers without a subscription.


one-time charge (PC 2.0) is an ad-hoc charge against a customer and can be linked to any particular subscription or customer.


In this example, we have created a Charge linked to the subscription ID.

sample request

curl  https://videoclikz-test.chargebee.com/api/v2/invoices/create_for_charge_items_and_charges \

     -u test_Mu99gW9wCf6kKeiUTP5bcduMEjGYMscuqA:\

     -d subscription_id="AzZTUvTKhlNgE2Am" \

     -d item_prices[item_price_id][0]="Charge-USD" \

     -d item_prices[quantity][0]="2" \


sample response

{

    "invoice": {

        "id": "2022000699",

        "customer_id": "16Be5OTKhKSGE1ef",

        "recurring": false,

        "status": "posted",

        "price_type": "tax_exclusive",

        "date": 1666264512,

        "due_date": 1668424513,

        "net_term_days": 25,

        "exchange_rate": 1.0,

        "total": 4600,

        "amount_paid": 0,

        "amount_adjusted": 0,

        "write_off_amount": 0,

        "credits_applied": 0,

        "amount_due": 4600,

        "updated_at": 1666264513,

        "resource_version": 1666264513260,

        "deleted": false,

        "object": "invoice",

        "first_invoice": false,

        "amount_to_collect": 4600,

        "round_off_amount": 0,

        "has_advance_charges": false,

        "currency_code": "USD",

        "base_currency_code": "USD",

        "generated_at": 1666264513,

        "is_gifted": false,

        "term_finalized": true,

        "channel": "web",

        "payment_owner": "16Be5OTKhKSGE1ef",

        "tax": 0,

        "line_items": [{

            "id": "li_AzZizYTKnk5Pts9o",

            "date_from": 1666204200,

            "date_to": 1666290599,

            "unit_amount": 2300,

            "quantity": 2,

            "amount": 4600,

            "pricing_model": "per_unit",

            "is_taxed": false,

            "tax_amount": 0,

            "object": "line_item",

            "subscription_id": "AzZTUvTKhlNgE2Am",

            "customer_id": "16CM4DTKhKmi21WL",

            "description": "Charge",

            "entity_type": "charge_item_price",

            "entity_id": "Charge-USD",

            "metered": false,

            "tax_exempt_reason": "export",

            "discount_amount": 0,

            "item_level_discount_amount": 0

        }],

        "sub_total": 4600,

        "linked_payments": [],

        "applied_credits": [],

        "adjustment_credit_notes": [],

        "issued_credit_notes": [],

        "linked_orders": [],

        "dunning_attempts": [],

        "billing_address": {

            "first_name": "Kat",

            "last_name": "Josh",

            "validation_status": "not_validated",

            "object": "billing_address"

        },

        "notes": [{

            "note": "<a href=\"https://www.yoursite.com\">Visit mysite.com<\/a>"

        }]

    }

}



In this example, we have created a charge linked to the customer


sample request

curl  https://videoclikz-test.chargebee.com/api/v2/invoices/create_for_charge_items_and_charges \

     -u test_Mu99gW9wCf6kKeiUTP5bcduMEjGYMscuqA:\

     -d customer_id="16Be5OTKhKSGE1ef" \

     -d item_prices[item_price_id][0]="Charge-USD" \

     -d item_prices[quantity][0]="2"



same response

{

    "invoice": {

        "id": "2022000701",

        "customer_id": "16Be5OTKhKSGE1ef",

        "recurring": false,

        "status": "posted",

        "price_type": "tax_exclusive",

        "date": 1666277535,

        "due_date": 1668437535,

        "net_term_days": 25,

        "exchange_rate": 1.0,

        "total": 4600,

        "amount_paid": 0,

        "amount_adjusted": 0,

        "write_off_amount": 0,

        "credits_applied": 0,

        "amount_due": 4600,

        "updated_at": 1666277535,

        "resource_version": 1666277535707,

        "deleted": false,

        "object": "invoice",

        "first_invoice": false,

        "amount_to_collect": 4600,

        "round_off_amount": 0,

        "has_advance_charges": false,

        "currency_code": "USD",

        "base_currency_code": "USD",

        "generated_at": 1666277535,

        "is_gifted": false,

        "term_finalized": true,

        "channel": "web",

        "payment_owner": "16Be5OTKhKSGE1ef",

        "tax": 0,

        "line_items": [{

            "id": "li_16CJAnTKocjC0aph",

            "date_from": 1666204200,

            "date_to": 1666290599,

            "unit_amount": 2300,

            "quantity": 2,

            "amount": 4600,

            "pricing_model": "per_unit",

            "is_taxed": false,

            "tax_amount": 0,

            "object": "line_item",

            "customer_id": "16Be5OTKhKSGE1ef",

            "description": "Charge",

            "entity_type": "charge_item_price",

            "entity_id": "Charge-USD",

            "metered": false,

            "tax_exempt_reason": "export",

            "discount_amount": 0,

            "item_level_discount_amount": 0

        }],

        "sub_total": 4600,

        "linked_payments": [],

        "applied_credits": [],

        "adjustment_credit_notes": [],

        "issued_credit_notes": [],

        "linked_orders": [],

        "dunning_attempts": [],

        "billing_address": {

            "first_name": "Kat",

            "last_name": "Josh",

            "validation_status": "not_validated",

            "object": "billing_address"

        },

        "notes": [{

            "note": "<a href=\"https://www.yoursite.com\">Visit mysite.com<\/a>"

        }]

    }

}



Related Articles

What is the difference between one-time charge and recurring charge notifications?

What is the difference between Charges and Quick Charges in PC 2.0?

How to differentiate between Addon and Charges in Portal?

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.
×