intuit / QuickBooks-V3-PHP-SDK

Official PHP SDK for QuickBooks REST API v3.0: https://developer.intuit.com/
Apache License 2.0
245 stars 246 forks source link

What should these actually be returning #388

Open GameCharmer opened 3 years ago

GameCharmer commented 3 years ago

in src/DataService/DataService.php L793

    /**
     * Creates an entity under the specified realm. The realm must be set in the context.
     *
     * @param IPPIntuitEntity $entity Entity to Create.
     * @return IPPIntuitEntity Returns the created version of the entity.
     * @throws IdsException
     */
    public function Add($entity)
    {
        ........
        return $this->sendRequestParseResponseBodyAndHandleHttpError($entity, $uri, $httpsPostBody, DataService::ADD);
    }

in src/DataService/DataService.php L635

        /**
     *  Using the @entity and @uri to generate Request.
     *  Response will parsed. It will store any Error Code in 3xx to 5xx level.
     *
     * @param ...
     * @return null|string
     */
    private function sendRequestParseResponseBodyAndHandleHttpError($entity, $uri, $httpsPostBody, $CALLINGMETHOD, $boundaryString = null, $email = null)
    {...}

The Add method is returning Boolean FALSE. Add says it's only returning IPPIntuitEntity, the method it's directly returning says it's only returning null or string. What are my actual options here?

abisalehalliprasan commented 3 years ago

@GameCharmer : Did you pass the Entity which is of the type IPPIntuitEntity to Add method? The Add method of the DataService object should return IPPIntuitEntity of the entity that was created. Take a look at the Samples folder if you haven't already : https://github.com/intuit/QuickBooks-V3-PHP-SDK/blob/master/src/_Samples/ItemCreation.php

GameCharmer commented 3 years ago

@abisalehalliprasan I passed it the result from Invoice::create() I'm betting I have the wrong CustomerRef value and Invoice::create is just returning false. Either way, do you think I should put together a pull request to fix the doc blocks?

abisalehalliprasan commented 3 years ago

If you pass the request paylaod to the create method of the Invoice facade as shown below :

//Add a new Invoice
$theResourceObj = Invoice::create([
    "Line" => [
        [
            "Amount" => 100.00,
            "DetailType" => "SalesItemLineDetail",
            "SalesItemLineDetail" => [
                "ItemRef" => [
                    "value" => 1,
                    "name" => "Services"
                ]
            ]
        ]
    ],
    "CustomerRef"=> [
        "value"=> 0
    ]
]);

print "The resource object is : " . PHP_EOL . print_r($theResourceObj) . PHP_EOL;

Output:

