'Issue saving card for customer

I would like to store credit card information for a customer in our QuickBooks account using the PHP Payments SDK - the following is what I am trying to achieve this but I get an invalid arguments error:

$client = new PaymentClient([
'access_token' => $accessTokenValue,
'environment' => "sandbox" ]);


$array = [
   "number" => "4408041234567893",
   "expMonth" => "12",
   "expYear" => "2026",
   "name" => "Test User",
   "address" => [
       "streetAddress" => "1245 Hana Rd",
       "city" => "Richmond",
       "region" => "VA",
       "country" => "US",
       "postalCode" => "44112"
    ],
    "customerid" => "94"
];


$create = CardOperations::createCard($array);
$response = $client->charge($create);

I have not had any luck reaching out to support, any way this can be done, I appreciate the help.

Error received:

Uncaught TypeError: Argument 1 passed to QuickBooksOnline\Payments\Operations\CardOperations::createCard() must be an instance of QuickBooksOnline\Payments\Modules\Card, array given

UPDATE using recommended code:

Uncaught ArgumentCountError: Too few arguments to function QuickBooksOnline\Payments\Operations\CardOperations::createCard(), 1 passed



Solution 1:[1]

As per your error it seems the required Card data should be an instance of the class

QuickBooksOnline\Payments\Modules\Card

But you're passing array to it. As per the documentation could you please check this below code , hopefully it will work.

$client = new PaymentClient([
    'access_token' => $accessTokenValue,
    'environment' => "sandbox" 
]);
    
    
$cardData = [
    "number" => "4408041234567893",
    "expMonth" => "12",
    "expYear" => "2026",
    "name" => "Test User",
    "address" => [
        "streetAddress" => "1245 Hana Rd",
        "city" => "Richmond",
        "region" => "VA",
        "country" => "US",
        "postalCode" => "44112"
    ],
    "customerid" => "94"
];

$chargeData = [
  "amount" => "10.55",
  "currency" => "USD",
  "card" => $cardData,
  "context" => [
        "mobile" => "false",
        "isEcommerce" => "true"
    ]
];
$customerId = "94";

$charge = ChargeOperations::buildFrom($chargeData);
$chargeResponse = $client->charge($charge);

$clientId = rand();
$card = CardOperations::buildFrom($cardData);
$createCardresponse = $client->createCard($card, $clientId, rand() . "abd");

//or alternatively $createCardresponse = $client->createCard($card, $customerId, rand() . "abd");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman