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

setLineItems and setLineItem private API function examples missing #116

Closed zeshanb closed 6 years ago

zeshanb commented 6 years ago

Hi there,

Please update the following sample-code-php example to include examples of private function calls needed to create lineItems:

sample-code-php/PaymentTransactions/get-an-accept-payment-page.php

During creation of transaction before requesting a hosted payment page. To add Lineitems to customer order, the private function examples are missing.

["order":"net\authorize\api\contract\v1\TransactionRequestType":private]=> NULL ["lineItems":"net\authorize\api\contract\v1\TransactionRequestType":private]

order->Lineitems is only superficially referenced in API documentation located here: https://developer.authorize.net/api/reference/index.html#payment-transactions-create-an-accept-payment-transaction

There is only a python sdk example at the moment: https://community.developer.authorize.net/t5/Integration-and-Testing/Adding-lineItems-in-python-sdk/m-p/59737/highlight/true#M34315

When trying to do the following:

        $lineItem1 = array();
        $lineItem1["itemId"] = "12345";
    $lineItem1["name"] = "first";
    $lineItem1["description"] = "Here's the first line item";
    $lineItem1["quantity"] = "2";
    $lineItem1["unitPrice"] = "7.99";

    $lineItems = array();
    $lineItems[] = $lineItem1;

        $transactionRequestType->setLineItems($lineItems);

API responds with this error:

PHP Fatal error: Call to a member function getItemId() on array

There seems to be private functions designated in API for this purpose but are not documented.

Thank you, Zeshan

ashtru commented 6 years ago
  1. What is the type of your create transaction request?

  2. All of the fields in PHP SDK are private. If a field is supposed to be set in a request, appropriate setter is present. (See for reference: a. In TransactionRequestType , lineItems is defined as private . b. setLineItems setter is defined for lineItems. c. Similarly, you can create a lineItem object based on LineItemType.php

  3. LineItems is an array. A lineItem, in itself is an object. Hence similar to the python example, the object attributes need to be assigned. For each attribute, the respective setter method need to be used.

Can you try using something like below:

     $lineItem1 = new AnetAPI\LineItemType();
     $lineItem1->setItemId("12345");
     $lineItem1->setName("first");
     $lineItem1->setDescription("Here's the first line item");
     $lineItem1->setQuantity(2);
     $lineItem1->setUnitPrice("7.99");
     $lineItems[0] = $lineItem1;

      //create a transaction
      $transactionRequestType = new AnetAPI\TransactionRequestType();
      $transactionRequestType->setTransactionType( "authCaptureTransaction"); 
      $transactionRequestType->setAmount($amount);
      $transactionRequestType->setOrder($order);
      $transactionRequestType->setPayment($paymentOne);
      $transactionRequestType->setLineItems($lineItems);

I have based it on the charge-credit-card sample.

gnongsie commented 6 years ago

An easier implementation would be this:

    $lineItem1 = new AnetAPI\LineItemType();
    $lineItem1->setItemId("12345");
    $lineItem1->setName("first");
    $lineItem1->setDescription("Here's the first line item");
    $lineItem1->setQuantity("2");
    $lineItem1->setUnitPrice("7.99");

    $transactionRequestType->addToLineItems($lineItem1);

I've tested this and it works perfectly well.

zeshanb commented 6 years ago

Thank you, setting the variable to the provided settype function worked.

$lineItem1 = new AnetAPI\LineItemType();

My concern is that these functions aren't referenced in API reference doc. For example only lineitem is mentioned.

Thank you very much for this response to my inquiry.

Regards,

Zeshan

On Thu, Jul 12, 2018, 12:57 PM Gabriel Broadwin Nongsiej < notifications@github.com> wrote:

An easier implementation would be this:

$lineItem1 = new AnetAPI\LineItemType();
$lineItem1->setItemId("12345");
$lineItem1->setName("first");
$lineItem1->setDescription("Here's the first line item");
$lineItem1->setQuantity("2");
$lineItem1->setUnitPrice("7.99");

$transactionRequestType->addToLineItems($lineItem1);

I've tested this and it works perfectly well.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AuthorizeNet/sample-code-php/issues/116#issuecomment-404579868, or mute the thread https://github.com/notifications/unsubscribe-auth/AGXRY-eczN9yS5Z6axnDEErqGITiLS4Oks5uF3_ygaJpZM4VM5Md .

gnongsie commented 6 years ago

Hi Zeshan,

We're sorry for the inconvenience. We will relay this information to the relevant teams and have them carry it forward.

Do let us know if you have any other issues. If your issues are resolved, kindly close this issue.

zeshanb commented 6 years ago

HI @gnongsie,

Just to confirm, is the following correct understanding of what variables have this type function name designation?

element function
order $your-holder = new AnetAPI\OrderType();
tax $your-holder = new AnetAPI\TaxType();
duty $your-holder = new AnetAPI\DutyType();
customer $your-holder = new AnetAPI\CustomerType();
billTo $your-holder = new AnetAPI\BillToType();
.. ..

In reference to API doc located here: https://developer.authorize.net/api/reference/index.html#payment-transactions-create-an-accept-payment-transaction

Regards, Zeshan

gnongsie commented 6 years ago

Hi @zeshanb,

For further information, kindly refer to our PHP SDK. For your particular request, you can find further information of the fields here for Creating an Accept Payment Request and here for Getting a Hosted Payment Page Request.

zeshanb commented 6 years ago

Thank you @gnongsie and @ashtru