PHP Classes

File: examples/cim/createCustomerShippingAddressRequest.php

Recommend this page to a friend!
  Classes of John Conde   PHP Authorize.net Integration with JSON API   examples/cim/createCustomerShippingAddressRequest.php   Download  
File: examples/cim/createCustomerShippingAddressRequest.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: Removed style="text/css" from examples
Updated namespacing to be PSR-0/4 compliant
Improved example to show how more data is accessed
Date: 1 year ago
Size: 3,456 bytes
 

Contents

Class file image Download
<?php
/*************************************************************************************************

Use the CIM JSON API to create a shipping profile

SAMPLE REQUEST
--------------------------------------------------------------------------------------------------
{
   "createCustomerShippingAddressRequest":{
      "merchantAuthentication":{
         "name":"",
         "transactionKey":""
      },
      "customerProfileId":"31390172",
      "address":{
         "firstName":"John",
         "lastName":"Doe",
         "company":"",
         "address":"123 Main St.",
         "city":"Bellevue",
         "state":"WA",
         "zip":"98004",
         "country":"USA",
         "phoneNumber":"800-555-1234",
         "faxNumber":"800-555-1234"
      }
   }
}

SAMPLE RESPONSE
--------------------------------------------------------------------------------------------------
{
   "customerAddressId":"29870028",
   "messages":{
      "resultCode":"Ok",
      "message":[
         {
            "code":"I00001",
            "text":"Successful."
         }
      ]
   }
}

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

namespace Authnetjson;

use
Exception;

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

try {
   
$request = AuthnetApiFactory::getJsonApiHandler(
       
AUTHNET_LOGIN,
       
AUTHNET_TRANSKEY,
       
AuthnetApiFactory::USE_DEVELOPMENT_SERVER
   
);
   
$response = $request->createCustomerShippingAddressRequest([
       
'customerProfileId' => '31390172',
       
'address' => [
           
'firstName' => 'John',
           
'lastName' => 'Doe',
           
'company' => '',
           
'address' => '123 Main St.',
           
'city' => 'Bellevue',
           
'state' => 'WA',
           
'zip' => '98004',
           
'country' => 'USA',
           
'phoneNumber' => '800-555-1234',
           
'faxNumber' => '800-555-1234'
       
]
    ]);
} catch (
Exception $e) {
    echo
$e;
    exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>CIM :: Create Shipping Profile</title>
    <style>
        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>
        CIM :: Create Shipping Profile
    </h1>
    <h2>
        Results
    </h2>
    <table>
        <tr>
            <th>Successful?</th>
            <td><?= $response->isSuccessful() ? 'yes' : 'no' ?></td>
        </tr>
        <tr>
            <th>Error?</th>
            <td><?= $response->isError() ? 'yes' : 'no' ?></td>
        </tr>
        <tr>
            <th>Result Code</th>
            <td><?= $response->messages->resultCode ?></td>
        </tr>
        <tr>
            <th>Message Code</th>
            <td><?= $response->messages->message[0]->code ?></td>
        </tr>
        <tr>
            <th>Message</th>
            <td><?= $response->messages->message[0]->text ?></td>
        </tr>
        <?php if ($response->isSuccessful()) : ?>
<tr>
            <th>Customer Address ID</th>
            <td><?= $response->customerAddressId ?></td>
        </tr>
        <?php endif; ?>
</table>
    <h2>
        Raw Input/Output
    </h2>
    <?= $request, $response ?>
</body>
</html>