@maxio-com/advanced-billing-sdk
Version:
Ultimate billing and pricing flexibility for B2B SaaS. Maxio integrates directly into your product, so you can seamlessly manage your product catalog, bill customers, and collect payments.
120 lines • 7.1 kB
JavaScript
;
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubscriptionProductsController = void 0;
var tslib_1 = require("tslib");
var subscriptionMigrationPreviewRequest_js_1 = require("../models/subscriptionMigrationPreviewRequest.js");
var subscriptionMigrationPreviewResponse_js_1 = require("../models/subscriptionMigrationPreviewResponse.js");
var subscriptionProductMigrationRequest_js_1 = require("../models/subscriptionProductMigrationRequest.js");
var subscriptionResponse_js_1 = require("../models/subscriptionResponse.js");
var schema_js_1 = require("../schema.js");
var baseController_js_1 = require("./baseController.js");
var errorListResponseError_js_1 = require("../errors/errorListResponseError.js");
var SubscriptionProductsController = /** @class */ (function (_super) {
tslib_1.__extends(SubscriptionProductsController, _super);
function SubscriptionProductsController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Migrates a subscription to a different product.
*
* In order to create a migration, you must pass the `product_id` or `product_handle` in the object
* when you send a POST request. You may also pass either a `product_price_point_id` or
* `product_price_point_handle` to choose which price point the subscription is moved to. If no price
* point identifier is passed the subscription will be moved to the products default price point. The
* response will be the updated subscription.
*
* ## Valid Subscriptions
*
* Subscriptions should be in the `active` or `trialing` state in order to be migrated.
*
* (For backwards compatibility reasons, it is possible to migrate a subscription that is in the
* `trial_ended` state via the API, however this is not recommended. Since `trial_ended` is an end-of-
* life state, the subscription should be canceled, the product changed, and then the subscription can
* be reactivated.)
*
* ## Migrations Documentation
*
* Full documentation on how to record Migrations in the Advanced Billing UI can be located
* [here](https://maxio.zendesk.com/hc/en-us/articles/24181589372429-Data-Migration-to-Advanced-
* Billing).
*
* ## Failed Migrations
*
* Important note: One of the most common ways that a migration can fail is when the attempt is made to
* migrate a subscription to its current product.
*
* ## 3D Secure (3DS) Authentication post-authentication flow
*
* When a payment requires 3DS Authentication to adhere to Strong Customer Authentication (SCA), the
* request enters a post-authentication flow where a 422 Unprocessable Entity status is returned with
* an action_link that will direct the customer through 3DS Authentication.
*
* See the [3D Secure Post-Authentication Flow](https://docs.maxio.com/hc/en-us/articles/44277749524365-
* 3D-Secure-Post-Authentication-Flow) article in the product documentation to learn how to manage the
* redirect flow.
*
* @param subscriptionId The Chargify id of the subscription.
* @param body
* @return Response from the API call
*/
SubscriptionProductsController.prototype.migrateSubscriptionProduct = function (subscriptionId, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('POST');
mapped = req.prepareArgs({
subscriptionId: [subscriptionId, (0, schema_js_1.number)()],
body: [body, (0, schema_js_1.optional)(subscriptionProductMigrationRequest_js_1.subscriptionProductMigrationRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/subscriptions/", "/migrations.json"], ["/subscriptions/", "/migrations.json"])), mapped.subscriptionId);
req.throwOn(422, errorListResponseError_js_1.ErrorListResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(subscriptionResponse_js_1.subscriptionResponseSchema, requestOptions)];
});
});
};
/**
* Previews the charges resulting from migrating a subscription to a different product.
*
* ## Previewing a future date
* It is also possible to preview the migration for a date in the future, as long as it's still within
* the subscription's current billing period, by passing a `proration_date` along with the request (e.g.
* , `"proration_date": "2020-12-18T18:25:43.511Z"`).
*
* This will calculate the prorated adjustment, charge, payment and credit applied values assuming the
* migration is done at that date in the future as opposed to right now.
*
* @param subscriptionId The Chargify id of the subscription.
* @param body
* @return Response from the API call
*/
SubscriptionProductsController.prototype.previewSubscriptionProductMigration = function (subscriptionId, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('POST');
mapped = req.prepareArgs({
subscriptionId: [subscriptionId, (0, schema_js_1.number)()],
body: [body, (0, schema_js_1.optional)(subscriptionMigrationPreviewRequest_js_1.subscriptionMigrationPreviewRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/subscriptions/", "/migrations/preview.json"], ["/subscriptions/", "/migrations/preview.json"])), mapped.subscriptionId);
req.throwOn(422, errorListResponseError_js_1.ErrorListResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(subscriptionMigrationPreviewResponse_js_1.subscriptionMigrationPreviewResponseSchema, requestOptions)];
});
});
};
return SubscriptionProductsController;
}(baseController_js_1.BaseController));
exports.SubscriptionProductsController = SubscriptionProductsController;
var templateObject_1, templateObject_2;
//# sourceMappingURL=subscriptionProductsController.js.map