コード例 #1
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();
 }
コード例 #2
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);