| @@ -4,46 +4,56 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package SeQura/WC |
| 6 | 6 | * @var string $args The arguments. Must contain: |
| 7 | 7 | * - description: string |
| 8 | - * - payment_methods: array<string, mixed> | |
| 8 | + * - payment_methods: Payment_Method_Option[] | |
| 9 | + * - cart_total: int The cart total in cents. | |
| 9 | 10 | */ |
| 10 | 11 | |
| 11 | -use SeQura\WC\Dto\Payment_Method_Data; | |
| 12 | +use SeQura\WC\Dto\Payment_Method_Option; | |
| 12 | 13 | |
| 13 | 14 | defined( 'WPINC' ) || die; |
| 14 | -if ( ! isset( $args['description'], $args['payment_methods'] ) ) { | |
| 15 | +if ( ! isset( $args['description'], $args['payment_methods'], $args['cart_total'] ) ) { | |
| 15 | 16 | return; |
| 16 | 17 | } |
| 17 | 18 | ?> |
| 18 | - | |
| 19 | 19 | <span class="sequra-block__description"><?php echo wp_kses_post( wpautop( wptexturize( $args['description'] ) ) ); ?></span> |
| 20 | 20 | <?php |
| 21 | +/** | |
| 22 | + * Payment methods | |
| 23 | + * | |
| 24 | + * @var Payment_Method_Option $pm | |
| 25 | + */ | |
| 21 | 26 | foreach ( (array) $args['payment_methods'] as $key => $pm ) : |
| 22 | - /** | |
| 23 | - * Dto | |
| 24 | - * | |
| 25 | - * @var Payment_Method_Data $dto | |
| 26 | - */ | |
| 27 | - $dto = Payment_Method_Data::from_array( $pm ); | |
| 28 | - if ( ! $dto || ! $dto->is_valid() ) { | |
| 29 | - continue; | |
| 27 | + if ( ! $pm instanceof Payment_Method_Option || ! $pm->is_valid() ) { | |
| 28 | + continue; | |
| 30 | 29 | } |
| 31 | 30 | |
| 32 | - $input_id = "sequra_payment_method_{$key}"; | |
| 31 | + $input_id = "sequra_payment_method_{$key}"; | |
| 32 | + $more_info = ''; | |
| 33 | + if ( $pm->should_show_more_info() ) { | |
| 34 | + $more_info = sprintf( | |
| 35 | + '<span class="sequra-educational-popup sequra_more_info" data-amount="%s" data-product="%s" data-campaign="%s" rel="sequra_invoice_popup_checkout" title="%s">%s</span>', | |
| 36 | + esc_attr( (string) $args['cart_total'] ), | |
| 37 | + esc_attr( (string) $pm->product ), | |
| 38 | + esc_attr( (string) ( $pm->campaign ?? '' ) ), | |
| 39 | + esc_attr__( 'More information', 'sequra' ), | |
| 40 | + esc_html__( '+info', 'sequra' ) | |
| 41 | + ); | |
| 42 | + } | |
| 33 | 43 | ?> |
| 34 | 44 | <div class="sequra-payment-method"> |
| 35 | - <input type="radio" name="sequra_payment_method_data" value="<?php echo esc_attr( $dto->encode() ); ?>" id="<?php echo esc_attr( $input_id ); ?>" class="sequra-payment-method__input wc-block-components-radio-control__input" /> | |
| 45 | + <input type="radio" name="sequra_payment_method_data" value="<?php echo esc_attr( $pm->encode_data() ); ?>" id="<?php echo esc_attr( $input_id ); ?>" class="sequra-payment-method__input wc-block-components-radio-control__input" /> | |
| 36 | 46 | <label for="<?php echo esc_attr( $input_id ); ?>"> |
| 37 | 47 | <div class="sequra-payment-method__description"> |
| 38 | - <span class="sequra-payment-method__name" style="width:100%"><?php echo esc_html( $pm['title'] ); ?></span> | |
| 39 | - <span class="sequra-payment-method__claim" style="width:100%"><?php echo esc_html( $pm['claim'] ); ?></span> | |
| 40 | - <?php if ( ! empty( $pm['costDescription'] ) ) : ?> | |
| 41 | - <span class="sequra-payment-method__cost-desc" style="width:100%"><?php echo esc_html( $pm['costDescription'] ); ?></span> | |
| 48 | + <span class="sequra-payment-method__name" style="width:100%"><?php echo esc_html( (string) empty( $pm->long_title ) ? $pm->title : $pm->long_title ); ?></span> | |
| 49 | + <span class="sequra-payment-method__claim" style="width:100%"><?php echo esc_html( (string) ( $pm->claim ?? '' ) ); ?> <?php echo wp_kses_post( $more_info ); ?></span> | |
| 50 | + <?php if ( $pm->should_show_cost_description() ) : ?> | |
| 51 | + <span class="sequra-payment-method__cost-desc" style="width:100%"><?php echo esc_html( (string) $pm->cost_description ); ?></span> | |
| 42 | 52 | <?php endif; ?> |
| 43 | 53 | </div> |
| 44 | - <?php if ( ! empty( $pm['icon'] ) ) : ?> | |
| 45 | - <img src="data:image/svg+xml;base64,<?php echo esc_attr( base64_encode( $pm['icon'] ) ); ?>" height="40px" loading="lazy" alt="<?php echo esc_attr( $pm['title'] ); ?>" class="sequra-payment-method__icon" /> | |
| 54 | + <?php if ( $pm->icon ) : ?> | |
| 55 | + <img src="data:image/svg+xml;base64,<?php echo esc_attr( base64_encode( (string) ( $pm->icon ?? '' ) ) ); ?>" height="40px" loading="lazy" alt="<?php echo esc_attr( $pm->title ); ?>" class="sequra-payment-method__icon" /> | |
| 46 | 56 | <?php endif; ?> |
| 47 | 57 | </label> |
| 48 | 58 | </div> |
| 49 | -<?php endforeach; ?> | |
| 59 | +<?php endforeach; ?> | |