(
    [Deposit] => 
    [AllowIPNPayment] => 
    [AllowOnlinePayment] => 
    [AllowOnlineCreditCardPayment] => 
    [AllowOnlineACHPayment] => 
    [EInvoiceStatus] => 
    [ECloudStatusTimeStamp] => 
    [invoiceStatus] => 
    [callToAction] => 
    [invoiceStatusLog] => 
    [InvoiceEx] => 
    [LessCIS] => 
    [InvoiceLink] => 
    [PaymentDetailsMessage] => 
    [ConvenienceFeeDetail] => 
    [InvoiceLinkSecurityCode] => 
    [InvoiceLinkExpiryDate] => 
    [AutoDocNumber] => 
    [CustomerRef] => QuickBooksOnline\API\Data\IPPReferenceType Object
        (
            [name] => 
            [type] => 
            [value] => 0
        )

    [CustomerMemo] => 
    [BillAddr] => 
    [ShipAddr] => 
    [FreeFormAddress] => 
    [ShipFromAddr] => 
    [RemitToRef] => 
    [ClassRef] => 
    [SalesTermRef] => 
    [DueDate] => 
    [SalesRepRef] => 
    [PONumber] => 
    [FOB] => 
    [ShipMethodRef] => 
    [ShipDate] => 
    [TrackingNum] => 
    [GlobalTaxCalculation] => 
    [TotalAmt] => 
    [HomeTotalAmt] => 
    [ApplyTaxAfterDiscount] => 
    [TemplateRef] => 
    [PrintStatus] => 
    [EmailStatus] => 
    [BillEmail] => 
    [BillEmailCc] => 
    [BillEmailBcc] => 
    [ARAccountRef] => 
    [Balance] => 
    [HomeBalance] => 
    [FinanceCharge] => 
    [PaymentMethodRef] => 
    [PaymentRefNum] => 
    [PaymentType] => 
    [CheckPayment] => 
    [CreditCardPayment] => 
    [DepositToAccountRef] => 
    [DeliveryInfo] => 
    [DiscountRate] => 
    [DiscountAmt] => 
    [GovtTxnRefIdentifier] => 
    [TaxExemptionRef] => 
    [DocNumber] => 
    [TxnDate] => 
    [DepartmentRef] => 
    [CurrencyRef] => 
    [ExchangeRate] => 
    [PrivateNote] => 
    [TxnStatus] => 
    [LinkedTxn] => 
    [Line] => Array
        (
            [0] => QuickBooksOnline\API\Data\IPPLine Object
                (
                    [Id] => 
                    [LineNum] => 
                    [Description] => 
                    [Amount] => 100
                    [Received] => 
                    [LinkedTxn] => 
                    [DetailType] => QuickBooksOnline\API\Data\IPPLineDetailTypeEnum Object
                        (
                            [value] => SalesItemLineDetail
                        )

                    [PaymentLineDetail] => 
                    [DiscountLineDetail] => 
                    [TaxLineDetail] => 
                    [SalesItemLineDetail] => QuickBooksOnline\API\Data\IPPSalesItemLineDetail Object
                        (
                            [ServiceDate] => 
                            [TaxInclusiveAmt] => 
                            [DiscountRate] => 
                            [DiscountAmt] => 
                            [SalesItemLineDetailEx] => 
                            [ItemRef] => QuickBooksOnline\API\Data\IPPReferenceType Object
                                (
                                    [name] => Services
                                    [type] => 
                                    [value] => 1
                                )

                            [ClassRef] => 
                            [UnitPrice] => 
                            [RatePercent] => 
                            [PriceLevelRef] => 
                            [MarkupInfo] => 
                            [Qty] => 
                            [UOMRef] => 
                            [ItemAccountRef] => 
                            [InventorySiteRef] => 
                            [TaxCodeRef] => 
                            [TaxClassificationRef] => 
                        )

                    [DescriptionLineDetail] => 
                    [ItemBasedExpenseLineDetail] => 
                    [AccountBasedExpenseLineDetail] => 
                    [ReimburseLineDetail] => 
                    [DepositLineDetail] => 
                    [PurchaseOrderItemLineDetail] => 
                    [SalesOrderItemLineDetail] => 
                    [ItemReceiptLineDetail] => 
                    [JournalEntryLineDetail] => 
                    [GroupLineDetail] => 
                    [SubTotalLineDetail] => 
                    [TDSLineDetail] => 
                    [CustomField] => 
                    [LineEx] => 
                )

        )

    [TxnTaxDetail] => 
    [TxnSource] => 
    [TaxFormType] => 
    [TaxFormNum] => 
    [TransactionLocationType] => 
    [Tag] => 
    [TxnApprovalInfo] => 
    [RecurDataRef] => 
    [RecurringInfo] => 
    [Id] => 
    [SyncToken] => 
    [MetaData] => 
    [CustomField] => 
    [AttachableRef] => 
    [domain] => 
    [status] => 
    [sparse] => 
)
The resource object is : 
1

If you do not pass a valid CustomerRef for Creating Invoice the exception SDK is throwing is :

Fatal error: Uncaught QuickBooksOnline\API\Exception\ServiceException: Http Status Code [400]: Request is not made successful. Response Code:[400] with body: [<?xml version="1.0" encoding="UTF-8" standalone="yes"?><IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2021-02-04T20:44:45.308-08:00"><Fault type="ValidationFault"><Error code="2500" element="Reference Id"><Message>Invalid Reference Id</Message><Detail>Invalid Reference Id : Names element id 0 not found</Detail></Error></Fault></IntuitResponse>].

Not sure how you are getting a boolean response. If you could post your payload ( make sure to mask any sensitive information ) before creating a PR would help.

GameCharmer commented 3 years ago

@abisalehalliprasan the overarching problem here isn't the data, it's the returned values. I can't get past code validation when the returns don't line up. Add says it only returns IPPIntuitEntity , but it returns the result of sendRequestParseResponseBodyAndHandleHttpError, which says it only returns null|string.

The best I can think of here would be to fork and throw exceptions when returns don't line up.

abisalehalliprasan commented 3 years ago

@GameCharmer : Could you create a PR and we can take a look at this please?

GameCharmer commented 3 years ago

@abisalehalliprasan PR: https://github.com/intuit/QuickBooks-V3-PHP-SDK/pull/394