Jump to content

AddOrder - Help required


namoos

Recommended Posts

Hi, 

I am implementing the AddOrder API, a bit confused by the configoptions. Actually I am unable to make a proper request. In the order there are configurable options like physical servers and tiers etc. In the below product I need 2 configurable options, "physical_server_tier" and "physical_servers", according to docs the code should look like this.

"configoptions" => [base64_encode(serialize([

     '12' => 2 // quantity of the physical servers

     '11' => 27

]))], but this is not working. Any help would be much appreciated.

array:3 [
  "id" => 8
  "name" => "R1Soft License Key"
  "options" => array:7 [
    "physical_tier_lock" => array:3 []
    "physical_server_tier" => array:3 [
      "id" => 11
      "name" => "Physical Server Tier"
      "options" => array:8 [
        0 => array:4 [
          "id" => 27
          "name" => "tier-0"
          "currency" => "USD"
          "pricing" => array:3 []
        ]
        1 => array:4 []
        2 => array:4 []
        3 => array:4 []
        4 => array:4 []
        5 => array:4 []
        6 => array:4 []
        7 => array:4 []
      ]
    ]
    "physical_servers" => array:3 [
      "id" => 12
      "name" => "Physical Servers"
      "options" => array:1 [
        0 => array:4 [
          "id" => 35
          "name" => "Physical Servers"
          "currency" => "USD"
          "pricing" => array:3 []
        ]
      ]
    ]
    "virtual_tier_lock" => array:3 []
    "virtual_machine_tier" => array:3 []
    "virtual_machines" => array:3 []
    "license_key" => array:3 []
  ]
]

screencapture-devsite-cachewall-whmcs-admin-clientsservices-php-2019-06-19-16_53_37.png

Link to comment
Share on other sites

You should post your script since the array you posted probably comes from another system and let us know if you need to use External or Internal API.  Here you find all information (use as reference the provided code). Don't forget that the Product/Service you're trying to add must exist on your WHMCS with Configurable Options you need.

Link to comment
Share on other sites

@Kian Thanks for your reply. I am receiving this product/service from this API and submitting it via the api you mentioned "AddOrder".  It creates an order at the WHMCS, but the configurable options are missing as I have pointed out in the above attachment. Below is the code I am using.

                if ($input['package'] == 45) {
                    $product = $packages['license'];
                    $config_options = [
                        base64_encode(serialize([
                            $product['options']['physical_servers']['id'] => (int)$input['agents']
                        ]))
                    ];
                    $product_options = $product['options']['license_key']['options'];
                }
                $selected_package = null;
                foreach ($product_options as $record) {
                    if ($input['package'] == $record['id']) {
                        $selected_package = $record;
                        break;
                    }
                }
                // Package price
                $package_price = 0;
                if ($input['term'] == 'monthly') {
                    $package_price = $selected_package['pricing']['monthly'];
                } else {
                    $package_price = $selected_package['pricing']['annually'];
                }
                // Setup price
                $setup_price = 0;
                if ($input['setup'] == 1) {
                    $setup_price = 24.95;
                }
                // Addons prices
                $tier_price = 0;
                if ($input['package'] == 45) {
                    $tiers = $packages['license']['options']['physical_server_tier']['options'];
                    if ($input['term'] == 'monthly') {
                        $tier_price = $tiers[0]['pricing']['monthly'] * $input['agents'];
                    } else {
                        $tier_price = $tiers[0]['pricing']['annually'] * $input['agents'];
                    }
                }
                $total_price = $package_price + $setup_price + $tier_price;
                $response = $this->client->request('POST', $this->api_url, [
                        'form_params' => [
                            'action' => $this->commands['place_order'],
                            'username' => $this->api_identifier,
                            'password' => $this->api_secret,
                            'clientid' => $client_id,
                            'pid' => $product['id'],
                            'billingcycle' => $input['term'],
                            'configoptions' => $config_options,
                            'paymentmethod' => 'paypalbilling',
                            'clientip' => $_SERVER['REMOTE_ADDR'],
                            'priceoverride' => round(floatval($total_price), 2),
                            'responsetype' => 'json',
                        ]
                    ]);
                $result = json_decode($response->getBody());

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated