コード例 #1
0
<?php

require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("556KThWQ6vf2");
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
$refId = 'ref' . time();
//Use an existing profile id
$existingcustomerprofileid = "35858366";
// Retrieve an existing customer profile along with all the associated payment profiles and shipping addresses
$request = new AnetAPI\GetCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setCustomerProfileId($existingcustomerprofileid);
$controller = new AnetController\GetCustomerProfileController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    //   echo "SUCCESS: PROFILE RETRIEVED : " . $response->getProfile() . "\n";
    $getcustomerprofileid = $response->getProfile();
} else {
    echo "GetCustomerProfileRequest ERROR :  Invalid response\n";
}
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4012888818888");
$creditCard->setExpirationDate("2038-11");
$paymentCreditCard = new AnetAPI\PaymentType();
$paymentCreditCard->setCreditCard($creditCard);
コード例 #2
0
ファイル: Authnet.php プロジェクト: AndreyTepaykin/Platform
 /**
  * Executes some API calls and obtains a payment profile id
  * @method paymentProfileId
  * @return {string} The payment profile id
  */
 function paymentProfileId($customerId)
 {
     $options = $this->options;
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName($options['authname']);
     $merchantAuthentication->setTransactionKey($options['authkey']);
     $request = new AnetAPI\GetCustomerProfileRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setCustomerProfileId($customerId);
     $controller = new AnetController\GetCustomerProfileController($request);
     $response = $controller->executeWithApiResponse($options['server']);
     if (!isset($response) or $response->getMessages()->getResultCode() != "Ok") {
         $messages = $response->getMessages()->getMessage();
         $message = reset($messages);
         throw new Assets_Exception_InvalidResponse(array('response' => $message->getCode() . ' ' . $message->getText()));
     }
     $profileSelected = $response->getProfile();
     $paymentProfilesSelected = $profileSelected->getPaymentProfiles();
     if ($paymentProfilesSelected == null) {
         throw new Assets_Exception_PaymentMethodRequired();
     }
     return $paymentProfilesSelected[0]->getCustomerPaymentProfileId();
 }
コード例 #3
0
    echo "ERROR :  CreateCustomerProfile: Invalid response\n";
}
// Update an existing customer profile
$updatecustomerprofile = new AnetAPI\CustomerProfileExType();
$updatecustomerprofile->setCustomerProfileId($profileidcreated);
$updatecustomerprofile->setDescription("Updated existing Profile Request");
$updatecustomerprofile->setEmail("*****@*****.**");
$request = new AnetAPI\UpdateCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setProfile($updatecustomerprofile);
$controller = new AnetController\UpdateCustomerProfileController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    echo "UpdateCustomerProfile SUCCESS : " . "\n";
    // Validate the description and e-mail that was updated
    $request = new AnetAPI\GetCustomerProfileRequest();
    $request->setMerchantAuthentication($merchantAuthentication);
    $request->setCustomerProfileId($profileidcreated);
    $controller = new AnetController\GetCustomerProfileController($request);
    $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
    if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
        echo "Get updated CustomerProfile  SUCCESS : " . "\n";
        $profileselected = $response->getProfile();
        echo "Updated Customer Profile Customer description : " . $profileselected->getDescription() . "\n";
        echo "Updated Customer Profile EMail description : " . $profileselected->getEmail() . "\n";
    } else {
        echo "ERROR :  GetCustomerProfile: Invalid response\n";
        echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . "  " . $response->getMessages()->getMessage()[0]->getText() . "\n";
    }
} else {
    echo "ERROR :  UpdateCustomerProfile: Invalid response\n";