Skip to content

Commit

Permalink
feat: integrate credit on in page
Browse files Browse the repository at this point in the history
  • Loading branch information
joyet-simon committed Oct 3, 2024
1 parent 58e3463 commit 977683c
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/assets/js/alma-checkout-in-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
function isAlmaInPageChecked() {
return $( '#payment_method_alma_in_page' ).is( ':checked' )
|| $( '#payment_method_alma_in_page_pay_now' ).is( ':checked' )
|| $( '#payment_method_alma_in_page_pay_later' ).is( ':checked' );
|| $( '#payment_method_alma_in_page_pay_later' ).is( ':checked' )
|| $( '#payment_method_alma_in_page_pnx_plus_4' ).is( ':checked' );
}

$( 'body' ).on(
Expand Down
5 changes: 5 additions & 0 deletions src/includes/Admin/Helpers/FormFieldsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ public function init_general_settings_fields( array $default_settings ) {
$title_gateway_in_page = array();
$fields_title_gateway_in_page = array();
$fields_description_gateway_in_page = array();
$fields_in_page_pnx_plus_4 = array();

$general_settings_fields = array(
'general_section' => array(
Expand All @@ -540,6 +541,9 @@ public function init_general_settings_fields( array $default_settings ) {
if ( $this->settings_helper->has_pay_later() ) {
$fields_in_page_pay_later = $this->get_custom_fields_payment_method( ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_LATER, __( 'Deferred Payments:', 'alma-gateway-for-woocommerce' ), $default_settings );
}
if ( $this->settings_helper->has_pnx_plus_4() ) {
$fields_in_page_pnx_plus_4 = $this->get_custom_fields_payment_method( ConstantsHelper::GATEWAY_ID_IN_PAGE_MORE_THAN_FOUR, __( 'Payments in more than 4 installments:', 'alma-gateway-for-woocommerce' ), $default_settings );
}
}

if (
Expand Down Expand Up @@ -606,6 +610,7 @@ public function init_general_settings_fields( array $default_settings ) {
$fields_pay_later,
$fields_in_page_pay_later,
$fields_pnx_plus_4,
$fields_in_page_pnx_plus_4,
$general_settings_fields_end,
$field_cart_not_eligible_message_gift_cards
);
Expand Down
10 changes: 7 additions & 3 deletions src/includes/AlmaPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
use Alma\Woocommerce\Exceptions\VersionDeprecated;
use Alma\Woocommerce\Factories\VersionFactory;
use Alma\Woocommerce\Gateways\Inpage\InPageGateway;
use Alma\Woocommerce\Gateways\Inpage\PayLaterGateway;
use Alma\Woocommerce\Gateways\Inpage\PayLaterGateway as InPagePayLaterGateway;
use Alma\Woocommerce\Gateways\Inpage\PayMoreThanFourGateway as InPagePayMoreThanFourGateway;
use Alma\Woocommerce\Gateways\Inpage\PayNowGateway as InPagePayNowGateway;
use Alma\Woocommerce\Gateways\Standard\PayLaterGateway;
use Alma\Woocommerce\Gateways\Standard\PayMoreThanFourGateway;
use Alma\Woocommerce\Gateways\Standard\PayNowGateway;
use Alma\Woocommerce\Gateways\Standard\StandardGateway;
Expand Down Expand Up @@ -194,12 +197,13 @@ public static function get_instance() {
*/
public function add_gateways( $gateways ) {
if ( ! is_admin() ) {
$gateways[] = \Alma\Woocommerce\Gateways\Inpage\PayNowGateway::class;
$gateways[] = InPagePayNowGateway::class;
$gateways[] = PayNowGateway::class;
$gateways[] = InPageGateway::class;
$gateways[] = PayMoreThanFourGateway::class;
$gateways[] = InPagePayLaterGateway::class;
$gateways[] = InPagePayMoreThanFourGateway::class;
$gateways[] = PayLaterGateway::class;
$gateways[] = \Alma\Woocommerce\Gateways\Standard\PayLaterGateway::class;
}

$gateways[] = StandardGateway::class;
Expand Down
1 change: 1 addition & 0 deletions src/includes/AlmaSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ public function should_display_plan( $plan_key, $gateway_id ) {
$this->get_installments_count( $plan_key ) === 1
&& ( $this->get_deferred_days( $plan_key ) !== 0 || $this->get_deferred_months( $plan_key ) !== 0 )
);
case ConstantsHelper::GATEWAY_ID_IN_PAGE_MORE_THAN_FOUR:
case ConstantsHelper::GATEWAY_ID_MORE_THAN_FOUR:
return ( $this->get_installments_count( $plan_key ) > 4 );
default:
Expand Down
39 changes: 39 additions & 0 deletions src/includes/Gateways/Inpage/PayMoreThanFourGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* PayMoreThanFourGateway.
*
* @since 5.0.0
*
* @package Alma_Gateway_For_Woocommerce
* @subpackage Alma_Gateway_For_Woocommerce//includes/Gateways/Standard
* @namespace Alma\Woocommerce\Gateways\StandardGateway
*/

namespace Alma\Woocommerce\Gateways\Inpage;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

use Alma\Woocommerce\Gateways\AlmaPaymentGateway;
use Alma\Woocommerce\Helpers\ConstantsHelper;
use Alma\Woocommerce\Traits\InPageGatewayTrait;

/**
* PayMoreThanFourGateway
*/
class PayMoreThanFourGateway extends AlmaPaymentGateway {

use InPageGatewayTrait;
/**
* Get the gateway id.
*
* @return string
*/
public function get_gateway_id() {
return ConstantsHelper::GATEWAY_ID_IN_PAGE_MORE_THAN_FOUR;
}



}
17 changes: 10 additions & 7 deletions src/includes/Helpers/ConstantsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
*/
class ConstantsHelper {

const GATEWAY_ID = 'alma';
const GATEWAY_ID_PAY_NOW = 'alma_pay_now';
const GATEWAY_ID_PAY_LATER = 'alma_pay_later';
const GATEWAY_ID_MORE_THAN_FOUR = 'alma_pnx_plus_4';
const GATEWAY_ID_IN_PAGE = 'alma_in_page';
const GATEWAY_ID_IN_PAGE_PAY_NOW = 'alma_in_page_pay_now';
const GATEWAY_ID_IN_PAGE_PAY_LATER = 'alma_in_page_pay_later';
const GATEWAY_ID = 'alma';
const GATEWAY_ID_PAY_NOW = 'alma_pay_now';
const GATEWAY_ID_PAY_LATER = 'alma_pay_later';
const GATEWAY_ID_MORE_THAN_FOUR = 'alma_pnx_plus_4';
const GATEWAY_ID_IN_PAGE = 'alma_in_page';
const GATEWAY_ID_IN_PAGE_PAY_NOW = 'alma_in_page_pay_now';
const GATEWAY_ID_IN_PAGE_PAY_LATER = 'alma_in_page_pay_later';
const GATEWAY_ID_IN_PAGE_MORE_THAN_FOUR = 'alma_in_page_pnx_plus_4';

const JQUERY_CART_UPDATE_EVENT = 'updated_cart_totals';

Expand Down Expand Up @@ -97,6 +98,7 @@ class ConstantsHelper {
self::GATEWAY_ID_PAY_LATER,
self::GATEWAY_ID_IN_PAGE_PAY_LATER,
self::GATEWAY_ID_MORE_THAN_FOUR,
self::GATEWAY_ID_IN_PAGE_MORE_THAN_FOUR,
);

/**
Expand All @@ -108,5 +110,6 @@ class ConstantsHelper {
self::GATEWAY_ID_IN_PAGE,
self::GATEWAY_ID_IN_PAGE_PAY_NOW,
self::GATEWAY_ID_IN_PAGE_PAY_LATER,
self::GATEWAY_ID_IN_PAGE_MORE_THAN_FOUR,
);
}
9 changes: 6 additions & 3 deletions src/includes/Helpers/PlanHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function render_checkout_fields( $eligibilities, $eligible_plans, $gatewa
ConstantsHelper::GATEWAY_ID_IN_PAGE === $gateway_id
|| ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW === $gateway_id
|| ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_LATER === $gateway_id
|| ConstantsHelper::GATEWAY_ID_IN_PAGE_MORE_THAN_FOUR === $gateway_id
) {
$this->render_fields_in_page( $eligible_plans, $gateway_id, $default_plan );
} else {
Expand Down Expand Up @@ -212,10 +213,12 @@ public function order_plans( $eligible_plans = array(), $gateway_id = null ) {
unset( $eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID ] );
unset( $eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_PAY_NOW ] );
unset( $eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_PAY_LATER ] );
unset( $eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_MORE_THAN_FOUR ] );

$eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_IN_PAGE ] = array();
$eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW ] = array();
$eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_LATER ] = array();
$eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_IN_PAGE ] = array();
$eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW ] = array();
$eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_LATER ] = array();
$eligible_plans_by_type[ ConstantsHelper::GATEWAY_ID_IN_PAGE_MORE_THAN_FOUR ] = array();
}

$result = array();
Expand Down
2 changes: 2 additions & 0 deletions src/includes/Helpers/SettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public function default_settings() {
'description_alma_in_page_pay_now' => $this->default_description(),
'title_alma_in_page_pay_later' => $this->default_pay_later_title(),
'description_alma_in_page_pay_later' => $this->default_payment_description(),
'title_alma_in_page_pnx_plus_4' => $this->default_pnx_plus_4_title(),
'description_alma_in_page_pnx_plus_4' => $this->default_payment_description(),
'title_alma' => $this->default_pnx_title(),
'description_alma' => $this->default_payment_description(),
'title_alma_pay_now' => $this->default_pay_now_title(),
Expand Down
3 changes: 3 additions & 0 deletions src/includes/Services/CheckoutService.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public function process_checkout_alma( $post_fields ) {
if ( ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_LATER === $_POST[ ConstantsHelper::PAYMENT_METHOD ] ) {
$posted_data[ ConstantsHelper::PAYMENT_METHOD_TITLE ] = __( 'Pay Later via Alma', 'alma-gateway-for-woocommerce' );
}
if ( ConstantsHelper::GATEWAY_ID_IN_PAGE_MORE_THAN_FOUR === $_POST[ ConstantsHelper::PAYMENT_METHOD ] ) {
$posted_data[ ConstantsHelper::PAYMENT_METHOD_TITLE ] = __( 'Payments in more than 4 installments', 'alma-gateway-for-woocommerce' );
}

// Update session for customer and totals.
$this->update_session( $posted_data );
Expand Down
2 changes: 2 additions & 0 deletions src/tests/Helpers/SettingsHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class SettingsHelperTest extends WP_UnitTestCase {
'keys_validity' => 'no',
'display_in_page' => 'no',
'use_blocks_template' => 'no',
'title_alma_in_page_pnx_plus_4' => 'Pay with financing',
'description_alma_in_page_pnx_plus_4' => 'Fast and secure payment by credit card'
);

protected $alma_settings = '{"enabled":"yes","payment_upon_trigger_enabled":"no","payment_upon_trigger_event":"completed","payment_upon_trigger_display_text":"at_shipping","selected_fee_plan":"general_12_0_0","enabled_general_3_0_0":"yes","title_alma_in_page":"Pay in installments","description_alma_in_page":"Fast and secure payment by credit card","title_alma_in_page_pay_now":"Pay by credit card","description_alma_in_page_pay_now":"Fast and secured payments","title_alma_in_page_pay_later":"Pay later","description_alma_in_page_pay_later":"Fast and secure payment by credit card","title_alma":"Pay in installments","description_alma":"Fast and secure payment by credit card","title_alma_pay_now":"Pay by credit card","description_alma_pay_now":"Fast and secured payments","title_alma_pay_later":"Pay later","description_alma_pay_later":"Fast and secure payment by credit card","title_alma_pnx_plus_4":"Pay with financing","description_alma_pnx_plus_4":"Fast and secure payment by credit card","title_blocks_alma_in_page":"Pay in installments","description_blocks_alma_in_page":"Fast and secure payment by credit card","title_blocks_alma_in_page_pay_now":"Pay by credit card","description_blocks_alma_in_page_pay_now":"Fast and secured payments","title_blocks_alma_in_page_pay_later":"Pay later","description_blocks_alma_in_page_pay_later":"Fast and secure payment by credit card","title_blocks_alma":"Pay in installments","description_blocks_alma":"Fast and secure payment by credit card","title_blocks_alma_pay_now":"Pay by credit card","description_blocks_alma_pay_now":"Fast and secured payments","title_blocks_alma_pay_later":"Pay later","description_blocks_alma_pay_later":"Fast and secure payment by credit card","title_blocks_alma_pnx_plus_4":"Pay with financing","description_blocks_alma_pnx_plus_4":"Fast and secure payment by credit card","display_cart_eligibility":"yes","display_product_eligibility":"yes","variable_product_price_query_selector":"form.variations_form div.woocommerce-variation-price span.woocommerce-Price-amount bdi","variable_product_sale_price_query_selector":"form.variations_form div.woocommerce-variation-price ins span.woocommerce-Price-amount bdi","variable_product_check_variations_event":"check_variations","excluded_products_list":"","cart_not_eligible_message_gift_cards":"Some products cannot be paid with monthly or deferred installments","live_api_key":"","test_api_key":"123","environment":"test","share_of_checkout_enabled":"no","debug":"yes","keys_validity":"yes","display_in_page":"yes","use_blocks_template":"yes","allowed_fee_plans":[{"installments_count":1,"kind":"general","deferred_months":0,"deferred_days":30,"deferred_trigger_limit_days":null,"max_purchase_amount":200000,"min_purchase_amount":5000,"allowed":true,"merchant_fee_variable":500,"merchant_fee_fixed":0,"customer_fee_variable":0,"customer_lending_rate":0,"customer_fee_fixed":0,"id":null,"available_in_pos":true,"capped":false,"deferred_trigger_bypass_scoring":false,"first_installment_ratio":null,"is_under_maximum_interest_regulated_rate":true,"merchant":"merchant_11v4pR74zvoPaF0EldGQRpJo41fP268FSw","payout_on_acceptance":false},{"installments_count":1,"kind":"general","deferred_months":0,"deferred_days":0,"deferred_trigger_limit_days":null,"max_purchase_amount":200000,"min_purchase_amount":50,"allowed":true,"merchant_fee_variable":75,"merchant_fee_fixed":0,"customer_fee_variable":0,"customer_lending_rate":0,"customer_fee_fixed":0,"id":null,"available_in_pos":true,"capped":false,"deferred_trigger_bypass_scoring":false,"first_installment_ratio":null,"is_under_maximum_interest_regulated_rate":true,"merchant":"mon_marchand","payout_on_acceptance":false},{"installments_count":1,"kind":"general","deferred_months":0,"deferred_days":15,"deferred_trigger_limit_days":null,"max_purchase_amount":200000,"min_purchase_amount":5000,"allowed":true,"merchant_fee_variable":440,"merchant_fee_fixed":0,"customer_fee_variable":0,"customer_lending_rate":0,"customer_fee_fixed":0,"id":null,"available_in_pos":true,"capped":false,"deferred_trigger_bypass_scoring":false,"first_installment_ratio":null,"is_under_maximum_interest_regulated_rate":true,"merchant":"merchant_11v4pR74zvoPaF0EldGQRpJo41fP268FSw","payout_on_acceptance":false},{"installments_count":2,"kind":"general","deferred_months":0,"deferred_days":0,"deferred_trigger_limit_days":null,"max_purchase_amount":200000,"min_purchase_amount":5000,"allowed":true,"merchant_fee_variable":340,"merchant_fee_fixed":0,"customer_fee_variable":0,"customer_lending_rate":0,"customer_fee_fixed":0,"id":null,"available_in_pos":true,"capped":false,"deferred_trigger_bypass_scoring":false,"first_installment_ratio":null,"is_under_maximum_interest_regulated_rate":true,"merchant":"merchant_11v4pR74zvoPaF0EldGQRpJo41fP268FSw","payout_on_acceptance":false},{"installments_count":3,"kind":"general","deferred_months":0,"deferred_days":0,"deferred_trigger_limit_days":null,"max_purchase_amount":200000,"min_purchase_amount":5000,"allowed":true,"merchant_fee_variable":261,"merchant_fee_fixed":0,"customer_fee_variable":99,"customer_lending_rate":0,"customer_fee_fixed":0,"id":null,"available_in_pos":true,"capped":false,"deferred_trigger_bypass_scoring":false,"first_installment_ratio":null,"is_under_maximum_interest_regulated_rate":true,"merchant":"merchant_11v4pR74zvoPaF0EldGQRpJo41fP268FSw","payout_on_acceptance":false},{"installments_count":4,"kind":"general","deferred_months":0,"deferred_days":0,"deferred_trigger_limit_days":null,"max_purchase_amount":200000,"min_purchase_amount":5000,"allowed":true,"merchant_fee_variable":439,"merchant_fee_fixed":0,"customer_fee_variable":1,"customer_lending_rate":0,"customer_fee_fixed":0,"id":null,"available_in_pos":true,"capped":false,"deferred_trigger_bypass_scoring":false,"first_installment_ratio":null,"is_under_maximum_interest_regulated_rate":true,"merchant":"merchant_11v4pR74zvoPaF0EldGQRpJo41fP268FSw","payout_on_acceptance":false},{"installments_count":10,"kind":"general","deferred_months":0,"deferred_days":0,"deferred_trigger_limit_days":null,"max_purchase_amount":200000,"min_purchase_amount":5000,"allowed":true,"merchant_fee_variable":380,"merchant_fee_fixed":0,"customer_fee_variable":0,"customer_lending_rate":0,"customer_fee_fixed":0,"id":null,"available_in_pos":true,"capped":false,"deferred_trigger_bypass_scoring":false,"first_installment_ratio":null,"is_under_maximum_interest_regulated_rate":true,"merchant":"merchant_11v4pR74zvoPaF0EldGQRpJo41fP268FSw","payout_on_acceptance":false},{"installments_count":12,"kind":"general","deferred_months":0,"deferred_days":0,"deferred_trigger_limit_days":null,"max_purchase_amount":200000,"min_purchase_amount":5000,"allowed":true,"merchant_fee_variable":380,"merchant_fee_fixed":0,"customer_fee_variable":0,"customer_lending_rate":0,"customer_fee_fixed":0,"id":null,"available_in_pos":true,"capped":false,"deferred_trigger_bypass_scoring":false,"first_installment_ratio":null,"is_under_maximum_interest_regulated_rate":true,"merchant":"merchant_11v4pR74zvoPaF0EldGQRpJo41fP268FSw","payout_on_acceptance":false}],"live_merchant_id":null,"test_merchant_id":"merchant_11v4pR74zvoPaF0EldGQRpJo41fP268FSw","test_merchant_name":"Claire","min_amount_general_1_30_0":5000,"max_amount_general_1_30_0":200000,"enabled_general_1_30_0":"yes","deferred_months_general_1_30_0":0,"deferred_days_general_1_30_0":30,"installments_count_general_1_30_0":1,"min_amount_general_1_0_0":100,"max_amount_general_1_0_0":200000,"enabled_general_1_0_0":"yes","deferred_months_general_1_0_0":0,"deferred_days_general_1_0_0":0,"installments_count_general_1_0_0":1,"min_amount_general_1_15_0":5000,"max_amount_general_1_15_0":200000,"enabled_general_1_15_0":"yes","deferred_months_general_1_15_0":0,"deferred_days_general_1_15_0":15,"installments_count_general_1_15_0":1,"min_amount_general_2_0_0":5000,"max_amount_general_2_0_0":200000,"enabled_general_2_0_0":"yes","deferred_months_general_2_0_0":0,"deferred_days_general_2_0_0":0,"installments_count_general_2_0_0":2,"min_amount_general_3_0_0":5000,"max_amount_general_3_0_0":200000,"deferred_months_general_3_0_0":0,"deferred_days_general_3_0_0":0,"installments_count_general_3_0_0":3,"min_amount_general_4_0_0":5000,"max_amount_general_4_0_0":200000,"enabled_general_4_0_0":"yes","deferred_months_general_4_0_0":0,"deferred_days_general_4_0_0":0,"installments_count_general_4_0_0":4,"min_amount_general_10_0_0":5000,"max_amount_general_10_0_0":200000,"enabled_general_10_0_0":"yes","deferred_months_general_10_0_0":0,"deferred_days_general_10_0_0":0,"installments_count_general_10_0_0":10,"min_amount_general_12_0_0":5000,"max_amount_general_12_0_0":200000,"enabled_general_12_0_0":"yes","deferred_months_general_12_0_0":0,"deferred_days_general_12_0_0":0,"installments_count_general_12_0_0":12}';
Expand Down

0 comments on commit 977683c

Please sign in to comment.