Invalid_fields - [cart_items]

When I include cart_items I get INVALID_FIELDS - [CART_ITEMS]:

array(1) { [“status”]=> array(5) { [“error_code”]=> string(29) “INVALID_FIELDS - [CART_ITEMS]” [“status”]=> string(5) “ERROR” [“message”]=> string(261) “The request attempted an operation, but one or more of the fields did not have a valid value. The request was rejected. Corrective action: Use valid values. The names of the affected fields appear at the end of the error code. See the API Reference for details.” [“response_code”]=> string(29) “INVALID_FIELDS - [CART_ITEMS]” [“operation_id”]=> string(36) “47bcd867-06de-4009-a467-eac8c8bb20b6” } }

This is my code:

<?php
include('utilities.php');
$cart_items = [
        "name" => "course",
        "amount" => 51,
        "quantity" => 2,
];
$body = [
    "amount" => 102,
    "complete_checkout_url" => "https://...co.uk/sandbox/complete.php",
    "cancel_checkout_url" => "https://...co.uk/sandbox/cancel.php",
    "cart_items" => $cart_items,
    "country" => "GB",
    "currency" => "GBP",
    "merchant_reference_id" => "950ae8c6-76",
];

try {
    $object = make_request('post', '/v1/checkout', $body);
//    var_dump($object['data']['redirect_url']);
    var_dump($object);
//    header("Location: ".$object['data']['redirect_url']);
    exit();
} catch (Exception $e) {
    echo "Error: $e";
}
?>

Thanks, @m2z, those fields are correct, and I made a generated a page in postman just to check.

The URLs you have are actual URLs rather than …co.uk… correct? It would create an error if you input those specific strings (https://...co.uk/sandbox/cancel.php).

My guess is the code is generating something, but cart_items seems to have valid fields.

Request

{
    "complete_checkout_url": "http://test.co.uk/sandbox/complete.php",
    "country": "GB",
    "currency": "GBP",
    "cancel_checkout_url": "https://test.co.uk/sandbox/cancel.php",
    "merchant_reference_id": "950ae8c6-76",
    "amount": 102,
    "cart_items": [{
            "name": "course",
            "amount": 51,
            "quantity": 2
        }
    ]
}

Response

{
    "status": {
        "error_code": "",
        "status": "SUCCESS",
        "message": "",
        "response_code": "",
        "operation_id": "54cf6685-85b5-4eb7-a898-cff8dc9791bc"
    },
    "data": {
        "id": "checkout_d3af1bd3147dcc93ef7af11b408c9de6",
        "status": "NEW",
        "language": null,
        "merchant_color": "323fff",
        "merchant_logo": null,
        "merchant_website": "http://rapyd.net",
        "merchant_customer_support": {
            "url": "http://support.rapyd.net",
            "email": "support@rapyd.net",
            "phone_number": "555-555-5555"
        },
        "merchant_alias": "Test Business",
        "merchant_terms": null,
        "merchant_privacy_policy": null,
        "page_expiration": 1657657888,
        "redirect_url": "https://sandboxcheckout.rapyd.net?token=checkout_d3af1bd3147dcc93ef7af11b408c9de6",
        "merchant_main_button": "pay_now",
        "cancel_checkout_url": "https://test.co.uk/sandbox/cancel.php",
        "complete_checkout_url": "http://test.co.uk/sandbox/complete.php",
        "country": "GB",
        "currency": "GBP",
        "amount": 102,
        "payment": {
            "id": null,
            "amount": 102,
            "original_amount": 0,
            "is_partial": false,
            "currency_code": "GBP",
            "country_code": "GB",
            "status": null,
            "description": "Payment via Checkout",
            "merchant_reference_id": "950ae8c6-76",
            "customer_token": null,
            "payment_method": null,
            "payment_method_data": {},
            "expiration": 0,
            "captured": false,
            "refunded": false,
            "refunded_amount": 0,
            "receipt_email": null,
            "redirect_url": null,
            "complete_payment_url": null,
            "error_payment_url": null,
            "receipt_number": null,
            "flow_type": null,
            "address": null,
            "statement_descriptor": null,
            "transaction_id": null,
            "created_at": 0,
            "updated_at": 0,
            "metadata": null,
            "failure_code": null,
            "failure_message": null,
            "paid": false,
            "paid_at": 0,
            "dispute": null,
            "refunds": null,
            "order": null,
            "outcome": null,
            "visual_codes": {},
            "textual_codes": {},
            "instructions": {},
            "ewallet_id": null,
            "ewallets": [],
            "payment_method_options": {},
            "payment_method_type": null,
            "payment_method_type_category": null,
            "fx_rate": null,
            "merchant_requested_currency": null,
            "merchant_requested_amount": null,
            "fixed_side": null,
            "payment_fees": null,
            "invoice": null,
            "escrow": null,
            "group_payment": null,
            "cancel_reason": null,
            "initiation_type": "customer_present",
            "mid": null,
            "next_action": "not_applicable"
        },
        "payment_method_type": null,
        "payment_method_type_categories": null,
        "payment_method_types_include": null,
        "payment_method_types_exclude": null,
        "customer": null,
        "custom_elements": {
            "save_card_default": false,
            "display_description": false,
            "payment_fees_display": true,
            "merchant_currency_only": false,
            "billing_address_collect": false,
            "dynamic_currency_conversion": false
        },
        "timestamp": 1656448288,
        "payment_expiration": null,
        "cart_items": [
            {
                "name": "course",
                "amount": 51,
                "quantity": 2,
                "image": null
            }
        ],
        "escrow": null,
        "escrow_release_days": null
    }
}

@m2z, after speaking with a team member, it was pointing out that card_items does need to be an array of objects vs an array of fields as referenced on Checkout Page Object.

I’m unfamiliar with PHP syntax, What would your $cart_items look like as an array of objects?

1 Like

Your $cart_items is an object, not an array of objects. It can be an array of one single object, but it must be the right datatype.

1 Like

Thanks for your help.

3 Likes