netsuitephp / netsuite-php

NetSuite PHP API Client with namespaces and autoloading
Other
189 stars 85 forks source link

Override On Hold Credit Customers #85

Closed ezequiel9 closed 3 years ago

ezequiel9 commented 3 years ago

Hi, sorry for opening a new issue. I am trying to submit a new sales order and it wont let me do it if the customer is on hold. The thing is that I need to place the sales order when users pay with credit card. See below:

Trying to submit by using this field: (I have tried $sale->orderStatus = SalesOrderOrderStatus::_fullyBilled; too)

image

^ NetSuite\Classes\AddResponse {#6017 ▼
  +writeResponse: NetSuite\Classes\WriteResponse {#6019 ▼
    +status: NetSuite\Classes\Status {#6020 ▼
      +statusDetail: array:1 [▼
        0 => NetSuite\Classes\StatusDetail {#5977 ▼
          +code: "USER_ERROR"
          +message: "Customer is on credit hold."
          +afterSubmitFailed: null
          +type: "ERROR"
        }
      ]
      +isSuccess: false
    }
    +baseRef: null
  }
}

is there any help you can give me ? thanks! :)

Here my code:

        $sale = new SalesOrder();
        // Associate a customer record with this order
        $sale->entity = new RecordRef();
        $sale->entity->type = 'customer';
        $sale->entity->internalId = $payload['entity'];

        // Set the date of the order
        $sale->tranDate = Carbon::now()->format('c');
        $sale->otherRefNum = $payload['otherRefNum'];

        // Set the shipping method and price for the order
        $sale->shipMethod = new RecordRef();
        $sale->shipMethod->internalId = $payload['shipMethod'];
        //$sale->shippingCost = $payload['shipping_rate'] ?? 0;

        // Look at the SalesOrder class definition for a list of all the available
        // properties and their types that you can use on a sales order in NetSuite.
        // You'll need to add items, addresses, status, etc.
        $items = [];
        foreach ($payload['items'] as $item) {
            $inventory_item = new SalesOrderItem();

            $item_ref = new RecordRef();
            $item_ref->internalId = $item['item'];
            $item_ref->recordType = "inventoryItem";

            $inventory_item->item = $item_ref;
            $inventory_item->commitInventory = SalesOrderItemCommitInventory::_doNotCommit;
            $inventory_item->quantityBackOrdered = $item['quantity'];
            //$inventory_item->quantity = $item['quantity'];
            $items[] = $inventory_item;
        }

        $sale->itemList = new SalesOrderItemList();
        $sale->itemList->replaceAll = true;
        $sale->itemList->item = $items;

        if ($payload['forceCash']) {
            $sale->orderStatus = SalesOrderOrderStatus::_fullyBilled;
            $sale->ispurchasecard = true;
        } else {
            $sale->orderStatus = SalesOrderOrderStatus::_pendingFulfillment;
            $sale->ispurchasecard = false;
        }

        $address = new Address();
        $address->addr1 = $payload['shippingAddress']['addr1'];
        $address->addr2 = $payload['shippingAddress']['addr2'];
        $address->city = $payload['shippingAddress']['addressee'];
        $address->zip = $payload['shippingAddress']['zip'];
        $address->country = Country::_newZealand;
        $sale->shippingAddress = $address;

        $address = new Address();
        $address->addr1 = $payload['billingaddress']['addr1'];
        $address->addr2 = $payload['billingaddress']['addr2'];
        $address->city = $payload['billingaddress']['addressee'];
        $address->zip = $payload['billingaddress']['zip'];
        $address->country = Country::_newZealand;
        $sale->billingAddress = $address;

        // Create a sample string-type custom field to the order which represents
        // the ID of the order in our source platform:
        $custom12 = new StringCustomFieldRef();
        $custom12->scriptId = 'custbody12';
        $custom12->value = $payload['custbody12'];

        $customNotes = new StringCustomFieldRef();
        $customNotes->scriptId = 'custbody_czo_internal_notes';
        $customNotes->value = $payload['custbody_czo_internal_notes'];

        // Collect all custom fields into an array and add the list of fields to the
        // order add request:
        $customFields[] = $custom12;
        $customFields[] = $customNotes;
        $sale->customFieldList = new CustomFieldList();
        $sale->customFieldList->customField = $customFields;

        //$sale->terms = $payload['terms'];
        $sale->toBeEmailed = $payload['toBeEmailed'];
        $sale->toBePrinted = $payload['toBePrinted'];
        $sale->location = 1;
        $sale->webstore = 'T';

        // Submit the sales order create request
        $request = new AddRequest();
        $request->record = $sale;
        $service = $this->getNetsuiteService();
//        dd($request);
        $addResponse = $service->add($request);
        dd($addResponse);
jrebs commented 3 years ago

I have no idea, but the message seems to pretty clearly identify the problem. You need to get the customer off of credit hold (I've never had this problem, perhaps it's something about your account settings). I see that there's a Customer::creditHoldOverride property which is an object of the CustomerCreditHoldOverride class. I'd probably look into experimenting with the controls associated with this flag. In the UI it looks like it corresponds to something in Setup -> Accounting -> Accounting Preferences. For what it's worth, My 'Customer Credit Limit Handling' is set to 'Warn Only'.

Closing because not a library issue.