> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # ChargeMembership # Package: memberships # Namespace: MembershipsSPI # Method link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/payments/memberships/memberships-service-plugin/charge-membership.md ## Introduction This method requests that a membership be charged by your app. --- ## REST API ### Schema ``` Method: chargeMembership Description: This method requests that a membership be charged by your app. URL: null Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: memberId, membershipId, idempotencyKey, catalogReference, catalogReference.appId Method parameters: param name: additionalData | type: additionalData | description: Additional data about this charge. param name: catalogReference | type: CatalogReference | description: Used for grouping line items. Sent when an item is added to a cart, checkout, or order. | required: true - name: catalogItemId | type: string | description: GUID of the item within the catalog it belongs to. - name: appId | type: string | description: GUID of the app providing the catalog. You can get your app's GUID from its page in the [app dashboard](https://dev.wix.com/dc3/my-apps/). For items from Wix catalogs, the following values always apply: + Wix Stores: `"215238eb-22a5-4c36-9e7b-e7c08025e04e"` + Wix Bookings: `"13d21c63-b5ec-5912-8397-c3a5ddb27a97"` + Wix Restaurants: `"9a5d83fd-8570-482e-81ab-cfa88942ee60"` | required: true - name: options | type: object | description: Additional item details in `key:value` pairs. Use this optional field for more specificity with item selection. The values of the `options` field differ depending on which catalog is providing the items. For Wix Stores products, learn more about integrating with [Catalog V3](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/e-commerce-integration.md) or [Catalog V1](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/e-commerce-integration.md), depending on [the version the site uses](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-versioning/introduction.md). param name: idempotencyKey | type: idempotencyKey | description: Idempotency key to avoid duplicate charge. The value will usually would be the same as `membershipId` + `orderId` + `rootCatalogItemId`. | required: true param name: memberId | type: memberId | description: Member GUID. Do not retrieve this from the request context. In some cases the caller is not a member, but a user who is using the membership on behalf of a member. | required: true param name: membershipId | type: membershipId | description: Membership GUID, as returned from the List Eligible Memberships call. | required: true param name: rootCatalogItemId | type: rootCatalogItemId | description: Root catalog item GUID. The value will usually be the same as `catalogReference.catalogItemId`. In cases when these are not the same, this field will return the actual GUID of the item in the catalog. For example, for Wix bookings, the value of `catalogReference.catalogItemId` is the booking GUID, but `rootCatalogItemId` is set to the service GUID. param name: serviceProperties | type: ServiceProperties - name: scheduledDate | type: string | description: Date and time the service is to be provided, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. For example, the start time of a class. - name: numberOfParticipants | type: integer | description: The number of people participating in the service. For example, the number of people attending a class or the number of people per hotel room. Return type: ChargeMembershipResponse - name: transactionId | type: string | description: The transaction GUID for this charge. Use this GUID to void the charge. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MEMBERSHIP_DOES_NOT_APPLY_TO_ITEM | Description: The membership was found, but does not apply for the provided item HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: MEMBERSHIP_ALREADY_CHARGED | Description: This charge was already done, per the idempotency key of membershipId + orderId + rootCatalogItemId HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MEMBERSHIP_CANNOT_BE_CHARGED | Description: The membership was found, applied to the provided item but cannot be charged. For example because a limited membership doesn't have enough credits ``` ### Examples ### Charge Membership ```curl curl -X POST \ 'https://provider.example.com/v1/charge-membership' \ -H 'user-agent: Wix' \ -H 'accept-encoding: gzip, deflate' \ -H 'content-type: text/plain; charset=utf-8' \ --data-binary '{ "memberId": "79b755c4-2033-4a90-90ac-f5859474bb17", "membershipId": "7c1ff545-95f8-3391-a110-9670f906190c/9bd72a2f-b7fa-4594-8c91-e362d5d279f0", "catalogReference": { "catalogItemId": "68f71a63-d406-49bd-942f-b70865e72d99", "appId": "13d21c63-b5ec-5912-8397-c3a5ddb27a97" }, "rootCatalogItemId": "8e02a329-893c-46d4-9d52-c45aed5ecf32", "idempotencyKey": "7c1ff545-95f8-3391-a110-9670f906190c/9bd72a2f-b7fa-4594-8c91-e362d5d279f0", "additionalData": { "benefitId": "9bd72a2f-b7fa-4594-8c91-e362d5d279f0", "orderId": "7c1ff545-95f8-3391-a110-9670f906190c" } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.memberships.MembershipsSPI.chargeMembership(request, metadata) Description: This method requests that a membership be charged by your app. Method parameters: param name: metadata | type: Context | description: this message is not directly used by any service, it exists to describe the expected parameters that SHOULD be provided to invoked Velo methods as part of open-platform. e.g. SPIs, event-handlers, etc.. NOTE: this context object MUST be provided as the last argument in each Velo method signature. Example: ```typescript export function wixStores_onOrderCanceled({ event, metadata }: OrderCanceledEvent) { ... } ``` - name: requestId | type: string | description: A unique identifier of the request. You may print this GUID to your logs to help with future debugging and easier correlation with Wix's logs. - name: currency | type: string | description: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) 3-letter currency code. - name: identity | type: IdentificationData | description: An object that describes the identity that triggered this request. - ONE-OF: - name: anonymousVisitorId | type: string | description: GUID of a site visitor that has not logged in to the site. - name: memberId | type: string | description: GUID of a site visitor that has logged in to the site. - name: wixUserId | type: string | description: GUID of a Wix user (site owner, contributor, etc.). - name: appId | type: string | description: GUID of an app. - name: languages | type: array | description: A string representing a language and region in the format of `"xx-XX"`. First 2 letters represent the language code according to ISO 639-1. This is followed by a dash "-", and then a by 2 capital letters representing the region according to ISO 3166-2. For example, `"en-US"`. - name: instanceId | type: string | description: The service provider app's instance GUID. param name: request | type: ChargeMembershipRequest - name: memberId | type: string | description: Member GUID. Do not retrieve this from the request context. In some cases the caller is not a member, but a user who is using the membership on behalf of a member. - name: membershipId | type: string | description: Membership GUID, as returned from the List Eligible Memberships call. - name: idempotencyKey | type: string | description: Idempotency key to avoid duplicate charge. The value will usually would be the same as `membershipId` + `orderId` + `rootCatalogItemId`. - name: serviceProperties | type: ServiceProperties | description: Service properties. When relevant, this contains information such as date and number of participants. - name: scheduledDate | type: Date | description: Date and time the service is to be provided, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) format. For example, the start time of a class. - name: numberOfParticipants | type: integer | description: The number of people participating in the service. For example, the number of people attending a class or the number of people per hotel room. - name: catalogReference | type: CatalogReference | description: Catalog and item reference info. - name: catalogItemId | type: string | description: GUID of the item within the catalog it belongs to. - name: appId | type: string | description: GUID of the app providing the catalog. You can get your app's GUID from its page in the [app dashboard](https://dev.wix.com/dc3/my-apps/). For items from Wix catalogs, the following values always apply: + Wix Stores: `"215238eb-22a5-4c36-9e7b-e7c08025e04e"` + Wix Bookings: `"13d21c63-b5ec-5912-8397-c3a5ddb27a97"` + Wix Restaurants: `"9a5d83fd-8570-482e-81ab-cfa88942ee60"` - name: options | type: object | description: Additional item details in `key:value` pairs. Use this optional field for more specificity with item selection. The values of the `options` field differ depending on which catalog is providing the items. For Wix Stores products, learn more about integrating with [Catalog V3](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/e-commerce-integration.md) or [Catalog V1](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/e-commerce-integration.md), depending on [the version the site uses](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-versioning/introduction.md). - name: rootCatalogItemId | type: string | description: Root catalog item GUID. The value will usually be the same as `catalogReference.catalogItemId`. In cases when these are not the same, this field will return the actual GUID of the item in the catalog. For example, for Wix bookings, the value of `catalogReference.catalogItemId` is the booking GUID, but `rootCatalogItemId` is set to the service GUID. - name: additionalData | type: object | description: Additional data about this charge. Return type: PROMISE - name: transactionId | type: string | description: The transaction GUID for this charge. Use this GUID to void the charge. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: MEMBERSHIP_DOES_NOT_APPLY_TO_ITEM | Description: The membership was found, but does not apply for the provided item HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: MEMBERSHIP_ALREADY_CHARGED | Description: This charge was already done, per the idempotency key of membershipId + orderId + rootCatalogItemId HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MEMBERSHIP_CANNOT_BE_CHARGED | Description: The membership was found, applied to the provided item but cannot be charged. For example because a limited membership doesn't have enough credits ``` ### Examples ### chargeMembership ```javascript import { memberships } from '@wix/ecom/service-plugins'; async function chargeMembership(request,metadata) { const response = await memberships.chargeMembership(request,metadata); }; ``` ### chargeMembership (with elevated permissions) ```javascript import { memberships } from '@wix/ecom/service-plugins'; import { auth } from '@wix/essentials'; async function myChargeMembershipMethod(request,metadata) { const elevatedChargeMembership = auth.elevate(memberships.chargeMembership); const response = await elevatedChargeMembership(request,metadata); } ``` ### chargeMembership (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { memberships } from '@wix/ecom/service-plugins'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { memberships }, // Include the auth strategy and host as relevant }); async function chargeMembership(request,metadata) { const response = await myWixClient.memberships.chargeMembership(request,metadata); }; ``` ---