AuthorizeNet / sample-code-php

This repository contains working code samples which demonstrate php integration with the Authorize.Net API
MIT License
175 stars 197 forks source link

How do you set 'includeTransactions'? #102

Closed sjordan1975 closed 6 years ago

sjordan1975 commented 6 years ago

The AuthorizeNet documentation references being able to set includeTransactions property:

[BOOLEAN] Indicates whether to include information about transactions for this subscription.

If set to true, information about the most recent 20 transactions for this subscription will be included in the response.

How is this done with the SDK?

Similar to #280

Thank you

enterlight commented 6 years ago

Could somebody paste the required code to get the recent transactions from the Get Subscription SDK call?

enterlight commented 6 years ago

@sjordan1975 I fiddled and fiddled and ended up making a php curl call using json just for that specific request. I will look at your forked project. Thanks for your help

sjordan1975 commented 6 years ago

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.php) 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 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

brianmc commented 6 years ago

This is coming soon in the SDKs and we'll make sure to include it in sample code as well. We're trying to keep not more than a month behind API updates but the latest release has been a little delayed.

ashtru commented 6 years ago

includeTransactions has been added to the ARBGetSubscription request as part of the latest release! Kindly change your composer.json to use version 1.9.5 of authorizenet/authorizenet similar to the sample code composer.

sjordan1975 commented 6 years ago

@ashtru Thank you. I'll check it out.

It would also be nice to update the sample code to demonstrate how to use this functionality.

ashtru commented 6 years ago

Thanks @sjordan1975 . The sample code is updated.

Happy Coding! Authorize.Net

sjordan1975 commented 6 years ago

Hi @ashtru I see you updated the sample code to set setIncludeTransactions to true

I think it would be helpful to update the section of code which displays results...

Example

Current code snippet:

{
    // 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";
}

I suggest something like the follow (see comments inline):

{
    // 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";

    echo "Previous transactions: " . "\n";
    // INSERT EXAMPLE LOOP OVER TRANSACTIONS RETURNED FROM CALL TO ARBGetSubscriptionRequest
}

The goal is to help future devs as much as possible; you want to make it easy for people to use and want to use the SDK (IMHO)

I integrated the updated code into my codebase and it's working. Thank you. However ...

I noticed that from the documentation for arbTransaction:

* response 
* Contains explanatory text about the transaction.  
* String.For example, "The credit card has expired."

There is no success flag/code for payment. If I want to know if a payment was actually successful, I have to check the value of response which is This transaction has been approved. on success.

This seems very fragile and prone to potential error if the SDK message changes even slightly in the future. I might suggest a success code of some kind.

ashtru commented 6 years ago

Thanks again for the suggestion, @sjordan1975 . @kikmak42 has updated the sample code .

Happy Coding! Authorize.Net