Create
1 min
To create a Subscription in the Square, use the action “CreateSubscription” and pass the Subscription data in the RequestJSON under “subscriptions.”
Note: You can only create one record at a time.
Here is an example of creating a Subscription where we are setting every possible field(See Subscription - Square for all the available fields). The response will return the response from Square, which includes the Subscription ID (internalId) plus the newly created Salesforce Subscription ID (salesforceId).
Map<String, Object> subscriptionData = new Map<String, Object>();
// Required fields
subscriptionData.put('processorCustomerId', 'processorCustomerId'); //required
subscriptionData.put('locationId', 'locationId'); //required to Square, if not specified we are sending a request to Square to get the main Square location id.
subscriptionData.put('processorPlanId', 'processorPlanId'); //required
// Optional fields
subscriptionData.put('processorPaymentMethodId', 'processorPaymentMethodId'); // If not specified, the collection method will be considered “send_invoice”.
subscriptionData.put('startDate', 'startDate');
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('subscriptions', new List<Object>{subscriptionData});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version','1.0');
reqObj.put('action','CreateSubscription');
reqObj.put('processorId', 'processorId');
reqObj.put('requestJSON',reqJSON);
// Placing a request to Breadwinner Global API
Map<String,Object> resp = bw_payments.BreadwinnerPaymentsAPI.call(reqObj);
System.debug(resp);