クラス
AmazonCheckoutDetails
Amazon shipping address and payment details Vue component
ソース ソース
ファイル: src/Components/AmazonCheckoutDetails/AmazonCheckoutDetails.php
class AmazonCheckoutDetails extends VueComponent { /** * AmazonPay module instance * * @var AmazonPay */ private $module; /** * Amazon Pay checkout session ID * * @var string */ private $checkoutSessionId; /** * Checkout session details * * @var array */ private $checkoutSessionDetails; /** * Address error message, if set * * @var string */ private $addressError; /** * Sets `$module` member var. Sets `$checkoutSessionId` with parameter value * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param AmazonPay $module * @param string $checkoutSessionId * @param bool $controlledComponent * @return void */ public function __construct(AmazonPay $module, $checkoutSessionId, $controlledComponent = true) { parent::__construct($controlledComponent); $this->module = $module; $this->checkoutSessionId = $checkoutSessionId; $this->checkoutSessionDetails = $_SESSION['amazonCheckoutSession']; $details = $this->checkoutSessionDetails; $this->addressError = !empty($details['addressError']) ? $details['addressError'] : ''; } /** * Loads assets for this component * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ public function init() { add_action('wp_enqueue_scripts', function () { wp_enqueue_script( Checkout::AMAZON_CHECKOUT_JS_SLUG, $this->module->getActingOpts()['amzjsurl'] . '/checkout.js', [], WCEXAAP_VERSION, false ); $semantic = new Semantic(); $semantic->loadButtonCss(); $semantic->loadMessageCss(); $this->loadAddressErrorMessageBoxCss(); }); } /** * Returns component name as is recognized by Vue. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return string */ public function getComponentName() { return 'amazonCheckoutDetailsComponent'; } /** * Amazon checkout details component template. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ public function template() { $details = $this->checkoutSessionDetails; $payAndShip = $details['productType'] === 'PayAndShip'; $paymentDescriptor = $details['paymentPreferences'][0]['paymentDescriptor']; $btnclass = AmazonPay::getThemeConfig()['btnprimary']; /** * Filters the CSS class name that wraps `amazon-checkout-details-component` * * @param string $classname Default: '' */ $wrapperClass = apply_filters('wcexaap_filter_amazon_checkout_details_wrapper_class', ''); $wrapperClass = !empty($wrapperClass) ? ' ' . $wrapperClass : ''; $entries = isset($_SESSION['usces_entry']) ? $_SESSION['usces_entry'] : []; $customer = isset($entries['customer']) ? $entries['customer'] : []; $propsAndEvents = []; if ($this->controlledComponent === true) { $propsAndEvents[] = 'v-bind:gift-shipping="giftShipping"'; $propsAndEvents[] = '@update-hard-decline-errors="updateHardDeclineErrors"'; } else { $propsAndEvents[] = 'v-bind:gift-shipping="\'false\'"'; } $allPropsAndEvents = join(' ', $propsAndEvents); ?> <amazon-checkout-details-component checkout-session-id="<?php echo $this->checkoutSessionId; ?>" address-error="<?php echo $this->addressError; ?>" v-bind:pay-and-ship="<?php echo $payAndShip ? 'true' : 'false'; ?>" v-bind:logged-in="<?php echo usces_is_login() ? 'true' : 'false'; ?>" <?php echo $allPropsAndEvents; ?> inline-template > <div class="amazon-details-container<?php echo esc_attr($wrapperClass); ?>"> <?php ob_start(); ?> <table id="confirm_table"> <template v-if="!hideCustomerInfo"> <tr class="ttl"> <td colspan="2"><h3><?php _e('Customer Information', 'usces'); ?></h3></td> </tr> <tr> <th><?php _e('e-mail adress', 'usces'); ?></th> <td><?php echo esc_html($customer['mailaddress1']); ?></td> </tr> </template> <?php $this->confirmAddressTable($entries); ?> <tr class="ttl"> <td colspan="2"><h3><?php _e('Others', 'usces'); ?></h3></td> </tr> <tr> <th class="paymentMethod-th"> <div class="change-container"> <div><?php _e('payment method', 'usces'); ?></div> <button id="updatePaymentMethodButton" class="ui mini <?php echo $btnclass; ?> button" > <?php _e('Change', 'wcexaap'); ?> </button> </div> </th> <td id="paymentMethodTd"> <img id="amazonPayLogo" src="<?php echo WCEXAAP_PLUGIN_URL . '/assets/logo-pay.png'; ?>" height="20px" /> <span><?php echo esc_html($paymentDescriptor); ?></span> </td> </tr> </table> <?php $vuehtml = ob_get_clean(); ?> <?php /** * Filters the `amazon-checkout-details-component` Vue HTML * * @param string $vuehtml * @param \Aivec\Welcart\SettlementModules\AmazonPay\Components\AmazonCheckoutDetails\AmazonCheckoutDetails $instance * @param string $btnclass * @param string $paymentDescriptor */ echo apply_filters('wcexaap_filter_amazon_checkout_details_component', $vuehtml, $this, $btnclass, $paymentDescriptor); ?> </div> </amazon-checkout-details-component> <?php } /** * Returns error message box for an address error * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param string $changeButtonId ID to bind the change action * @param string $wrapperClass * @return string */ public function getAddressErrorMessageBox($changeButtonId, $wrapperClass = '') { ob_start(); ?> <div class="ui wcexaap <?php echo esc_attr($wrapperClass); ?> error-box negative message"> <div class="messages-container"> <div class="header"> <?php echo $this->addressError; ?> </div> <p><?php _e('This address is invalid. Please choose a different address.', 'wcexaap'); ?></p> </div> <div class="button-container"> <button id="<?php echo esc_attr($changeButtonId); ?>" class="ui black fluid mini button"> <?php _e('Change', 'wcexaap'); ?> </button> </div> </div> <?php return ob_get_clean(); } /** * Loads CSS for address error box * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ public function loadAddressErrorMessageBoxCss() { wp_enqueue_style( 'wcexaap-hard-decline-error-box', WCEXAAP_PLUGIN_URL . '/src/Components/AmazonCheckoutDetails/errorbox.css', [], WCEXAAP_VERSION ); } /** * Adds 'Change Address' button to address table * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param array $data * @return void */ public function confirmAddressTable($data) { global $usces, $usces_settings; $options = get_option('usces'); $form = $options['system']['addressform']; $applyform = usces_get_apply_addressform($form); $formtag = ''; $values = $data; $type = 'confirm'; $data['type'] = 'confirm'; $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform(); $values = $usces->stripslashes_deep_post($values); $target_market_count = (isset($options['system']['target_market']) && is_array($options['system']['target_market'])) ? count($options['system']['target_market']) : 1; // phpcs:disable WordPress.WP.I18n.NoEmptyStrings switch ($applyform) { case 'JP': /** * Mirrored Welcart filter * * @ignore */ $formtag .= '<tr v-if="!hideCustomerInfo" class="name-row member-name-row"><th>' . apply_filters('usces_filters_addressform_name_label', __('Full name', 'usces'), $type, $values, $applyform) . '</th><td>' . esc_html(sprintf(_x('%s', 'honorific', 'usces'), (esc_html($values['customer']['name1']) . ' ' . esc_html($values['customer']['name2'])))) . '</td></tr>'; if (usces_is_login()) { $furigana = ('' == (trim($values['customer']['name3']) . trim($values['customer']['name4']))) ? '' : sprintf(_x('%s', 'honorific', 'usces'), (esc_html($values['customer']['name3']) . ' ' . esc_html($values['customer']['name4']))); $furigana_customer = '<tr class="furikana-row member-furikana-row"><th>' . __('furigana', 'usces') . '</th><td>' . $furigana . '</td></tr>'; /** * Mirrored Welcart filter * * @ignore */ $formtag .= apply_filters('usces_filter_furigana_confirm_customer', $furigana_customer, $type, $values); $formtag .= '<tr class="zipcode-row member-zipcode-row"><th>' . __('Zip/Postal Code', 'usces') . '</th><td>' . esc_html($values['customer']['zipcode']) . '</td></tr>'; if (1 < $target_market_count) { $customer_country = (!empty($usces_settings['country'][$values['customer']['country']])) ? $usces_settings['country'][$values['customer']['country']] : ''; $formtag .= '<tr class="country-row member-country-row"><th>' . __('Country', 'usces') . '</th><td>' . esc_html($customer_country) . '</td></tr>'; } $customer_pref = ($values['customer']['pref'] == __('-- Select --', 'usces') || $values['customer']['pref'] == '-- Select --') ? '' : $values['customer']['pref']; $formtag .= ' <tr class="states-row member-states-row"><th>' . __('Province', 'usces') . '</th><td>' . esc_html($customer_pref) . '</td></tr> <tr class="address1-row member-address1-row"><th>' . __('city', 'usces') . '</th><td>' . esc_html($values['customer']['address1']) . '</td></tr> <tr class="address2-row member-address2-row"><th>' . __('numbers', 'usces') . '</th><td>' . esc_html($values['customer']['address2']) . '</td></tr> <tr class="address3-row member-address3-row"><th>' . __('building name', 'usces') . '</th><td>' . esc_html($values['customer']['address3']) . '</td></tr> <tr class="tel-row member-tel-row"><th>' . __('Phone number', 'usces') . '</th><td>' . esc_html($values['customer']['tel']) . '</td></tr> <tr class="fax-row member-fax-row"><th>' . __('FAX number', 'usces') . '</th><td>' . esc_html($values['customer']['fax']) . '</td></tr>'; } $shipping_address_info = ''; if (isset($values['delivery'])) { $shipping_address_info = $this->getAddressTableHeader(); /** * Mirrored Welcart filter * * @ignore */ $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters('usces_filters_addressform_name_label', __('Full name', 'usces'), $type, $values, $applyform) . '</th><td>' . sprintf(_x('%s', 'honorific', 'usces'), (esc_html($values['delivery']['name1']) . ' ' . esc_html($values['delivery']['name2']))) . '</td></tr>'; $shipping_address_info .= '<tr class="zipcode-row delivery-zipcode-row"><th>' . __('Zip/Postal Code', 'usces') . '</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr>'; if (1 < $target_market_count) { $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : ''; $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __('Country', 'usces') . '</th><td>' . esc_html($shipping_country) . '</td></tr>'; } $delivery_pref = ($values['delivery']['pref'] == __('-- Select --', 'usces') || $values['delivery']['pref'] == '-- Select --') ? '' : $values['delivery']['pref']; $shipping_address_info .= ' <tr class="states-row delivery-states-row"><th>' . __('Province', 'usces') . '</th><td>' . esc_html($delivery_pref) . '</td></tr> <tr class="address1-row delivery-address1-row"><th>' . __('city', 'usces') . '</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr> <tr class="address2-row delivery-address2-row"><th>' . __('numbers', 'usces') . '</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr> <tr class="address3-row delivery-address3-row"><th>' . __('building name', 'usces') . '</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr> <tr class="tel-row delivery-tel-row"><th>' . __('Phone number', 'usces') . '</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr>'; } $formtag .= $shipping_address_info; break; case 'CN': /** * Mirrored Welcart filter * * @ignore */ $formtag .= '<tr v-if="!hideCustomerInfo" class="name-row member-name-row"><th>' . apply_filters('usces_filters_addressform_name_label', __('Full name', 'usces'), $type, $values, $applyform) . '</th><td>' . sprintf(_x('%s', 'honorific', 'usces'), esc_html(usces_localized_name($values['customer']['name1'], $values['customer']['name2'], 'return'))) . '</td></tr>'; if (usces_is_login()) { if (1 < $target_market_count) { $customer_country = (!empty($usces_settings['country'][$values['customer']['country']])) ? $usces_settings['country'][$values['customer']['country']] : ''; $formtag .= '<tr class="country-row member-country-row"><th>' . __('Country', 'usces') . '</th><td>' . esc_html($customer_country) . '</td></tr>'; } $customer_pref = ($values['customer']['pref'] == __('-- Select --', 'usces') || $values['customer']['pref'] == '-- Select --') ? '' : $values['customer']['pref']; $formtag .= ' <tr class="states-row member-states-row"><th>' . __('State', 'usces') . '</th><td>' . esc_html($customer_pref) . '</td></tr> <tr class="address1-row member-address1-row"><th>' . __('city', 'usces') . '</th><td>' . esc_html($values['customer']['address1']) . '</td></tr> <tr class="address2-row member-address2-row"><th>' . __('Address Line1', 'usces') . '</th><td>' . esc_html($values['customer']['address2']) . '</td></tr> <tr class="address3-row member-address3-row"><th>' . __('Address Line2', 'usces') . '</th><td>' . esc_html($values['customer']['address3']) . '</td></tr> <tr class="zipcode-row member-zipcode-row"><th>' . __('Zip', 'usces') . '</th><td>' . esc_html($values['customer']['zipcode']) . '</td></tr> <tr class="tel-row member-tel-row"><th>' . __('Phone number', 'usces') . '</th><td>' . esc_html($values['customer']['tel']) . '</td></tr> <tr class="fax-row member-fax-row"><th>' . __('FAX number', 'usces') . '</th><td>' . esc_html($values['customer']['fax']) . '</td></tr>'; } $shipping_address_info = ''; if (isset($values['delivery'])) { $shipping_address_info = $this->getAddressTableHeader(); /** * Mirrored Welcart filter * * @ignore */ $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters('usces_filters_addressform_name_label', __('Full name', 'usces'), $type, $values, $applyform) . '</th><td>' . sprintf(_x('%s', 'honorific', 'usces'), esc_html(usces_localized_name($values['delivery']['name1'], $values['delivery']['name2'], 'return'))) . '</td></tr>'; if (1 < $target_market_count) { $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : ''; $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __('Country', 'usces') . '</th><td>' . esc_html($shipping_country) . '</td></tr>'; } $delivery_pref = ($values['delivery']['pref'] == __('-- Select --', 'usces') || $values['delivery']['pref'] == '-- Select --') ? '' : $values['delivery']['pref']; $shipping_address_info .= ' <tr class="states-row delivery-states-row"><th>' . __('State', 'usces') . '</th><td>' . esc_html($delivery_pref) . '</td></tr> <tr class="address1-row delivery-address1-row"><th>' . __('city', 'usces') . '</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr> <tr class="address2-row delivery-address2-row"><th>' . __('Address Line1', 'usces') . '</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr> <tr class="address3-row delivery-address3-row"><th>' . __('Address Line2', 'usces') . '</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr> <tr class="zipcode-row delivery-zipcode-row"><th>' . __('Zip', 'usces') . '</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr> <tr class="tel-row delivery-tel-row"><th>' . __('Phone number', 'usces') . '</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr>'; } $formtag .= $shipping_address_info; break; case 'US': default: /** * Mirrored Welcart filter * * @ignore */ $formtag .= '<tr v-if="!hideCustomerInfo" class="name-row member-name-row"><th>' . apply_filters('usces_filters_addressform_name_label', __('Full name', 'usces'), $type, $values, $applyform) . '</th><td>' . sprintf(_x('%s', 'honorific', 'usces'), (esc_html($values['customer']['name2']) . ' ' . esc_html($values['customer']['name1']))) . '</td></tr>'; if (usces_is_login()) { $customer_pref = ($values['customer']['pref'] == __('-- Select --', 'usces') || $values['customer']['pref'] == '-- Select --') ? '' : $values['customer']['pref']; $formtag .= ' <tr class="address2-row member-address2-row"><th>' . __('Address Line1', 'usces') . '</th><td>' . esc_html($values['customer']['address2']) . '</td></tr> <tr class="address3-row member-address3-row"><th>' . __('Address Line2', 'usces') . '</th><td>' . esc_html($values['customer']['address3']) . '</td></tr> <tr class="address1-row member-address1-row"><th>' . __('city', 'usces') . '</th><td>' . esc_html($values['customer']['address1']) . '</td></tr> <tr class="states-row member-states-row"><th>' . __('State', 'usces') . '</th><td>' . esc_html($customer_pref) . '</td></tr>'; if (1 < $target_market_count) { $customer_country = (!empty($usces_settings['country'][$values['customer']['country']])) ? $usces_settings['country'][$values['customer']['country']] : ''; $formtag .= '<tr class="country-row member-country-row"><th>' . __('Country', 'usces') . '</th><td>' . esc_html($customer_country) . '</td></tr>'; } $formtag .= ' <tr class="zipcode-row member-zipcode-row"><th>' . __('Zip', 'usces') . '</th><td>' . esc_html($values['customer']['zipcode']) . '</td></tr> <tr class="tel-row member-tel-row"><th>' . __('Phone number', 'usces') . '</th><td>' . esc_html($values['customer']['tel']) . '</td></tr> <tr class="fax-row member-fax-row"><th>' . __('FAX number', 'usces') . '</th><td>' . esc_html($values['customer']['fax']) . '</td></tr>'; } $shipping_address_info = ''; if (isset($values['delivery'])) { $delivery_pref = ($values['delivery']['pref'] == __('-- Select --', 'usces') || $values['delivery']['pref'] == '-- Select --') ? '' : $values['delivery']['pref']; $shipping_address_info = $this->getAddressTableHeader(); /** * Mirrored Welcart filter * * @ignore */ $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters('usces_filters_addressform_name_label', __('Full name', 'usces'), $type, $values, $applyform) . '</th><td>' . sprintf(_x('%s', 'honorific', 'usces'), (esc_html($values['delivery']['name2']) . ' ' . esc_html($values['delivery']['name1']))) . '</td></tr>'; $shipping_address_info .= ' <tr class="address2-row delivery-address2-row"><th>' . __('Address Line1', 'usces') . '</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr> <tr class="address3-row delivery-address3-row"><th>' . __('Address Line2', 'usces') . '</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr> <tr class="address1-row delivery-address1-row"><th>' . __('city', 'usces') . '</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr> <tr class="states-row delivery-states-row"><th>' . __('State', 'usces') . '</th><td>' . esc_html($delivery_pref) . '</td></tr>'; if (1 < $target_market_count) { $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : ''; $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __('Country', 'usces') . '</th><td>' . esc_html($shipping_country) . '</td></tr>'; } $shipping_address_info .= ' <tr class="zipcode-row delivery-zipcode-row"><th>' . __('Zip', 'usces') . '</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr> <tr class="tel-row delivery-tel-row"><th>' . __('Phone number', 'usces') . '</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr>'; } $formtag .= $shipping_address_info; break; } // phpcs:enable echo $formtag; } /** * Returns `配送先情報` table header with update address button * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return string */ public function getAddressTableHeader() { $btnclass = AmazonPay::getThemeConfig()['btnprimary']; ob_start(); ?> <tr class="ttl"> <td colspan="2"> <div class="change-container"> <h3> <span><?php _e('Shipping address information', 'usces'); ?></span> <span> <button style="margin-left: 6px;" id="updateShippingAddressButton" class="ui mini <?php echo $btnclass; ?> button" > <?php _e('Change', 'wcexaap'); ?> </button> </span> </h3> </div> </td> </tr> <?php return ob_get_clean(); } /** * Getter for `checkoutSessionDetails` * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return array */ public function getCheckoutSessionDetails() { return $this->checkoutSessionDetails; } /** * Getter for `addressError` * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return array */ public function getAddressError() { return $this->addressError; } /** * Getter for `checkoutSessionId` * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return array */ public function getCheckoutSessionId() { return $this->checkoutSessionId; } }
- __construct — Sets $module member var. Sets $checkoutSessionId with parameter value
- confirmAddressTable — Adds 'Change Address' button to address table
- getAddressError — Getter for addressError
- getAddressErrorMessageBox — Returns error message box for an address error
- getAddressTableHeader — Returns 配送先情報 table header with update address button
- getCheckoutSessionDetails — Getter for checkoutSessionDetails
- getCheckoutSessionId — Getter for checkoutSessionId
- getComponentName — Returns component name as is recognized by Vue.
- init — Loads assets for this component
- loadAddressErrorMessageBoxCss — Loads CSS for address error box
- template — Amazon checkout details component template.