我目前正在使用square / connect-php-sdk createOrder创建一个Square Order。
$api_config = new SquareConnect\Configuration();
$api_config->setAccessToken($access_token);
$api_config->setHost($host);
$api_client = new SquareConnect\ApiClient($api_config);
$apiInstance = new SquareConnect\Api\OrdersApi($api_client);
$orderRequest = new SquareConnect\Model\CreateOrderRequest();
$orderRequest->setIdempotencyKey(uniqid());
$order = new SquareConnect\Model\Order();
$money = new SquareConnect\Model\Money();
$money->setAmount(intval(500))
->setCurrency("USD");
$line_item = new SquareConnect\Model\OrderLineItem();
$line_item->setCatalogObjectId(<square item id>)
->setQuantity("1")
->setBasePriceMoney($money);
$line_items[] = $line_item;
$order->setLineItems($line_items);
$orderRequest->setOrder($order);
$result = $apiInstance->createOrder($location_id, $orderRequest);
这将返回我在本地存储的订单ID(以及其他订单数据)。然后,我使用付款方表格处理信用卡:https://developer.squareup.com/docs/payment-form/payment-form-walkthrough
这给我一个随机数,然后我将其随订单ID和价格一起发送。
$apiInstance = new SquareConnect\Api\PaymentsApi($api_client);
$paymentRequest = new SquareConnect\Model\CreatePaymentRequest();
$paymentRequest->setIdempotencyKey(uniqid());
$paymentRequest->setLocationId($location_id);
$money = new SquareConnect\Model\Money();
$money->setAmount(intval($total_cost))
->setCurrency("USD");
$paymentRequest->setAmountMoney($money);
$paymentRequest->setOrderId($sq_order_id);
$paymentRequest->setSourceId($nonce);
$result = $apiInstance->createPayment($paymentRequest);
这给了我一个付款ID(以及其他付款数据)。在方形仪表板上,我能够在“事务”部分中看到交易,但是仪表板的“订单”部分为空。
我的问题是如何将其显示在“订单”部分?
为了使订单显示在仪表板上,您需要做两件事:1.支付订单费用(听起来像您已完成此部分)2.在fulfillments
请求中包含CreateOrder
参数:https://developer.squareup.com/docs/orders-api/order-ahead-usecase#add-fulfillment-information-to-make-a-pickup-order