Export Subscription

This function can be used to export and check the current subscriptions. It returns a list of the subscriptions whose state expired (became canceled, finished or unpaid) between startDate and endDate. In case the allSubscriptions field is set to 1, startDate and endDate refer to the initial subscription (transaction) date.


Endpoints

HTTP Method API URL API Version
GET https://api.payzone.ma/subscriptions >= 002

Accepted parameters

Field Type Max Length Required Description Version
startDate String 20 yes Retrieve subscriptions on or after the startDate. In Unix Timestamp
endDate String 20 yes Retrieve subscriptions on or before the endDate. In Unix Timestamp
allSubscriptions Integer 1 no Whether or not to export all Subscriptions instead of only the expired ones (0 or 1 to export all - default 0). >=203

Code samples

Note: Gateway API transactions are done with a different library than payment-page API. See the code sample comments for more info:

   
    /*
    *   Transaction name is 'ExportSubscription', once you create a new transaction passing this as parameter, 
    *   you need to set the mandatory data using the following method:
    *    setExportInterval()
    */

    $client = new GatewayClient();

    $transaction = $client->newTransaction('ExportSubscription', 'testMerchant', 'testPassword');
    $transaction->setExportInterval(time() - 3600, time());  //1 hour window
    $transaction->setExportAllSubscriptions(1); // Export all subscriptions created one hour ago

    $response = $transaction->send();

    if ('000' === $response->errorCode) {
        $subscriptionList = $response->subscriptionList;
    } else {
        echo "Error {$response->errorCode} with message {$response->errorMessage}";
    }
                      
   
    PaymentGatewayConnector connector = new PaymentGatewayConnector(API_URL, ORIGINATOR, PASSWORD);

    SubscriptionsExportResponse response = null;
    SubscriptionsExportRequest request = new SubscriptionsExportRequest();

    Calendar cal = new GregorianCalendar();
    cal.add(Calendar.HOUR, -1);
    request.setStartDate(cal.getTime()).setEndDate(new Date());
    request.setAllSubscriptions(true);

    try {
        response = connector.getSubscriptionsExport(request);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (response != null) {
        if (TransactionResultCode.TRANSACTION_SUCCESSFULLY.equals(response.getErrorCode()) {
        System.out.println("Success: " + response.getErrorMessage());
        } else {
        System.out.println("Failure: " + response.getErrorMessage());
        }
    }
                      
   
    const gateway = require("payxpert")("123456", "GreatP4ssw0rd").gateway;
    let currentTimestamp = Math.floor(Date.now() / 1000);

    let requestBody = {
        startDate: currentTimestamp - (3600 * 5),
        endDate: currentTimestamp + (3600 * 5)
    };

    let responseExportSubscriptions = await gateway.exportSubscriptionsList(requestBody);

    if (responseExportSubscriptions.code == "000") {
        // Success
    }

        
   
    var client = new GatewayClient(OriginatorConfig.ORIGINATOR_ID, OriginatorConfig.ORIGINATOR_PASSWORD);
    var exportSubscriptions = client.NewExportSubscriptionsListTransaction(DateTime.UtcNow.AddMonths(-1), DateTime.UtcNow, true);
    var subscriptions = await exportSubscriptions.Send();

    Console.WriteLine("Total number of retrieved subscriptions: " + subscriptions.subscriptionList.Count.ToString());

    // subscriptions object could be iterated for future processing

    

Response

The body of the response is in JSON format.

The following fields are present in the response :


Name Type Description
errorCode String See API Response Codes
errorMessage String See API Response Codes
subscriptionList Object List (array) of Subscription objects (see Subscription object)

© Payzone | 2023