为客户发放储蓄卡

Issue saving card for customer

我想在我们的 QuickBooks 帐户中存储客户的信用卡信息 使用 PHP 支付 SDK - 以下是我试图实现的目标,但我收到无效参数错误:

$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);

我没有任何运气伸出支持,任何方式都可以做到这一点,我感谢你的帮助。

收到错误:

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

使用推荐代码进行更新:

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

根据您的错误,所需的卡片数据似乎应该是 class

的一个实例
QuickBooksOnline\Payments\Modules\Card

但是您要将数组传递给它。根据文档,您能否检查下面的代码,希望它能工作。

$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");