Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setLineItems and setLineItem private API function examples missing #116

Closed
zeshanb opened this issue Jul 12, 2018 · 7 comments
Closed

setLineItems and setLineItem private API function examples missing #116

zeshanb opened this issue Jul 12, 2018 · 7 comments

Comments

@zeshanb
Copy link

zeshanb commented Jul 12, 2018

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
Copy link
Contributor

ashtru commented Jul 12, 2018

  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
Copy link
Contributor

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
Copy link
Author

zeshanb commented Jul 13, 2018 via email

@gnongsie
Copy link
Contributor

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
Copy link
Author

zeshanb commented Jul 16, 2018

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
Copy link
Contributor

Hi @zeshanb,

  • The field "order" is of AnetApi\OrderType.
  • Any tax or duty amount is of AnetApi\ExtendedAmountType.
  • The "billTo" field is of AnetApi\CustomerAddressType.
  • The "shipTo" field is of AnetApi\NameAndAddressType.

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
Copy link
Author

zeshanb commented Jul 16, 2018

Thank you @gnongsie and @ashtru

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants