Skip to content

Commit

Permalink
Fixed save card in WC block.
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishgurung committed Aug 6, 2024
1 parent 915ac4e commit 2b1eb51
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion includes/blocks/assets/js/build/credit_card.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '724dd47b1b5d55c38a76e60fc98ffc12');
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '5064f6bb58dd3352c00f30554738304a');
2 changes: 1 addition & 1 deletion includes/blocks/assets/js/build/credit_card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion includes/blocks/assets/js/credit_card/credit-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const CreditCardPaymentMethod = (props) => {
type: emitResponse.responseTypes.SUCCESS,
meta: {
paymentMethodData: {
"omise_save_customer_card": saveCardRef.current.value,
"omise_save_customer_card": saveCardRef.current,
"omise_token": cardTokenRef.current,
}
}
Expand Down
23 changes: 22 additions & 1 deletion includes/class-omise-capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,28 @@ public static function shouldCallApi() {
// If endpoint url is `order-received`, it mean thank you page.
$isPaymentPage = is_checkout() && !is_wc_endpoint_url( 'order-received' );

return $isPaymentPage || $isOmiseSettingPage;
global $wp;
$isFromCheckout = !$wp
? false
: strpos($wp->request, '/checkout') === strlen($wp->request) - strlen('/checkout');

return $isPaymentPage || $isOmiseSettingPage || $isFromCheckout;
}

/**
* Checks if checkout is the current page.
*
* @return boolean
*/
public static function better_is_checkout() {
$checkout_path = wp_parse_url(wc_get_checkout_url(), PHP_URL_PATH);
$current_url_path = wp_parse_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", PHP_URL_PATH);

return (
$checkout_path !== null
&& $current_url_path !== null
&& trailingslashit($checkout_path) === trailingslashit($current_url_path)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/class-omise-wc-myaccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct() {
public function init_panel() {
if ( ! empty( $this->omise_customer_id ) ) {
try {
$viewData['existingCards'] = $this->customerCard->get($this->omise_customer_id);
$viewData['existing_cards'] = $this->customerCard->get($this->omise_customer_id)['data'];
$viewData['cardFormTheme'] = $this->omiseCardGateway->get_option('card_form_theme');
$viewData['secure_form_enabled'] = (boolean)$this->omiseCardGateway->get_option('secure_form_enabled');
$viewData['formDesign'] = Omise_Page_Card_From_Customization::get_instance()->get_design_setting();
Expand Down
3 changes: 2 additions & 1 deletion includes/gateway/class-omise-payment-creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public function get_existing_cards() {
if ( ! empty( $omise_customer_id ) ) {
try {
$cards = new OmiseCustomerCard;
$data['existingCards'] = $cards->get($omise_customer_id);
$existingCards = $cards->get($omise_customer_id);
$data['existing_cards'] = $existingCards['data'];
} catch (Exception $e) {
// nothing
}
Expand Down
4 changes: 2 additions & 2 deletions templates/myaccount/my-card.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<th><?php _e( 'Action', 'omise' ); ?></th>
</tr>
<tbody>
<?php if ( isset( $viewData['existingCards']['data'] ) ): ?>
<?php foreach( $viewData['existingCards']['data'] as $card ): ?>
<?php if ( isset( $viewData['existing_cards'] ) ): ?>
<?php foreach( $viewData['existing_cards'] as $card ): ?>
<?php
$nonce = wp_create_nonce( 'omise_delete_card_' . $card['id'] );
$created_date = date_i18n( get_option( 'date_format' ), strtotime($card['created']));
Expand Down
4 changes: 2 additions & 2 deletions templates/payment/form.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
$showExistingCards = $viewData['user_logged_in'] && isset($viewData['existingCards']['data']) && sizeof($viewData['existingCards']['data']) > 0;
$showExistingCards = $viewData['user_logged_in'] && isset($viewData['existing_cards']) && sizeof($viewData['existing_cards']) > 0;
$hideRememberCard = $viewData['user_logged_in'] ? 'no' : 'yes';
?>

<div id="omise_cc_form">
<?php if ($showExistingCards) : ?>
<h3><?php _e('Use an existing card', 'omise'); ?></h3>
<ul class="omise-customer-card-list">
<?php foreach ($viewData['existingCards']['data'] as $row => $card) : ?>
<?php foreach ($viewData['existing_cards'] as $row => $card) : ?>
<li class="item">
<input <?php echo $row === 0 ? 'checked=checked' : ''; ?> id="card-<?php echo $card['id']; ?>" type="radio" name="card_id" value="<?php echo $card['id']; ?>" />
<label for="card-<?php echo $card['id']; ?>">
Expand Down

0 comments on commit 2b1eb51

Please sign in to comment.