Exemple #1
1
 public function cancelSubscription()
 {
     // Common Set Up for API Credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName(config('subscription.API_LOGIN_ID'));
     $merchantAuthentication->setTransactionKey(config('subscription.TRANSACTION_KEY'));
     $request = new AnetAPI\ARBCancelSubscriptionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     /*$request->setRefId($refId);*/
     $request->setSubscriptionId($this->getPayload()->subscriptionId);
     $controller = new AnetController\ARBCancelSubscriptionController($request);
     $this->setResponse($controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX));
     if ($this->getResponse() != null && $this->getResponse()->getMessages()->getResultCode() == "Ok") {
         return $this->getResponse();
     } else {
         throw new PaymentErrorException($this->getResponse()->getMessages()->getMessage()[0]->getText());
     }
 }
<?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 Set Up for API Credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("556KThWQ6vf2");
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
$refId = 'ref' . time();
$request = new AnetAPI\ARBCancelSubscriptionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setSubscriptionId("100748");
$controller = new AnetController\ARBCancelSubscriptionController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    echo "SUCCESS" . $response->getMessages()->getMessage()[0]->getCode() . "  " . $response->getMessages()->getMessage()[0]->getText() . "\n";
} else {
    echo "ERROR :  Invalid response\n";
    echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . "  " . $response->getMessages()->getMessage()[0]->getText() . "\n";
}
Exemple #3
0
 function cancelSubscription($subscriptionId)
 {
     // Common Set Up for API Credentials
     $merchantAuthentication = $this->authorize();
     $refId = 'ref' . time();
     $request = new AnetAPI\ARBCancelSubscriptionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setSubscriptionId($subscriptionId);
     $controller = new AnetController\ARBCancelSubscriptionController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
     if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
         return true;
     } else {
         echo "ERROR :  Invalid response\n";
         $errorMessages = $response->getMessages()->getMessage();
         echo "Response : " . $errorMessages[0]->getCode() . "  " . $errorMessages[0]->getText() . "\n";
         return false;
     }
 }