関数
Request::makeRequestBody()
戻り値 戻り値
ファイル: src/Api/Request.php
public function makeRequestBody() {
global $usces;
$order = $_SESSION['usces_entry']['order'];
$delivery = isset($_SESSION['usces_entry']['delivery']) ? $_SESSION['usces_entry']['delivery'] : [];
$products = [];
$index = 0;
$shipping = false;
$capture_type = $this->module->getActingOpts()['payment_capture_type'];
$capture = $capture_type === 'on_purchase' ? true : false;
$cart = $usces->cart->get_cart();
foreach ($cart as $item) {
$item_division = get_post_meta($item['post_id'], '_item_division', true);
$division = empty($item_division) ? 'shipped' : $item_division;
if ($division === 'shipped') {
$shipping = true;
}
$itemCode = $usces->getItemCode($item['post_id']);
$pictid = (int)$usces->get_mainpictid($itemCode);
$imageurl = wp_get_attachment_image_src($pictid);
$products[] = [
'id' => $itemCode,
'name' => $usces->getItemName($item['post_id']),
'quantity' => $item['quantity'],
'price' => $item['price'],
];
if ($imageurl !== false) {
$products[$index]['imageUrl'] = $imageurl[0];
}
$index++;
}
$packages = [
'id' => uniqid(),
'amount' => $order['total_items_price'],
'userFee' => 0,
'products' => $products,
];
$cname = get_option('usces')['company_name'];
if (!empty($cname)) {
$packages['name'] = $cname;
}
$uuid = uniqid('wcexalp_request_', true);
$payload = [
'amount' => $order['total_full_price'],
'currency' => strtoupper(usces_crcode('return')),
'orderId' => $uuid,
'redirectUrls' => [
'cancelUrl' => USCES_CART_URL,
'confirmUrl' => LinePay::getConfirmRedirectUrl(),
'confirmUrlType' => 'CLIENT',
],
'packages' => [$packages],
'options' => [
'display' => [
'locale' => $this->module->getActingOpts()['locale'],
],
'payment' => [
'capture' => $capture,
],
],
];
if ($shipping === true) {
$payload['options']['shipping'] = [
'feeAmount' => $order['shipping_charge'],
'type' => 'FIXED_ADDRESS',
'feeInquiryType' => 'FIXED',
'address' => [
'country' => $delivery['country'],
'postalCode' => $delivery['zipcode'],
'state' => $delivery['pref'],
'city' => $delivery['address1'],
'detail' => $delivery['address2'],
'optional' => $delivery['address3'],
'recipient' => [
'firstName' => $delivery['name2'],
'lastName' => $delivery['name1'],
'firstNameOptional' => $this->name4,
'lastNameOptional' => $this->name3,
'email' => $delivery['mailaddress1'],
'phoneNo' => $delivery['tel'],
],
],
];
}
return $payload;
}