PHP Classes

File: examples/arb/ARBGetSubscriptionListRequest.php

Recommend this page to a friend!
  Classes of John Conde   PHP Authorize.net Integration with JSON API   examples/arb/ARBGetSubscriptionListRequest.php   Download  
File: examples/arb/ARBGetSubscriptionListRequest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Authorize.net Integration with JSON API
Process online payments with Authorize.net API
Author: By
Last change:
Date: 4 years ago
Size: 5,539 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of the AuthnetJSON package.
 *
 * (c) John Conde <stymiee@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/*************************************************************************************************

You can use the following method to request a list of subscriptions. The function will return up to 1000 results in a
single request. Paging options can be sent to limit the result set or to retrieve additional results beyond the
1000 item limit. You can add the sorting and paging options shown below to customize the result set.

SAMPLE REQUEST
--------------------------------------------------------------------------------------------------
{
    "ARBGetSubscriptionListRequest": {
        "merchantAuthentication": {
            "name": "",
            "transactionKey": ""
        },
        "refId": "123456",
        "searchType": "subscriptionActive",
        "sorting": {
            "orderBy": "id",
            "orderDescending": "false"
        },
        "paging": {
            "limit": "1000",
            "offset": "1"
        }
    }
}

SAMPLE RESPONSE
--------------------------------------------------------------------------------------------------
{
    "totalNumInResultSet": 1273,
    "totalNumInResultSetSpecified": true,
    "subscriptionDetails": [
        {
            "id": 100188,
            "name": "subscription",
            "status": "canceled",
            "createTimeStampUTC": "2004-04-28T23:59:47.33",
            "firstName": "Joe",
            "lastName": "Tester",
            "totalOccurrences": 12,
            "pastOccurrences": 6,
            "paymentMethod": "creditCard",
            "accountNumber": "XXXX5454",
            "invoice": "42820041325496571",
            "amount": 10,
            "currencyCode": "USD"
        },
        {
            "id": 100222,
            "name": "",
            "status": "canceled",
            "createTimeStampUTC": "2004-10-22T21:00:15.503",
            "firstName": "asdf",
            "lastName": "asdf",
            "totalOccurrences": 12,
            "pastOccurrences": 0,
            "paymentMethod": "creditCard",
            "accountNumber": "XXXX1111",
            "invoice": "",
            "amount": 1,
            "currencyCode": "USD"
        },
        {
            "id": 100223,
            "name": "",
            "status": "canceled",
            "createTimeStampUTC": "2004-10-22T21:01:27.69",
            "firstName": "asdf",
            "lastName": "asdf",
            "totalOccurrences": 12,
            "pastOccurrences": 1,
            "paymentMethod": "eCheck",
            "accountNumber": "XXXX3888",
            "invoice": "",
            "amount": 10,
            "currencyCode": "USD"
        }
    ],
    "refId": "123456",
    "messages": {
        "resultCode": "Ok",
        "message": [
            {
                "code": "I00001",
                "text": "Successful."
            }
        ]
    }
}

*************************************************************************************************/

namespace JohnConde\Authnet;

use
Exception;

require
'../../config.inc.php';

try {
   
$request = AuthnetApiFactory::getJsonApiHandler(
       
AUTHNET_LOGIN,
       
AUTHNET_TRANSKEY,
       
AuthnetApiFactory::USE_DEVELOPMENT_SERVER
   
);
   
$response = $request->ARBGetSubscriptionListRequest([
       
'refId' => '123456',
       
'searchType' => 'subscriptionActive',
       
'sorting' => [
       
'orderBy' => 'id',
           
"orderDescending" => 'false'
       
],
       
'paging' => [
           
'limit' => '1000',
           
'offset' => '1'
       
]
    ]);
} catch (
Exception $e) {
    echo
$e;
    exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>ARB :: Get Subscription List</title>
    <style type="text/css">
        table { border: 1px solid #cccccc; margin: auto; border-collapse: collapse; max-width: 90%; }
        table td { padding: 3px 5px; vertical-align: top; border-top: 1px solid #cccccc; }
        pre { white-space: pre-wrap; }
        table th { background: #e5e5e5; color: #666666; }
        h1, h2 { text-align: center; }
    </style>
</head>
<body>
    <h1>
        ARB :: Get Subscription List
    </h1>
    <h2>
        Results
    </h2>
    <table>
        <tr>
            <th>Response</th>
            <td><?= $response->messages->resultCode ?></td>
        </tr>
        <tr>
            <th>Successful?</th>
            <td><?= $response->isSuccessful() ? 'yes' : 'no' ?></td>
        </tr>
        <tr>
            <th>Error?</th>
            <td><?= $response->isError() ? 'yes' : 'no' ?></td>
        </tr>
        <tr>
            <th>Code</th>
            <td><?= $response->messages->message[0]->code ?></td>
        </tr>
        <tr>
            <th>Message</th>
            <td><?= $response->messages->message[0]->text ?></td>
        </tr>
        <tr>
            <th>Number of subscriptions</th>
            <td><?= $response->totalNumInResultSet ?></td>
        </tr>
        <tr>
            <th>Profile IDs</th>
            <td>
                <?php foreach ($response->subscriptionDetails as $subscription) : ?>
<?php printf('ID: %u Status: %s %s', $subscription->id, $subscription->status, '<br/>') ?>
<?php endforeach; ?>
</td>
        </tr>
    </table>
    <h2>
        Raw Input/Output
    </h2>
<?= $request, $response ?>
</body>
</html>