cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Subscription Transactions?

Is there any API to get a list of transactions for a given subscription id?  Maybe I totally missed it, but I don't see and API to do this.

 

As an alternative, it looks like I can load the subscription to get the customerProfileId and payentProfileId, call getTransactionListForCustomerRequest(customerProfileId, paymentProfileId), loop over the transactions returned in the response, and evaluate if transaction.subscription.id is equal to the subsciptionId I am looking for.  Furthermore, getTransactionListForCustomerRequest() uses paging, so I may need to call that API multiple times to get the collection of transactions for a subscription.

 

Seems like there should be an easier way to get the list of transactions for a subscription?

 

 

Thanks!

dnsBuffaloNY
Contributor
15 REPLIES 15

Any updates on retrieving transactions (including ARB transactions) for a subscription? I would like to atleast know the status and time frame we should expect this.

Any updates on getting transactions (including ARB transactions) for subscriptions? We are implementing ARB and it would be nice to know atleast a time frame on when we should expect a solution.

Hello  @Aaron

 

Any update on this? Seems there are many Community members waiting on your reply to your original offer of help back on June 6, 2017:

https://community.developer.authorize.net/t5/Integration-and-Testing/Subscription-Transactions/m-p/5...

 

And as Jan 2018, seems there's still issues with how to get transaction details from subscription API. See https://community.developer.authorize.net/t5/Ideas/Subscription-Transactions/idc-p/61397/highlight/t...

 

Please Authorize.Net, help the members of your development community!

Hey there  we recently updated out GetSubscription to provide just this feature:  https://developer.authorize.net/api/reference/index.html#recurring-billing-get-subscription

 

Just pass true for includeTransactions on your request and you'll get back the 20 most recent transactions for that subscription.

 

Please mark this as the solution if this meets your requirement as it should override the previous workaround solution.

 

Brian

Hey @brianmc

 

I have seen the documentation for the updated GetSubscription functionality. However, the sample PHP code referenced in the documentation (https://github.com/AuthorizeNet/sample-code-php/blob/master/RecurringBilling/get-subscription.php) t...

 

I and others have been struggling to get it to work; as can been seen in the following github issues:
https://github.com/AuthorizeNet/sdk-php/issues/280

https://github.com/AuthorizeNet/sample-code-php/issues/102

 

Can you provide working sample PHP code?

 

<?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");

function getSubscription($subscriptionId)
{
    /* Create a merchantAuthenticationType object with authentication details
       retrieved from the constants file */
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
    
    // Set the transaction's refId
    $refId = 'ref' . time();
		
		// Creating the API Request with required parameters
		$request = new AnetAPI\ARBGetSubscriptionRequest();
		$request->setMerchantAuthentication($merchantAuthentication);
		$request->setRefId($refId);
		$request->setSubscriptionId($subscriptionId);
                $request->setIncludeTransactions(true); //THROWS ERROR
		
		// Controller
		$controller = new AnetController\ARBGetSubscriptionController($request);
		
		// Getting the response
		$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
		
		if ($response != null) 
		{
			if($response->getMessages()->getResultCode() == "Ok")
			{
				// Success
				echo "SUCCESS: GetSubscription:" . "\n";
				// Displaying the details
				echo "Subscription Name: " . $response->getSubscription()->getName(). "\n";
				echo "Subscription amount: " . $response->getSubscription()->getAmount(). "\n";
				echo "Subscription status: " . $response->getSubscription()->getStatus(). "\n";
				echo "Subscription Description: " . $response->getSubscription()->getProfile()->getDescription(). "\n";
				echo "Customer Profile ID: " .  $response->getSubscription()->getProfile()->getCustomerProfileId() . "\n";
				echo "Customer payment Profile ID: ". $response->getSubscription()->getProfile()->getPaymentProfile()->getCustomerPaymentProfileId() . "\n";
			}
			else
			{
				// Error
				echo "ERROR :  Invalid response\n";	
				$errorMessages = $response->getMessages()->getMessage();
                echo "Response : " . $errorMessages[0]->getCode() . "  " .$errorMessages[0]->getText() . "\n";
			}
		}
		else
		{
			// Failed to get response
			echo "Null Response Error";
		}

		return $response;
	}

	if(!defined('DONT_RUN_SAMPLES'))
		getSubscription("2930242");
 ?>

 

I suspect that includeTransactions support has been implemented in the underlying Authorize.net API; however, the PHP SDK is woefully out of date. And no sample code has been forthcoming from Authorize.net (earliest request is from June 2016)

 

So, for my purposes, I forked the PHP SDK:
https://github.com/sjordan1975/sdk-php

 

I implemented get ARB Transaction from Get Subscription sufficient for what I needed.

 

Specifically, I modified the following 4 files:
lib/net/authorize/api/contract/v1/ARBGetSubscriptionRequest.php
lib/net/authorize/api/contract/v1/ARBSubscriptionMaskedType.php
lib/net/authorize/api/yml/v1/ARBGetSubscriptionRequest.yml
lib/net/authorize/api/yml/v1/ARBSubscriptionMaskedType.yml

 

Immediately after setting setSubscriptionID in the sample code (https://github.com/AuthorizeNet/sample-code-php/blob/master/RecurringBilling/get-subscription-status...) add the following:

 

$request->setIncludeTransactions(true);

Note: I have used TransactionDetailsType whereas I suspect the actual type should be something like ARBTransactionType, but the yaml definition is missing and I have not defined it

The result is for now is not all transaction data is populated; HOWEVER, transId IS populated and this is good enough to make an additional API call to get Transaction Details.

 

Feel free to have at it. Code provided AS IS to the Community. YMMV