ver. 0.269: ShopPaymentMethod refactor + Apilo keepalive
This commit is contained in:
@@ -1,19 +1,43 @@
|
||||
<?
|
||||
$settings = is_array( $this -> settings ) ? $this -> settings : [];
|
||||
|
||||
$apilo_status = is_array( $this -> apilo_status ) ? $this -> apilo_status : [
|
||||
'is_valid' => false,
|
||||
'severity' => 'warning',
|
||||
'message' => 'Brak statusu integracji.',
|
||||
];
|
||||
|
||||
$status_class = 'alert-warning';
|
||||
if ( isset( $apilo_status['severity'] ) && $apilo_status['severity'] == 'success' ) $status_class = 'alert-success';
|
||||
if ( isset( $apilo_status['severity'] ) && $apilo_status['severity'] == 'danger' ) $status_class = 'alert-danger';
|
||||
|
||||
$status_message = trim( (string)($apilo_status['message'] ?? '') );
|
||||
if ( $status_message == '' ) $status_message = 'Brak szczegolow statusu integracji.';
|
||||
|
||||
$platform_list_raw = isset( $settings['platform-list'] ) ? $settings['platform-list'] : '';
|
||||
$platform_list = @unserialize( $platform_list_raw );
|
||||
if ( !is_array( $platform_list ) ) $platform_list = [];
|
||||
?>
|
||||
<div class="panel panel-danger">
|
||||
<div class="panel-heading">
|
||||
<span class="panel-title">Ustawienia apilo.com</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="alert <?= $status_class;?> mb15">
|
||||
<b>Status integracji Apilo:</b> <?= $status_message;?>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację z apilo.com</label>
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Wlacz synchronizacje z apilo.com</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select class="form-control" id="enabled" name="enabled">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<option value="0" <? if ( !$this -> settings['enabled'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( $this -> settings['enabled'] ):?>selected<? endif;?>>tak</option>
|
||||
<option value="0" <? if ( !isset($settings['enabled']) || !$settings['enabled'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( isset($settings['enabled']) && $settings['enabled'] ):?>selected<? endif;?>>tak</option>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="enabled">
|
||||
<i class="fa fa-save"></i>
|
||||
@@ -22,15 +46,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację produktów</label>
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Wlacz synchronizacje produktow</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select class="form-control" id="sync_products" name="sync_products">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<option value="0" <? if ( !$this -> settings['sync_products'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( $this -> settings['sync_products'] ):?>selected<? endif;?>>tak</option>
|
||||
<option value="0" <? if ( !isset($settings['sync_products']) || !$settings['sync_products'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( isset($settings['sync_products']) && $settings['sync_products'] ):?>selected<? endif;?>>tak</option>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="sync_products">
|
||||
<i class="fa fa-save"></i>
|
||||
@@ -39,15 +64,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację zamówień</label>
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Wlacz synchronizacje zamowien</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select class="form-control" id="sync_orders" name="sync_orders">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<option value="0" <? if ( !$this -> settings['sync_orders'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( $this -> settings['sync_orders'] ):?>selected<? endif;?>>tak</option>
|
||||
<option value="0" <? if ( !isset($settings['sync_orders']) || !$settings['sync_orders'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( isset($settings['sync_orders']) && $settings['sync_orders'] ):?>selected<? endif;?>>tak</option>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="sync_orders">
|
||||
<i class="fa fa-save"></i>
|
||||
@@ -56,12 +82,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Data rozpoczęcia synchronizacji zamówień</label>
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Data rozpoczecia synchronizacji zamowien</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="sync_orders_date_start" name="sync_orders_date_start" placeholder="" value="<?= $this -> settings['sync_orders_date_start'];?>">
|
||||
<input class="form-control" type="text" id="sync_orders_date_start" name="sync_orders_date_start" value="<?= isset($settings['sync_orders_date_start']) ? $settings['sync_orders_date_start'] : '';?>">
|
||||
<span class="input-group-addon cursor" field-id="sync_orders_date_start">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
@@ -69,18 +96,20 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Platforma</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<?
|
||||
$platform_list = unserialize( $this -> settings['platform-list'] );
|
||||
?>
|
||||
<select class="form-control" id="platform-id" name="platform-id">
|
||||
<option value="">--- wybierz platformę ---</option>
|
||||
<option value="">--- wybierz platforme ---</option>
|
||||
<? foreach ( $platform_list as $platform ):?>
|
||||
<option value="<?= $platform['id'];?>" <? if ( $this -> settings['platform-id'] == $platform['id'] ):?>selected<? endif;?>><?= $platform['name'];?> <?= $platform['description'];?></option>
|
||||
<? if ( is_array($platform) && isset($platform['id']) ):?>
|
||||
<option value="<?= $platform['id'];?>" <? if ( isset($settings['platform-id']) && $settings['platform-id'] == $platform['id'] ):?>selected<? endif;?>>
|
||||
<?= isset($platform['name']) ? $platform['name'] : '';?> <?= isset($platform['description']) ? $platform['description'] : '';?>
|
||||
</option>
|
||||
<? endif;?>
|
||||
<? endforeach;?>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="platform-id">
|
||||
@@ -90,12 +119,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Client ID</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="client-id" name="client-id" placeholder="" value="<?= $this -> settings['client-id'];?>">
|
||||
<input class="form-control" type="text" id="client-id" name="client-id" value="<?= isset($settings['client-id']) ? $settings['client-id'] : '';?>">
|
||||
<span class="input-group-addon cursor" field-id="client-id">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
@@ -103,12 +133,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Client Secret</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="client-secret" name="client-secret" placeholder="" value="<?= $this -> settings['client-secret'];?>">
|
||||
<input class="form-control" type="text" id="client-secret" name="client-secret" value="<?= isset($settings['client-secret']) ? $settings['client-secret'] : '';?>">
|
||||
<span class="input-group-addon cursor" field-id="client-secret">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
@@ -116,12 +147,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">ID cennika</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="pricelist_id" name="pricelist_id" placeholder="" value="<?= $this -> settings['pricelist_id'];?>">
|
||||
<input class="form-control" type="text" id="pricelist_id" name="pricelist_id" value="<?= isset($settings['pricelist_id']) ? $settings['pricelist_id'] : '';?>">
|
||||
<span class="input-group-addon cursor" field-id="pricelist_id">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
@@ -129,86 +161,89 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Authorization Code</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="authorization-code" name="authorization-code" placeholder="" value="<?= $this -> settings['authorization-code'];?>" <? if ( $this -> settings['access-token'] ):?>readonly<? endif;?>>
|
||||
<? if ( !$this -> settings['access-token'] ):?>
|
||||
<input class="form-control" type="text" id="authorization-code" name="authorization-code" value="<?= isset($settings['authorization-code']) ? $settings['authorization-code'] : '';?>">
|
||||
<span class="input-group-addon cursor" field-id="authorization-code">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
<? endif;?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<? if ( $this -> settings['access-token'] ):?>
|
||||
|
||||
<? if ( !empty($settings['access-token']) ):?>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Access Token</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="access-token" name="access-token" placeholder="" value="<?= $this -> settings['access-token'];?>" readonly>
|
||||
<input class="form-control" type="text" id="access-token" name="access-token" value="<?= $settings['access-token'];?>" readonly>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<? endif;?>
|
||||
<? if ( $this -> settings['access-token-expire-at'] ):?>
|
||||
|
||||
<? if ( !empty($settings['access-token-expire-at']) ):?>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Access Token Expire At</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="access-token-expire-at" name="access-token-expire-at" placeholder="" value="<?= $this -> settings['access-token-expire-at'];?>" readonly>
|
||||
<input class="form-control" type="text" id="access-token-expire-at" name="access-token-expire-at" value="<?= $settings['access-token-expire-at'];?>" readonly>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<? endif;?>
|
||||
<? if ( $this -> settings['refresh-token'] ):?>
|
||||
|
||||
<? if ( !empty($settings['refresh-token']) ):?>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Refresh Token</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="refresh-token" name="refresh-token" placeholder="" value="<?= $this -> settings['refresh-token'];?>" readonly>
|
||||
<input class="form-control" type="text" id="refresh-token" name="refresh-token" value="<?= $settings['refresh-token'];?>" readonly>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<? endif;?>
|
||||
<? if ( $this -> settings['refresh-token-expire-at'] ):?>
|
||||
|
||||
<? if ( !empty($settings['refresh-token-expire-at']) ):?>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Refresh Token Expire At</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="refresh-token-expire-at" name="refresh-token-expire-at" placeholder="" value="<?= $this -> settings['refresh-token-expire-at'];?>" readonly>
|
||||
<input class="form-control" type="text" id="refresh-token-expire-at" name="refresh-token-expire-at" value="<?= $settings['refresh-token-expire-at'];?>" readonly>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<? endif;?>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6">
|
||||
<? if ( !$this -> settings['access-token'] ):?>
|
||||
<a href="#" class="btn btn-primary btn-block apilo-authorization">Autoryzuj się w apilo.com</a>
|
||||
<? else:?>
|
||||
<a href="/admin/integrations/get_payment_types_list/" class="btn btn-primary btn-block">Pobierz listę metod płatności</a>
|
||||
<a href="/admin/integrations/get_carrier_account_list/" class="btn btn-primary btn-block">Pobierz listę kont przewoźników</a>
|
||||
<a href="/admin/integrations/get_status_types_list/" class="btn btn-primary btn-block">Pobierz statusy zamówień</a>
|
||||
<a href="/admin/integrations/get_platform_list/" class="btn btn-primary btn-block">Pobierz listę platform</a>
|
||||
<? endif;?>
|
||||
<a href="#" class="btn btn-primary btn-block apilo-authorization"><? if ( !empty($apilo_status['is_valid']) ):?>Ponow autoryzacje w apilo.com<? else:?>Autoryzuj sie w apilo.com<? endif;?></a>
|
||||
<a href="/admin/integrations/get_payment_types_list/" class="btn btn-primary btn-block">Pobierz liste metod platnosci</a>
|
||||
<a href="/admin/integrations/get_carrier_account_list/" class="btn btn-primary btn-block">Pobierz liste kont przewoznikow</a>
|
||||
<a href="/admin/integrations/get_status_types_list/" class="btn btn-primary btn-block">Pobierz statusy zamowien</a>
|
||||
<a href="/admin/integrations/get_platform_list/" class="btn btn-primary btn-block">Pobierz liste platform</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$( 'body' ).on( 'click', '.apilo-authorization', function() {
|
||||
$( 'body' ).on( 'click', '.apilo-authorization', function(e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
url: '/admin/integrations/apilo_authorization/',
|
||||
type: 'POST',
|
||||
@@ -216,7 +251,12 @@
|
||||
response = JSON.parse( response );
|
||||
if ( response.status == 'ok' ) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert( response.msg || 'Autoryzacja nieudana.' );
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert('Nie udalo sie polaczyc z endpointem autoryzacji.');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -238,10 +278,10 @@
|
||||
$('#' + field_id).closest('.form-group').addClass('has-success');
|
||||
setTimeout(function() {
|
||||
$('#' + field_id).closest('.form-group').removeClass('has-success');
|
||||
}, 5000);
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1 @@
|
||||
<?= \Tpl::view('components/form-edit', ['form' => $this->form]); ?>
|
||||
@@ -0,0 +1 @@
|
||||
<?= \Tpl::view('components/table-list', ['list' => $this->viewModel]); ?>
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
global $gdb;
|
||||
foreach ( $this -> apilo_payment_types_list as $payment_type )
|
||||
{
|
||||
if ( isset( $payment_type['name'] ) && isset( $payment_type['id'] ) )
|
||||
$payment_types[ $payment_type['id'] ] = $payment_type['name'];
|
||||
}
|
||||
|
||||
$grid = new \grid( 'pp_shop_payment_methods' );
|
||||
$grid -> gdb_opt = $gdb;
|
||||
$grid -> debug = true;
|
||||
$grid -> order = [ 'column' => 'id', 'type' => 'ASC' ];
|
||||
$grid -> search = [
|
||||
[ 'name' => 'Nazwa', 'db' => 'name', 'type' => 'text' ],
|
||||
[ 'name' => 'Aktywny', 'db' => 'status', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ]
|
||||
];
|
||||
$grid -> columns_view = [
|
||||
[
|
||||
'name' => 'Lp.',
|
||||
'th' => [ 'class' => 'g-lp' ],
|
||||
'td' => [ 'class' => 'g-center' ],
|
||||
'autoincrement' => true
|
||||
], [
|
||||
'name' => 'Nazwa',
|
||||
'db' => 'name'
|
||||
], [
|
||||
'name' => 'Aktywny',
|
||||
'db' => 'status',
|
||||
'replace' => [ 'array' => [ 0 => '<span style="color: #FF0000;">nie</span>', 1 => 'tak' ] ],
|
||||
'td' => [ 'class' => 'g-center' ],
|
||||
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ]
|
||||
], [
|
||||
'name' => 'Typ płatności Apilo',
|
||||
'db' => 'apilo_payment_type_id',
|
||||
'replace' => [ 'array' => $payment_types ],
|
||||
'td' => [ 'class' => 'g-center' ],
|
||||
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ]
|
||||
]
|
||||
];
|
||||
|
||||
$grid -> columns_edit = [
|
||||
[
|
||||
'name' => 'Nazwa',
|
||||
'db' => 'name',
|
||||
'type' => 'text',
|
||||
'readonly-edit' => true
|
||||
], [
|
||||
'name' => 'Opis',
|
||||
'db' => 'description',
|
||||
'type' => 'textarea'
|
||||
], [
|
||||
'db' => 'apilo_payment_type_id',
|
||||
'type' => 'select',
|
||||
'name' => 'Typ płatności Apilo',
|
||||
'replace' => [ 'array' => $payment_types ],
|
||||
], [
|
||||
'name' => 'Aktywny',
|
||||
'db' => 'status',
|
||||
'type' => 'select',
|
||||
'default_value' => 1,
|
||||
'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ]
|
||||
]
|
||||
];
|
||||
$grid -> actions = [ 'edit' => true ];
|
||||
echo $grid -> draw();
|
||||
@@ -71,7 +71,7 @@
|
||||
</li>
|
||||
<li><a href="/admin/shop_attribute/view_list/"><img src="/admin/layout/icon/icon-menu/star-filled.svg">Cechy produktów</a></li>
|
||||
<li><a href="/admin/shop_transport/view_list/"><img src="/admin/layout/icon/icon-menu/bus.svg">Rodzaje transportu</a></li>
|
||||
<li><a href="/admin/shop_payment_method/view_list/"><img src="/admin/layout/icon/icon-menu/coins-fill.svg">Metody płatności</a></li>
|
||||
<li><a href="/admin/shop_payment_method/list/"><img src="/admin/layout/icon/icon-menu/coins-fill.svg">Metody płatności</a></li>
|
||||
<li>
|
||||
<a href="/admin/shop_statuses/list/"><i class="fa fa-bars"></i>Statusy zamówień</a>
|
||||
</li>
|
||||
|
||||
@@ -110,20 +110,83 @@ class IntegrationsRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
public function apiloGetAccessToken(): ?string
|
||||
public function apiloGetAccessToken( int $refreshLeadSeconds = 300 ): ?string
|
||||
{
|
||||
$settings = $this->getSettings( 'apilo' );
|
||||
|
||||
if ( empty( $settings['access-token-expire-at'] ) || empty( $settings['access-token'] ) )
|
||||
$hasRefreshCredentials = !empty( $settings['refresh-token'] )
|
||||
&& !empty( $settings['client-id'] )
|
||||
&& !empty( $settings['client-secret'] );
|
||||
|
||||
$accessToken = trim( (string)($settings['access-token'] ?? '') );
|
||||
$accessTokenExpireAt = trim( (string)($settings['access-token-expire-at'] ?? '') );
|
||||
|
||||
if ( $accessToken !== '' && $accessTokenExpireAt !== '' ) {
|
||||
if ( !$this->shouldRefreshAccessToken( $accessTokenExpireAt, $refreshLeadSeconds ) ) {
|
||||
return $accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$hasRefreshCredentials ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$expireAt = new \DateTime( $settings['access-token-expire-at'] );
|
||||
$now = new \DateTime( date( 'Y-m-d H:i:s' ) );
|
||||
if (
|
||||
!empty( $settings['refresh-token-expire-at'] ) &&
|
||||
!$this->isFutureDate( (string)$settings['refresh-token-expire-at'] )
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( $expireAt >= $now )
|
||||
return $settings['access-token'];
|
||||
return $this->refreshApiloAccessToken( $settings );
|
||||
}
|
||||
|
||||
// Token expired - refresh
|
||||
/**
|
||||
* Keepalive tokenu Apilo do uzycia w CRON.
|
||||
* Odswieza token, gdy wygasa lub jest bliski wygasniecia.
|
||||
*
|
||||
* @return array{success:bool,skipped:bool,message:string}
|
||||
*/
|
||||
public function apiloKeepalive( int $refreshLeadSeconds = 300 ): array
|
||||
{
|
||||
$settings = $this->getSettings( 'apilo' );
|
||||
|
||||
if ( (int)($settings['enabled'] ?? 0) !== 1 ) {
|
||||
return [
|
||||
'success' => false,
|
||||
'skipped' => true,
|
||||
'message' => 'Apilo disabled.',
|
||||
];
|
||||
}
|
||||
|
||||
if ( empty( $settings['client-id'] ) || empty( $settings['client-secret'] ) ) {
|
||||
return [
|
||||
'success' => false,
|
||||
'skipped' => true,
|
||||
'message' => 'Missing Apilo credentials.',
|
||||
];
|
||||
}
|
||||
|
||||
$token = $this->apiloGetAccessToken( $refreshLeadSeconds );
|
||||
if ( !$token ) {
|
||||
return [
|
||||
'success' => false,
|
||||
'skipped' => false,
|
||||
'message' => 'Unable to refresh Apilo token.',
|
||||
];
|
||||
}
|
||||
|
||||
$this->saveSetting( 'apilo', 'token-keepalive-at', date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'skipped' => false,
|
||||
'message' => 'Apilo token keepalive OK.',
|
||||
];
|
||||
}
|
||||
|
||||
private function refreshApiloAccessToken( array $settings ): ?string
|
||||
{
|
||||
$postData = [
|
||||
'grantType' => 'refresh_token',
|
||||
'token' => $settings['refresh-token'],
|
||||
@@ -147,17 +210,102 @@ class IntegrationsRepository
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
if ( empty( $response['accessToken'] ) )
|
||||
if ( empty( $response['accessToken'] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->saveSetting( 'apilo', 'access-token', $response['accessToken'] );
|
||||
$this->saveSetting( 'apilo', 'refresh-token', $response['refreshToken'] );
|
||||
$this->saveSetting( 'apilo', 'access-token-expire-at', $response['accessTokenExpireAt'] );
|
||||
$this->saveSetting( 'apilo', 'refresh-token-expire-at', $response['refreshTokenExpireAt'] );
|
||||
$this->saveSetting( 'apilo', 'refresh-token', $response['refreshToken'] ?? ( $settings['refresh-token'] ?? '' ) );
|
||||
$this->saveSetting( 'apilo', 'access-token-expire-at', $response['accessTokenExpireAt'] ?? null );
|
||||
$this->saveSetting( 'apilo', 'refresh-token-expire-at', $response['refreshTokenExpireAt'] ?? null );
|
||||
|
||||
return $response['accessToken'];
|
||||
}
|
||||
|
||||
private function shouldRefreshAccessToken( string $expiresAtRaw, int $leadSeconds = 300 ): bool
|
||||
{
|
||||
try {
|
||||
$expiresAt = new \DateTime( $expiresAtRaw );
|
||||
} catch ( \Exception $e ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$threshold = new \DateTime( date( 'Y-m-d H:i:s', time() + max( 0, $leadSeconds ) ) );
|
||||
return $expiresAt <= $threshold;
|
||||
}
|
||||
|
||||
private function isFutureDate( string $dateRaw ): bool
|
||||
{
|
||||
try {
|
||||
$date = new \DateTime( $dateRaw );
|
||||
} catch ( \Exception $e ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $date > new \DateTime( date( 'Y-m-d H:i:s' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdza aktualny stan integracji Apilo i zwraca komunikat dla UI.
|
||||
*
|
||||
* @return array{is_valid:bool,severity:string,message:string}
|
||||
*/
|
||||
public function apiloIntegrationStatus(): array
|
||||
{
|
||||
$settings = $this->getSettings( 'apilo' );
|
||||
|
||||
$missing = [];
|
||||
foreach ( [ 'client-id', 'client-secret' ] as $field ) {
|
||||
if ( trim( (string)($settings[$field] ?? '') ) === '' )
|
||||
$missing[] = $field;
|
||||
}
|
||||
|
||||
if ( !empty( $missing ) ) {
|
||||
return [
|
||||
'is_valid' => false,
|
||||
'severity' => 'danger',
|
||||
'message' => 'Brakuje konfiguracji Apilo: ' . implode( ', ', $missing ) . '.',
|
||||
];
|
||||
}
|
||||
|
||||
$accessToken = trim( (string)($settings['access-token'] ?? '') );
|
||||
$authorizationCode = trim( (string)($settings['authorization-code'] ?? '') );
|
||||
|
||||
if ( $accessToken === '' ) {
|
||||
if ( $authorizationCode === '' ) {
|
||||
return [
|
||||
'is_valid' => false,
|
||||
'severity' => 'warning',
|
||||
'message' => 'Brak authorization-code i access-token. Wpisz kod autoryzacji i uruchom autoryzacje.',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'is_valid' => false,
|
||||
'severity' => 'warning',
|
||||
'message' => 'Brak access-token. Uruchom autoryzacje Apilo.',
|
||||
];
|
||||
}
|
||||
|
||||
$token = $this->apiloGetAccessToken();
|
||||
if ( !$token ) {
|
||||
return [
|
||||
'is_valid' => false,
|
||||
'severity' => 'danger',
|
||||
'message' => 'Token Apilo jest niewazny lub wygasl i nie udal sie refresh. Wykonaj ponowna autoryzacje.',
|
||||
];
|
||||
}
|
||||
|
||||
$expiresAt = trim( (string)($settings['access-token-expire-at'] ?? '') );
|
||||
$suffix = $expiresAt !== '' ? ( ' Token wazny do: ' . $expiresAt . '.' ) : '';
|
||||
|
||||
return [
|
||||
'is_valid' => true,
|
||||
'severity' => 'success',
|
||||
'message' => 'Integracja Apilo jest aktywna.' . $suffix,
|
||||
];
|
||||
}
|
||||
|
||||
// ── Apilo API fetch lists ───────────────────────────────────
|
||||
|
||||
private const APILO_ENDPOINTS = [
|
||||
@@ -179,13 +327,45 @@ class IntegrationsRepository
|
||||
* @param string $type platform|status|carrier|payment
|
||||
*/
|
||||
public function apiloFetchList( string $type ): bool
|
||||
{
|
||||
$result = $this->apiloFetchListResult( $type );
|
||||
return !empty( $result['success'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch list from Apilo API and return detailed status for UI.
|
||||
*
|
||||
* @param string $type platform|status|carrier|payment
|
||||
* @return array{success:bool,count:int,message:string}
|
||||
*/
|
||||
public function apiloFetchListResult( string $type ): array
|
||||
{
|
||||
if ( !isset( self::APILO_ENDPOINTS[$type] ) )
|
||||
throw new \InvalidArgumentException( "Unknown apilo list type: $type" );
|
||||
|
||||
$settings = $this->getSettings( 'apilo' );
|
||||
$missingFields = [];
|
||||
foreach ( [ 'client-id', 'client-secret' ] as $requiredField ) {
|
||||
if ( trim( (string)($settings[$requiredField] ?? '') ) === '' )
|
||||
$missingFields[] = $requiredField;
|
||||
}
|
||||
|
||||
if ( !empty( $missingFields ) ) {
|
||||
return [
|
||||
'success' => false,
|
||||
'count' => 0,
|
||||
'message' => 'Brakuje konfiguracji Apilo: ' . implode( ', ', $missingFields ) . '. Uzupelnij pola i zapisz ustawienia.',
|
||||
];
|
||||
}
|
||||
|
||||
$accessToken = $this->apiloGetAccessToken();
|
||||
if ( !$accessToken )
|
||||
return false;
|
||||
if ( !$accessToken ) {
|
||||
return [
|
||||
'success' => false,
|
||||
'count' => 0,
|
||||
'message' => 'Brak aktywnego tokenu Apilo. Wykonaj autoryzacje Apilo i sprobuj ponownie.',
|
||||
];
|
||||
}
|
||||
|
||||
$ch = curl_init( self::APILO_ENDPOINTS[$type] );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
@@ -196,19 +376,140 @@ class IntegrationsRepository
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
$error = curl_error( $ch );
|
||||
curl_close( $ch );
|
||||
return false;
|
||||
return [
|
||||
'success' => false,
|
||||
'count' => 0,
|
||||
'message' => 'Blad polaczenia z Apilo: ' . $error . '. Sprawdz polaczenie serwera i sprobuj ponownie.',
|
||||
];
|
||||
}
|
||||
$httpCode = (int) curl_getinfo( $ch, CURLINFO_HTTP_CODE );
|
||||
curl_close( $ch );
|
||||
|
||||
$data = json_decode( $response, true );
|
||||
if ( !$data )
|
||||
if ( !is_array( $data ) ) {
|
||||
$responsePreview = substr( trim( (string)$response ), 0, 180 );
|
||||
if ( $responsePreview === '' )
|
||||
$responsePreview = '[pusta odpowiedz]';
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'count' => 0,
|
||||
'message' => 'Apilo zwrocilo niepoprawny format odpowiedzi (HTTP ' . $httpCode . '). Odpowiedz: ' . $responsePreview,
|
||||
];
|
||||
}
|
||||
|
||||
if ( $httpCode >= 400 ) {
|
||||
return [
|
||||
'success' => false,
|
||||
'count' => 0,
|
||||
'message' => 'Apilo zwrocilo blad HTTP ' . $httpCode . ': ' . $this->extractApiloErrorMessage( $data ),
|
||||
];
|
||||
}
|
||||
|
||||
$normalizedList = $this->normalizeApiloMapList( $data );
|
||||
if ( $normalizedList === null ) {
|
||||
return [
|
||||
'success' => false,
|
||||
'count' => 0,
|
||||
'message' => 'Apilo zwrocilo dane w nieoczekiwanym formacie. Odswiez token i sproboj ponownie.',
|
||||
];
|
||||
}
|
||||
|
||||
$this->saveSetting( 'apilo', self::APILO_SETTINGS_KEYS[$type], $normalizedList );
|
||||
return [
|
||||
'success' => true,
|
||||
'count' => count( $normalizedList ),
|
||||
'message' => 'OK',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizuje odpowiedz API mapowania do listy rekordow ['id' => ..., 'name' => ...].
|
||||
* Zwraca null dla payloadu bledow lub nieoczekiwanego formatu.
|
||||
*
|
||||
* @return array<int, array{id:mixed,name:mixed}>|null
|
||||
*/
|
||||
private function normalizeApiloMapList( array $data ): ?array
|
||||
{
|
||||
if ( isset( $data['message'] ) && isset( $data['code'] ) )
|
||||
return null;
|
||||
|
||||
if ( $this->isMapListShape( $data ) )
|
||||
return $data;
|
||||
|
||||
if ( isset( $data['items'] ) && is_array( $data['items'] ) && $this->isMapListShape( $data['items'] ) )
|
||||
return $data['items'];
|
||||
|
||||
if ( isset( $data['data'] ) && is_array( $data['data'] ) && $this->isMapListShape( $data['data'] ) )
|
||||
return $data['data'];
|
||||
|
||||
// Dopuszczamy rowniez format asocjacyjny: [id => name, ...], ale tylko dla kluczy liczbowych.
|
||||
if ( !empty( $data ) ) {
|
||||
$normalized = [];
|
||||
foreach ( $data as $key => $value ) {
|
||||
if ( !( is_int( $key ) || ( is_string( $key ) && preg_match('/^-?\d+$/', $key) === 1 ) ) )
|
||||
return null;
|
||||
|
||||
if ( !is_scalar( $value ) )
|
||||
return null;
|
||||
|
||||
$normalized[] = [
|
||||
'id' => $key,
|
||||
'name' => (string) $value,
|
||||
];
|
||||
}
|
||||
|
||||
return !empty( $normalized ) ? $normalized : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function isMapListShape( array $list ): bool
|
||||
{
|
||||
if ( empty( $list ) )
|
||||
return false;
|
||||
|
||||
$this->saveSetting( 'apilo', self::APILO_SETTINGS_KEYS[$type], $data );
|
||||
foreach ( $list as $row ) {
|
||||
if ( !is_array( $row ) || !array_key_exists( 'id', $row ) || !array_key_exists( 'name', $row ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function extractApiloErrorMessage( array $data ): string
|
||||
{
|
||||
foreach ( [ 'message', 'error', 'detail', 'title' ] as $key ) {
|
||||
if ( isset( $data[$key] ) && is_scalar( $data[$key] ) ) {
|
||||
$message = trim( (string)$data[$key] );
|
||||
if ( $message !== '' )
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $data['errors'] ) ) {
|
||||
if ( is_array( $data['errors'] ) ) {
|
||||
$flat = [];
|
||||
foreach ( $data['errors'] as $errorItem ) {
|
||||
if ( is_scalar( $errorItem ) )
|
||||
$flat[] = (string)$errorItem;
|
||||
elseif ( is_array( $errorItem ) )
|
||||
$flat[] = json_encode( $errorItem, JSON_UNESCAPED_UNICODE );
|
||||
}
|
||||
|
||||
if ( !empty( $flat ) )
|
||||
return implode( '; ', $flat );
|
||||
} elseif ( is_scalar( $data['errors'] ) ) {
|
||||
return (string)$data['errors'];
|
||||
}
|
||||
}
|
||||
|
||||
return 'Nieznany blad odpowiedzi API.';
|
||||
}
|
||||
|
||||
// ── Apilo product operations ────────────────────────────────
|
||||
|
||||
public function getProductSku( int $productId ): ?string
|
||||
|
||||
309
autoload/Domain/PaymentMethod/PaymentMethodRepository.php
Normal file
309
autoload/Domain/PaymentMethod/PaymentMethodRepository.php
Normal file
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
namespace Domain\PaymentMethod;
|
||||
|
||||
class PaymentMethodRepository
|
||||
{
|
||||
private const MAX_PER_PAGE = 100;
|
||||
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{items: array<int, array<string, mixed>>, total: int}
|
||||
*/
|
||||
public function listForAdmin(
|
||||
array $filters,
|
||||
string $sortColumn = 'name',
|
||||
string $sortDir = 'ASC',
|
||||
int $page = 1,
|
||||
int $perPage = 15
|
||||
): array {
|
||||
$allowedSortColumns = [
|
||||
'id' => 'spm.id',
|
||||
'name' => 'spm.name',
|
||||
'status' => 'spm.status',
|
||||
'apilo_payment_type_id' => 'spm.apilo_payment_type_id',
|
||||
];
|
||||
|
||||
$sortSql = $allowedSortColumns[$sortColumn] ?? 'spm.name';
|
||||
$sortDir = strtoupper(trim($sortDir)) === 'DESC' ? 'DESC' : 'ASC';
|
||||
$page = max(1, $page);
|
||||
$perPage = min(self::MAX_PER_PAGE, max(1, $perPage));
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
$where = ['1 = 1'];
|
||||
$params = [];
|
||||
|
||||
$name = trim((string)($filters['name'] ?? ''));
|
||||
if ($name !== '') {
|
||||
if (strlen($name) > 255) {
|
||||
$name = substr($name, 0, 255);
|
||||
}
|
||||
$where[] = 'spm.name LIKE :name';
|
||||
$params[':name'] = '%' . $name . '%';
|
||||
}
|
||||
|
||||
$status = trim((string)($filters['status'] ?? ''));
|
||||
if ($status === '0' || $status === '1') {
|
||||
$where[] = 'spm.status = :status';
|
||||
$params[':status'] = (int)$status;
|
||||
}
|
||||
|
||||
$whereSql = implode(' AND ', $where);
|
||||
|
||||
$sqlCount = "
|
||||
SELECT COUNT(0)
|
||||
FROM pp_shop_payment_methods AS spm
|
||||
WHERE {$whereSql}
|
||||
";
|
||||
|
||||
$stmtCount = $this->db->query($sqlCount, $params);
|
||||
$countRows = $stmtCount ? $stmtCount->fetchAll() : [];
|
||||
$total = isset($countRows[0][0]) ? (int)$countRows[0][0] : 0;
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
spm.id,
|
||||
spm.name,
|
||||
spm.description,
|
||||
spm.status,
|
||||
spm.apilo_payment_type_id
|
||||
FROM pp_shop_payment_methods AS spm
|
||||
WHERE {$whereSql}
|
||||
ORDER BY {$sortSql} {$sortDir}, spm.id ASC
|
||||
LIMIT {$perPage} OFFSET {$offset}
|
||||
";
|
||||
|
||||
$stmt = $this->db->query($sql, $params);
|
||||
$items = $stmt ? $stmt->fetchAll() : [];
|
||||
|
||||
if (!is_array($items)) {
|
||||
$items = [];
|
||||
}
|
||||
|
||||
foreach ($items as &$item) {
|
||||
$item = $this->normalizePaymentMethod($item);
|
||||
}
|
||||
unset($item);
|
||||
|
||||
return [
|
||||
'items' => $items,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
public function find(int $paymentMethodId): ?array
|
||||
{
|
||||
if ($paymentMethodId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$paymentMethod = $this->db->get('pp_shop_payment_methods', '*', ['id' => $paymentMethodId]);
|
||||
if (!is_array($paymentMethod)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->normalizePaymentMethod($paymentMethod);
|
||||
}
|
||||
|
||||
public function save(int $paymentMethodId, array $data): ?int
|
||||
{
|
||||
if ($paymentMethodId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = [
|
||||
'description' => trim((string)($data['description'] ?? '')),
|
||||
'status' => $this->toSwitchValue($data['status'] ?? 0),
|
||||
'apilo_payment_type_id' => $this->normalizeApiloPaymentTypeId($data['apilo_payment_type_id'] ?? null),
|
||||
];
|
||||
|
||||
$this->db->update('pp_shop_payment_methods', $row, ['id' => $paymentMethodId]);
|
||||
|
||||
return $paymentMethodId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function allActive(): array
|
||||
{
|
||||
$rows = $this->db->select('pp_shop_payment_methods', '*', [
|
||||
'status' => 1,
|
||||
'ORDER' => ['id' => 'ASC'],
|
||||
]);
|
||||
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
if (is_array($row)) {
|
||||
$result[] = $this->normalizePaymentMethod($row);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function allForAdmin(): array
|
||||
{
|
||||
$rows = $this->db->select('pp_shop_payment_methods', '*', [
|
||||
'ORDER' => ['name' => 'ASC'],
|
||||
]);
|
||||
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
if (is_array($row)) {
|
||||
$result[] = $this->normalizePaymentMethod($row);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function findActiveById(int $paymentMethodId): ?array
|
||||
{
|
||||
if ($paymentMethodId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$paymentMethod = $this->db->get('pp_shop_payment_methods', '*', [
|
||||
'AND' => [
|
||||
'id' => $paymentMethodId,
|
||||
'status' => 1,
|
||||
],
|
||||
]);
|
||||
|
||||
if (!is_array($paymentMethod)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->normalizePaymentMethod($paymentMethod);
|
||||
}
|
||||
|
||||
public function isActive(int $paymentMethodId): int
|
||||
{
|
||||
if ($paymentMethodId <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$status = $this->db->get('pp_shop_payment_methods', 'status', ['id' => $paymentMethodId]);
|
||||
return $this->toSwitchValue($status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|string|null
|
||||
*/
|
||||
public function getApiloPaymentTypeId(int $paymentMethodId)
|
||||
{
|
||||
if ($paymentMethodId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = $this->db->get('pp_shop_payment_methods', 'apilo_payment_type_id', ['id' => $paymentMethodId]);
|
||||
return $this->normalizeApiloPaymentTypeId($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function forTransport(int $transportMethodId): array
|
||||
{
|
||||
if ($transportMethodId <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
spm.id,
|
||||
spm.name,
|
||||
spm.description,
|
||||
spm.status,
|
||||
spm.apilo_payment_type_id
|
||||
FROM pp_shop_payment_methods AS spm
|
||||
INNER JOIN pp_shop_transport_payment_methods AS stpm
|
||||
ON stpm.id_payment_method = spm.id
|
||||
WHERE spm.status = 1
|
||||
AND stpm.id_transport = :transport_id
|
||||
";
|
||||
|
||||
$stmt = $this->db->query($sql, [':transport_id' => $transportMethodId]);
|
||||
$rows = $stmt ? $stmt->fetchAll() : [];
|
||||
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
if (is_array($row)) {
|
||||
$result[] = $this->normalizePaymentMethod($row);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function normalizePaymentMethod(array $row): array
|
||||
{
|
||||
$row['id'] = (int)($row['id'] ?? 0);
|
||||
$row['name'] = trim((string)($row['name'] ?? ''));
|
||||
$row['description'] = (string)($row['description'] ?? '');
|
||||
$row['status'] = $this->toSwitchValue($row['status'] ?? 0);
|
||||
$row['apilo_payment_type_id'] = $this->normalizeApiloPaymentTypeId($row['apilo_payment_type_id'] ?? null);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|string|null
|
||||
*/
|
||||
private function normalizeApiloPaymentTypeId($value)
|
||||
{
|
||||
if ($value === null || $value === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$text = trim((string)$value);
|
||||
if ($text === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/^-?\d+$/', $text) === 1) {
|
||||
return (int)$text;
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
private function toSwitchValue($value): int
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
return $value ? 1 : 0;
|
||||
}
|
||||
|
||||
if (is_numeric($value)) {
|
||||
return ((int)$value) === 1 ? 1 : 0;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$normalized = strtolower(trim($value));
|
||||
return in_array($normalized, ['1', 'on', 'true', 'yes'], true) ? 1 : 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -12,23 +12,23 @@ class IntegrationsController
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
// ── Apilo settings ──────────────────────────────────────────
|
||||
|
||||
public function apilo_settings(): string
|
||||
{
|
||||
return \Tpl::view( 'integrations/apilo-settings', [
|
||||
'settings' => $this->repository->getSettings( 'apilo' ),
|
||||
'apilo_status' => $this->repository->apiloIntegrationStatus(),
|
||||
] );
|
||||
}
|
||||
|
||||
public function apilo_settings_save(): void
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawien wystapil blad. Prosze sprobowac ponownie.' ];
|
||||
$fieldId = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( $this->repository->saveSetting( 'apilo', $fieldId, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
if ( $this->repository->saveSetting( 'apilo', $fieldId, $value ) ) {
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostaly zapisane.', 'value' => $value ];
|
||||
}
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
@@ -36,70 +36,55 @@ class IntegrationsController
|
||||
|
||||
public function apilo_authorization(): void
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas autoryzacji wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$settings = $this->repository->getSettings( 'apilo' );
|
||||
|
||||
if ( $this->repository->apiloAuthorize( $settings['client-id'], $settings['client-secret'], $settings['authorization-code'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Autoryzacja przebiegła pomyślnie.' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
if ( $this->repository->apiloAuthorize(
|
||||
(string)($settings['client-id'] ?? ''),
|
||||
(string)($settings['client-secret'] ?? ''),
|
||||
(string)($settings['authorization-code'] ?? '')
|
||||
) ) {
|
||||
echo json_encode( [ 'status' => 'ok', 'msg' => 'Autoryzacja przebiegla pomyslnie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── Apilo data fetch ────────────────────────────────────────
|
||||
$status = $this->repository->apiloIntegrationStatus();
|
||||
$message = trim( (string)($status['message'] ?? '') );
|
||||
if ( $message === '' ) {
|
||||
$message = 'Podczas autoryzacji wystapil blad. Prosze sprawdzic dane i sprobowac ponownie.';
|
||||
} else {
|
||||
$message = 'Autoryzacja nieudana. ' . $message;
|
||||
}
|
||||
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => $message ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function get_platform_list(): void
|
||||
{
|
||||
if ( $this->repository->apiloFetchList( 'platform' ) )
|
||||
\S::alert( 'Lista platform została pobrana.' );
|
||||
else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
$this->fetchApiloListWithFeedback( 'platform', 'Liste platform' );
|
||||
}
|
||||
|
||||
public function get_status_types_list(): void
|
||||
{
|
||||
if ( $this->repository->apiloFetchList( 'status' ) )
|
||||
\S::alert( 'Lista statusów została pobrana.' );
|
||||
else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
$this->fetchApiloListWithFeedback( 'status', 'Liste statusow' );
|
||||
}
|
||||
|
||||
public function get_carrier_account_list(): void
|
||||
{
|
||||
if ( $this->repository->apiloFetchList( 'carrier' ) )
|
||||
\S::alert( 'Lista kont przewoźników została pobrana.' );
|
||||
else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
$this->fetchApiloListWithFeedback( 'carrier', 'Liste kont przewoznikow' );
|
||||
}
|
||||
|
||||
public function get_payment_types_list(): void
|
||||
{
|
||||
if ( $this->repository->apiloFetchList( 'payment' ) )
|
||||
\S::alert( 'Lista metod płatności została pobrana.' );
|
||||
else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
$this->fetchApiloListWithFeedback( 'payment', 'Liste metod platnosci' );
|
||||
}
|
||||
|
||||
// ── Apilo product operations ────────────────────────────────
|
||||
|
||||
public function apilo_create_product(): void
|
||||
{
|
||||
$productId = (int) \S::get( 'product_id' );
|
||||
$result = $this->repository->apiloCreateProduct( $productId );
|
||||
|
||||
\S::alert( $result['message'] );
|
||||
\S::alert( (string)($result['message'] ?? 'Wystapil blad podczas tworzenia produktu w Apilo.') );
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
@@ -120,23 +105,25 @@ class IntegrationsController
|
||||
|
||||
public function apilo_product_select_save(): void
|
||||
{
|
||||
if ( $this->repository->linkProduct( (int) \S::get( 'product_id' ), \S::get( 'apilo_product_id' ), \S::get( 'apilo_product_name' ) ) )
|
||||
if ( $this->repository->linkProduct( (int) \S::get( 'product_id' ), \S::get( 'apilo_product_id' ), \S::get( 'apilo_product_name' ) ) ) {
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
} else {
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystapil blad. Prosze sprobowac ponownie.' ] );
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
public function apilo_product_select_delete(): void
|
||||
{
|
||||
if ( $this->repository->unlinkProduct( (int) \S::get( 'product_id' ) ) )
|
||||
if ( $this->repository->unlinkProduct( (int) \S::get( 'product_id' ) ) ) {
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
} else {
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystapil blad. Prosze sprobowac ponownie.' ] );
|
||||
}
|
||||
|
||||
// ── ShopPRO settings ────────────────────────────────────────
|
||||
exit;
|
||||
}
|
||||
|
||||
public function shoppro_settings(): string
|
||||
{
|
||||
@@ -147,26 +134,45 @@ class IntegrationsController
|
||||
|
||||
public function shoppro_settings_save(): void
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawien wystapil blad. Prosze sprobowac ponownie.' ];
|
||||
$fieldId = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( $this->repository->saveSetting( 'shoppro', $fieldId, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
if ( $this->repository->saveSetting( 'shoppro', $fieldId, $value ) ) {
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostaly zapisane.', 'value' => $value ];
|
||||
}
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── ShopPRO product import ──────────────────────────────────
|
||||
|
||||
public function shoppro_product_import(): void
|
||||
{
|
||||
$productId = (int) \S::get( 'product_id' );
|
||||
$result = $this->repository->shopproImportProduct( $productId );
|
||||
|
||||
\S::alert( $result['message'] );
|
||||
\S::alert( (string)($result['message'] ?? 'Wystapil blad podczas importu produktu.') );
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
private function fetchApiloListWithFeedback( string $type, string $label ): void
|
||||
{
|
||||
$result = $this->repository->apiloFetchListResult( $type );
|
||||
|
||||
if ( !empty( $result['success'] ) ) {
|
||||
$count = (int)($result['count'] ?? 0);
|
||||
\S::alert( $label . ' zostala pobrana. Liczba rekordow: ' . $count . '.' );
|
||||
} else {
|
||||
$details = trim( (string)($result['message'] ?? 'Nieznany blad.') );
|
||||
\S::alert(
|
||||
'Nie udalo sie pobrac ' . strtolower( $label ) . '. '
|
||||
. $details
|
||||
. ' Co zrobic: sprawdz konfiguracje Apilo, wykonaj autoryzacje i ponow pobranie listy.'
|
||||
);
|
||||
}
|
||||
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
290
autoload/admin/Controllers/ShopPaymentMethodController.php
Normal file
290
autoload/admin/Controllers/ShopPaymentMethodController.php
Normal file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
namespace admin\Controllers;
|
||||
|
||||
use Domain\PaymentMethod\PaymentMethodRepository;
|
||||
use admin\ViewModels\Common\PaginatedTableViewModel;
|
||||
use admin\ViewModels\Forms\FormAction;
|
||||
use admin\ViewModels\Forms\FormEditViewModel;
|
||||
use admin\ViewModels\Forms\FormField;
|
||||
use admin\ViewModels\Forms\FormTab;
|
||||
|
||||
class ShopPaymentMethodController
|
||||
{
|
||||
private PaymentMethodRepository $repository;
|
||||
|
||||
public function __construct(PaymentMethodRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function list(): string
|
||||
{
|
||||
$sortableColumns = ['id', 'name', 'status', 'apilo_payment_type_id'];
|
||||
$filterDefinitions = [
|
||||
[
|
||||
'key' => 'name',
|
||||
'label' => 'Nazwa',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'key' => 'status',
|
||||
'label' => 'Aktywny',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'' => '- aktywny -',
|
||||
'1' => 'tak',
|
||||
'0' => 'nie',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$listRequest = \admin\Support\TableListRequestFactory::fromRequest(
|
||||
$filterDefinitions,
|
||||
$sortableColumns,
|
||||
'id'
|
||||
);
|
||||
|
||||
$sortDir = $listRequest['sortDir'];
|
||||
if (trim((string)\S::get('sort')) === '') {
|
||||
$sortDir = 'ASC';
|
||||
}
|
||||
|
||||
$result = $this->repository->listForAdmin(
|
||||
$listRequest['filters'],
|
||||
$listRequest['sortColumn'],
|
||||
$sortDir,
|
||||
$listRequest['page'],
|
||||
$listRequest['perPage']
|
||||
);
|
||||
|
||||
$apiloPaymentTypes = $this->getApiloPaymentTypes();
|
||||
|
||||
$rows = [];
|
||||
$lp = ($listRequest['page'] - 1) * $listRequest['perPage'] + 1;
|
||||
foreach ($result['items'] as $item) {
|
||||
$id = (int)($item['id'] ?? 0);
|
||||
$name = trim((string)($item['name'] ?? ''));
|
||||
$status = (int)($item['status'] ?? 0);
|
||||
$apiloPaymentTypeId = $item['apilo_payment_type_id'] ?? null;
|
||||
|
||||
$apiloLabel = '-';
|
||||
if ($apiloPaymentTypeId !== null) {
|
||||
$apiloKey = (string)$apiloPaymentTypeId;
|
||||
if (isset($apiloPaymentTypes[$apiloKey])) {
|
||||
$apiloLabel = $apiloPaymentTypes[$apiloKey];
|
||||
}
|
||||
}
|
||||
|
||||
$rows[] = [
|
||||
'lp' => $lp++ . '.',
|
||||
'name' => '<a href="/admin/shop_payment_method/edit/id=' . $id . '">' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'status' => $status === 1 ? 'tak' : '<span style="color: #FF0000;">nie</span>',
|
||||
'apilo_payment_type' => htmlspecialchars((string)$apiloLabel, ENT_QUOTES, 'UTF-8'),
|
||||
'_actions' => [
|
||||
[
|
||||
'label' => 'Edytuj',
|
||||
'url' => '/admin/shop_payment_method/edit/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-primary',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$total = (int)$result['total'];
|
||||
$totalPages = max(1, (int)ceil($total / $listRequest['perPage']));
|
||||
|
||||
$viewModel = new PaginatedTableViewModel(
|
||||
[
|
||||
['key' => 'lp', 'label' => 'Lp.', 'class' => 'text-center', 'sortable' => false],
|
||||
['key' => 'name', 'sort_key' => 'name', 'label' => 'Nazwa', 'sortable' => true, 'raw' => true],
|
||||
['key' => 'status', 'sort_key' => 'status', 'label' => 'Aktywny', 'class' => 'text-center', 'sortable' => true, 'raw' => true],
|
||||
['key' => 'apilo_payment_type', 'sort_key' => 'apilo_payment_type_id', 'label' => 'Typ platnosci Apilo', 'class' => 'text-center', 'sortable' => true],
|
||||
],
|
||||
$rows,
|
||||
$listRequest['viewFilters'],
|
||||
[
|
||||
'column' => $listRequest['sortColumn'],
|
||||
'dir' => $sortDir,
|
||||
],
|
||||
[
|
||||
'page' => $listRequest['page'],
|
||||
'per_page' => $listRequest['perPage'],
|
||||
'total' => $total,
|
||||
'total_pages' => $totalPages,
|
||||
],
|
||||
array_merge($listRequest['queryFilters'], [
|
||||
'sort' => $listRequest['sortColumn'],
|
||||
'dir' => $sortDir,
|
||||
'per_page' => $listRequest['perPage'],
|
||||
]),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/shop_payment_method/list/',
|
||||
'Brak danych w tabeli.'
|
||||
);
|
||||
|
||||
return \Tpl::view('shop-payment-method/payment-methods-list', [
|
||||
'viewModel' => $viewModel,
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(): string
|
||||
{
|
||||
$paymentMethod = $this->repository->find((int)\S::get('id'));
|
||||
if ($paymentMethod === null) {
|
||||
\S::alert('Metoda platnosci nie zostala znaleziona.');
|
||||
header('Location: /admin/shop_payment_method/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
return \Tpl::view('shop-payment-method/payment-method-edit', [
|
||||
'form' => $this->buildFormViewModel($paymentMethod, $this->getApiloPaymentTypes()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$payload = $_POST;
|
||||
$paymentMethodId = isset($payload['id']) && $payload['id'] !== ''
|
||||
? (int)$payload['id']
|
||||
: (int)\S::get('id');
|
||||
|
||||
$id = $this->repository->save($paymentMethodId, $payload);
|
||||
if ($id !== null) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'id' => (int)$id,
|
||||
'message' => 'Metoda platnosci zostala zapisana.',
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'errors' => ['general' => 'Podczas zapisywania metody platnosci wystapil blad.'],
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
private function buildFormViewModel(array $paymentMethod, array $apiloPaymentTypes): FormEditViewModel
|
||||
{
|
||||
$id = (int)($paymentMethod['id'] ?? 0);
|
||||
$name = (string)($paymentMethod['name'] ?? '');
|
||||
|
||||
$apiloOptions = ['' => '--- wybierz typ platnosci apilo.com ---'];
|
||||
foreach ($apiloPaymentTypes as $apiloId => $apiloName) {
|
||||
$apiloOptions[(string)$apiloId] = $apiloName;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => $id,
|
||||
'description' => (string)($paymentMethod['description'] ?? ''),
|
||||
'status' => (int)($paymentMethod['status'] ?? 0),
|
||||
'apilo_payment_type_id' => $paymentMethod['apilo_payment_type_id'] ?? '',
|
||||
];
|
||||
|
||||
$fields = [
|
||||
FormField::hidden('id', $id),
|
||||
FormField::custom(
|
||||
'name_preview',
|
||||
\Html::input([
|
||||
'label' => 'Nazwa',
|
||||
'name' => 'name_preview',
|
||||
'id' => 'name_preview',
|
||||
'value' => $name,
|
||||
'type' => 'text',
|
||||
'readonly' => true,
|
||||
]),
|
||||
['tab' => 'settings']
|
||||
),
|
||||
FormField::textarea('description', [
|
||||
'label' => 'Opis',
|
||||
'tab' => 'settings',
|
||||
'rows' => 5,
|
||||
]),
|
||||
FormField::select('apilo_payment_type_id', [
|
||||
'label' => 'Typ platnosci Apilo',
|
||||
'tab' => 'settings',
|
||||
'options' => $apiloOptions,
|
||||
]),
|
||||
FormField::switch('status', [
|
||||
'label' => 'Aktywny',
|
||||
'tab' => 'settings',
|
||||
]),
|
||||
];
|
||||
|
||||
$tabs = [
|
||||
new FormTab('settings', 'Ustawienia', 'fa-wrench'),
|
||||
];
|
||||
|
||||
$actionUrl = '/admin/shop_payment_method/save/id=' . $id;
|
||||
$actions = [
|
||||
FormAction::save($actionUrl, '/admin/shop_payment_method/list/'),
|
||||
FormAction::cancel('/admin/shop_payment_method/list/'),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
'shop-payment-method-edit',
|
||||
'Edycja metody platnosci: ' . $name,
|
||||
$data,
|
||||
$fields,
|
||||
$tabs,
|
||||
$actions,
|
||||
'POST',
|
||||
$actionUrl,
|
||||
'/admin/shop_payment_method/list/',
|
||||
true,
|
||||
['id' => $id]
|
||||
);
|
||||
}
|
||||
|
||||
private function getApiloPaymentTypes(): array
|
||||
{
|
||||
$rawSetting = \admin\factory\Integrations::apilo_settings('payment-types-list');
|
||||
$raw = null;
|
||||
|
||||
if (is_array($rawSetting)) {
|
||||
$raw = $rawSetting;
|
||||
} elseif (is_string($rawSetting)) {
|
||||
$decoded = @unserialize($rawSetting);
|
||||
if (is_array($decoded)) {
|
||||
$raw = $decoded;
|
||||
} else {
|
||||
$decodedJson = json_decode($rawSetting, true);
|
||||
if (is_array($decodedJson)) {
|
||||
$raw = $decodedJson;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($raw)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (isset($raw['message']) && isset($raw['code'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (isset($raw['items']) && is_array($raw['items'])) {
|
||||
$raw = $raw['items'];
|
||||
} elseif (isset($raw['data']) && is_array($raw['data'])) {
|
||||
$raw = $raw['data'];
|
||||
}
|
||||
|
||||
$list = [];
|
||||
foreach ($raw as $key => $paymentType) {
|
||||
if (is_array($paymentType)) {
|
||||
if (isset($paymentType['id'], $paymentType['name'])) {
|
||||
$list[(string)$paymentType['id']] = (string)$paymentType['name'];
|
||||
continue;
|
||||
}
|
||||
} elseif (is_scalar($paymentType)) {
|
||||
if (is_int($key) || (is_string($key) && preg_match('/^-?\d+$/', $key) === 1)) {
|
||||
$list[(string)$key] = (string)$paymentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
@@ -316,6 +316,13 @@ class Site
|
||||
new \Domain\Coupon\CouponRepository( $mdb )
|
||||
);
|
||||
},
|
||||
'ShopPaymentMethod' => function() {
|
||||
global $mdb;
|
||||
|
||||
return new \admin\Controllers\ShopPaymentMethodController(
|
||||
new \Domain\PaymentMethod\PaymentMethodRepository( $mdb )
|
||||
);
|
||||
},
|
||||
'Pages' => function() {
|
||||
global $mdb;
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-payment-method/view-list', [
|
||||
'apilo_payment_types_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'payment-types-list' ) ),
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,12 @@ class ShopTransport
|
||||
|
||||
public static function transport_edit()
|
||||
{
|
||||
global $mdb;
|
||||
$paymentMethodRepository = new \Domain\PaymentMethod\PaymentMethodRepository( $mdb );
|
||||
|
||||
return \Tpl::view( 'shop-transport/transport-edit', [
|
||||
'transport_details' => \admin\factory\ShopTransport::transport_details( \S::get( 'id' ) ),
|
||||
'payments_list' => \admin\factory\ShopPaymentMethod::payments_list(),
|
||||
'payments_list' => $paymentMethodRepository -> allForAdmin(),
|
||||
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
|
||||
] );
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace admin\factory;
|
||||
/**
|
||||
* Fasada kompatybilnosci wstecznej.
|
||||
* Deleguje do Domain\Integrations\IntegrationsRepository.
|
||||
* Uzywane przez: cron.php, shop\Order, admin\Controllers\ShopStatusesController, admin\controls\ShopTransport, admin\controls\ShopPaymentMethod, admin\controls\ShopProduct.
|
||||
* Uzywane przez: cron.php, shop\Order, admin\Controllers\ShopStatusesController, admin\controls\ShopTransport, admin\controls\ShopProduct, admin\Controllers\ShopPaymentMethodController.
|
||||
*/
|
||||
class Integrations {
|
||||
|
||||
@@ -32,6 +32,11 @@ class Integrations {
|
||||
return self::repo()->apiloGetAccessToken();
|
||||
}
|
||||
|
||||
static public function apilo_keepalive( int $refresh_lead_seconds = 300 )
|
||||
{
|
||||
return self::repo()->apiloKeepalive( $refresh_lead_seconds );
|
||||
}
|
||||
|
||||
static public function apilo_authorization( $client_id, $client_secret, $authorization_code )
|
||||
{
|
||||
return self::repo()->apiloAuthorize( $client_id, $client_secret, $authorization_code );
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
public static function payments_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_payment_methods', '*', [ 'ORDER' => [ 'name' => 'ASC'] ] );
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
|
||||
}
|
||||
@@ -3,72 +3,64 @@ namespace front\factory;
|
||||
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
private static function repo(): \Domain\PaymentMethod\PaymentMethodRepository
|
||||
{
|
||||
global $mdb;
|
||||
return new \Domain\PaymentMethod\PaymentMethodRepository( $mdb );
|
||||
}
|
||||
|
||||
// get_apilo_payment_method_id
|
||||
static public function get_apilo_payment_method_id( $payment_method_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_payment_methods', 'apilo_payment_type_id', [ 'id' => $payment_method_id ] );
|
||||
return self::repo()->getApiloPaymentTypeId( (int)$payment_method_id );
|
||||
}
|
||||
|
||||
public static function payment_methods_by_transport( $transport_method_id )
|
||||
{
|
||||
global $mdb, $settings;
|
||||
$transport_method_id = (int)$transport_method_id;
|
||||
$cacheKey = 'payment_methods_by_transport' . $transport_method_id;
|
||||
$payments = \Cache::fetch( $cacheKey );
|
||||
|
||||
if ( !$payments = \Cache::fetch( 'payment_methods_by_transport' . $transport_method_id ) )
|
||||
{
|
||||
$results = $mdb -> query( 'SELECT '
|
||||
. 'pspm.id, name, description '
|
||||
. 'FROM '
|
||||
. 'pp_shop_payment_methods AS pspm '
|
||||
. 'INNER JOIN pp_shop_transport_payment_methods AS pstpm ON pstpm.id_payment_method = pspm.id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 '
|
||||
. 'AND '
|
||||
. 'id_transport = ' . $transport_method_id ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
$payments[] = $row;
|
||||
|
||||
\Cache::store( 'payment_methods_by_transport' . $transport_method_id, $payments );
|
||||
if ( $payments !== false && is_array( $payments ) ) {
|
||||
return $payments;
|
||||
}
|
||||
|
||||
$payments = self::repo()->forTransport( $transport_method_id );
|
||||
\Cache::store( $cacheKey, $payments );
|
||||
|
||||
return $payments;
|
||||
}
|
||||
|
||||
public static function is_payment_active( $payment_method_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_payment_methods', 'status', [ 'id' => $payment_method_id ] );
|
||||
return self::repo()->isActive( (int)$payment_method_id );
|
||||
}
|
||||
|
||||
public static function payment_method( $payment_method_id )
|
||||
{
|
||||
global $mdb;
|
||||
$payment_method_id = (int)$payment_method_id;
|
||||
$cacheKey = 'payment_method' . $payment_method_id;
|
||||
$payment_method = \Cache::fetch( $cacheKey );
|
||||
|
||||
if ( !$payment_method = \Cache::fetch( 'payment_method' . $payment_method_id ) )
|
||||
{
|
||||
$payment_method = $mdb -> get( 'pp_shop_payment_methods', '*', [
|
||||
'AND' => [
|
||||
'id' => $payment_method_id,
|
||||
'status' => 1
|
||||
] ] );
|
||||
|
||||
\Cache::store( 'payment_method' . $payment_method_id, $payment_method );
|
||||
if ( $payment_method === false ) {
|
||||
$payment_method = self::repo()->findActiveById( $payment_method_id );
|
||||
\Cache::store( $cacheKey, $payment_method );
|
||||
}
|
||||
|
||||
return $payment_method;
|
||||
}
|
||||
|
||||
public static function payment_methods()
|
||||
{
|
||||
global $mdb;
|
||||
$cacheKey = 'payment_methods';
|
||||
$payment_methods = \Cache::fetch( $cacheKey );
|
||||
|
||||
if ( !$payment_methods = \Cache::fetch( 'payment_methods' ) )
|
||||
{
|
||||
$results = $mdb -> select( 'pp_shop_payment_methods', '*', [ 'status' => 1 ] );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
$payment_methods[] = $row;
|
||||
|
||||
\Cache::store( 'payment_methods', $payment_methods );
|
||||
if ( $payment_methods !== false && is_array( $payment_methods ) ) {
|
||||
return $payment_methods;
|
||||
}
|
||||
|
||||
$payment_methods = self::repo()->allActive();
|
||||
\Cache::store( $cacheKey, $payment_methods );
|
||||
|
||||
return $payment_methods;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
<?
|
||||
<?php
|
||||
namespace shop;
|
||||
|
||||
class PaymentMethod implements \ArrayAccess
|
||||
{
|
||||
// lista dostępnych form płatności
|
||||
static public function method_list()
|
||||
private static function repo(): \Domain\PaymentMethod\PaymentMethodRepository
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_payment_methods', '*', [ 'status' => 1 ] );
|
||||
return new \Domain\PaymentMethod\PaymentMethodRepository( $mdb );
|
||||
}
|
||||
|
||||
// lista dostepnych form platnosci
|
||||
static public function method_list()
|
||||
{
|
||||
return self::repo()->allActive();
|
||||
}
|
||||
|
||||
// get_apilo_payment_method_id
|
||||
static public function get_apilo_payment_method_id( $payment_method_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_payment_methods', 'apilo_payment_type_id', [ 'id' => $payment_method_id ] );
|
||||
return self::repo()->getApiloPaymentTypeId( (int)$payment_method_id );
|
||||
}
|
||||
|
||||
public function offsetExists( $offset )
|
||||
|
||||
6
cron.php
6
cron.php
@@ -55,6 +55,12 @@ $mdb = new medoo( [
|
||||
$settings = \front\factory\Settings::settings_details();
|
||||
$apilo_settings = \admin\factory\Integrations::apilo_settings();
|
||||
|
||||
// Keepalive tokenu Apilo: odswiezaj token przed wygasnieciem, zeby integracja byla stale aktywna.
|
||||
if ( (int)($apilo_settings['enabled'] ?? 0) === 1 ) {
|
||||
\admin\factory\Integrations::apilo_keepalive( 300 );
|
||||
$apilo_settings = \admin\factory\Integrations::apilo_settings();
|
||||
}
|
||||
|
||||
function parsePaczkomatAddress($input)
|
||||
{
|
||||
$pattern = '/^([\w-]+)\s+\|\s+([^,]+),\s+(\d{2}-\d{3})\s+(.+)$/';
|
||||
|
||||
@@ -4,6 +4,23 @@ Logi zmian z migracji na Domain-Driven Architecture. Najnowsze na gorze.
|
||||
|
||||
---
|
||||
|
||||
## ver. 0.268 (2026-02-14) - ShopPaymentMethod + Apilo token keepalive
|
||||
|
||||
- **ShopPaymentMethod** - migracja `/admin/shop_payment_method` na Domain + DI + nowe widoki
|
||||
- NOWE: `Domain\PaymentMethod\PaymentMethodRepository` (`listForAdmin`, `find`, `save`, `allActive`, `allForAdmin`, `findActiveById`, `isActive`, `getApiloPaymentTypeId`, `forTransport`)
|
||||
- NOWE: `admin\Controllers\ShopPaymentMethodController` (DI) z akcjami `list`, `edit`, `save`
|
||||
- NOWE: widoki `shop-payment-method/payment-methods-list.php` i `shop-payment-method/payment-method-edit.php`
|
||||
- UPDATE: routing i menu admin na kanoniczny URL `/admin/shop_payment_method/list/`
|
||||
- UPDATE: `admin\controls\ShopTransport`, `front\factory\ShopPaymentMethod`, `shop\PaymentMethod` przepiete na nowe repozytorium
|
||||
- CLEANUP: usuniete legacy `autoload/admin/controls/class.ShopPaymentMethod.php`, `autoload/admin/factory/class.ShopPaymentMethod.php`, `autoload/admin/view/class.ShopPaymentMethod.php`, `admin/templates/shop-payment-method/view-list.php`
|
||||
- **Integrations/Apilo** - stabilizacja tokenu i lepszy feedback
|
||||
- NOWE: automatyczne odswiezanie tokenu Apilo przed wygasnieciem (`apiloKeepalive`, refresh lead time)
|
||||
- UPDATE: cron uruchamia keepalive i odswieza konfiguracje Apilo
|
||||
- UPDATE: bardziej szczegolowe komunikaty bledow dla przyciskow integracji Apilo (co zrobic dalej)
|
||||
- Testy: **OK (280 tests, 828 assertions)**
|
||||
|
||||
---
|
||||
|
||||
## ver. 0.267 (2026-02-14) - ShopStatuses
|
||||
|
||||
- **ShopStatuses** - migracja `/admin/shop_statuses` na Domain + DI + nowe widoki
|
||||
|
||||
@@ -368,6 +368,22 @@ Promocje sklepu (modul `/admin/shop_promotion`).
|
||||
|
||||
**Aktualizacja 2026-02-13 (ver. 0.265):** dodano obsluge `date_from` (repozytorium, formularz admin, lista admin, filtr aktywnych promocji na froncie) oraz poprawke zapisu edycji promocji po `id`.
|
||||
|
||||
## pp_shop_payment_methods
|
||||
Metody platnosci sklepu (modul `/admin/shop_payment_method`).
|
||||
|
||||
| Kolumna | Opis |
|
||||
|---------|------|
|
||||
| id | PK |
|
||||
| name | Nazwa metody platnosci |
|
||||
| description | Opis metody platnosci (wyswietlany m.in. w checkout) |
|
||||
| status | Status: 1 = aktywna, 0 = nieaktywna |
|
||||
| apilo_payment_type_id | ID typu platnosci Apilo (NULL gdy brak mapowania) |
|
||||
| sellasist_payment_type_id | DEPRECATED (integracja Sellasist usunieta w ver. 0.263) |
|
||||
|
||||
**Uzywane w:** `Domain\PaymentMethod\PaymentMethodRepository`, `admin\Controllers\ShopPaymentMethodController`, `front\factory\ShopPaymentMethod`, `shop\PaymentMethod`, `admin\controls\ShopTransport`, `cron.php`
|
||||
|
||||
**Aktualizacja 2026-02-14 (ver. 0.268):** modul `/admin/shop_payment_method` korzysta z `Domain\PaymentMethod\PaymentMethodRepository` przez `admin\Controllers\ShopPaymentMethodController`. Usunieto legacy klasy `admin\controls\ShopPaymentMethod`, `admin\factory\ShopPaymentMethod`, `admin\view\ShopPaymentMethod` oraz widok `admin/templates/shop-payment-method/view-list.php`.
|
||||
|
||||
## pp_shop_apilo_settings
|
||||
Ustawienia integracji Apilo (key-value).
|
||||
|
||||
|
||||
@@ -124,6 +124,10 @@ shopPRO/
|
||||
- `pp_shop_apilo_settings` (key-value)
|
||||
- `pp_shop_shoppro_settings` (key-value)
|
||||
|
||||
### Tabele checkout
|
||||
- `pp_shop_payment_methods` - metody platnosci sklepu (mapowanie `apilo_payment_type_id`)
|
||||
- `pp_shop_transport_payment_methods` - powiazanie metod transportu i platnosci
|
||||
|
||||
Pelna dokumentacja tabel: `DATABASE_STRUCTURE.md`
|
||||
|
||||
## Konfiguracja
|
||||
@@ -222,6 +226,12 @@ autoload/
|
||||
└── front/factory/ # Legacy - stopniowo migrowane
|
||||
```
|
||||
|
||||
**Aktualizacja 2026-02-14 (ver. 0.268):**
|
||||
- Dodano modul domenowy `Domain/PaymentMethod/PaymentMethodRepository.php`.
|
||||
- Dodano kontroler DI `admin/Controllers/ShopPaymentMethodController.php`.
|
||||
- Modul `/admin/shop_payment_method/*` dziala na nowych widokach (`payment-methods-list`, `payment-method-edit`).
|
||||
- Usunieto legacy: `autoload/admin/controls/class.ShopPaymentMethod.php`, `autoload/admin/factory/class.ShopPaymentMethod.php`, `autoload/admin/view/class.ShopPaymentMethod.php`, `admin/templates/shop-payment-method/view-list.php`.
|
||||
|
||||
### Routing admin (admin\Site::route())
|
||||
1. Sprawdź mapę `$newControllers` → utwórz instancję z DI → wywołaj
|
||||
2. Jeśli nowy kontroler nie istnieje (`class_exists()` = false) → fallback na `admin\controls\`
|
||||
|
||||
@@ -148,6 +148,7 @@ grep -r "Product::getQuantity" .
|
||||
| 17 | ShopPromotion | 0.264-0.265 | listForAdmin, find, save, delete, categoriesTree |
|
||||
| 18 | ShopCoupon | 0.266 | listForAdmin, find, save, delete, categoriesTree |
|
||||
| 19 | ShopStatuses | 0.267 | listForAdmin, find, save, color picker |
|
||||
| 20 | ShopPaymentMethod | 0.268 | listForAdmin, find, save, allActive, mapowanie Apilo, DI kontroler |
|
||||
|
||||
### Product - szczegolowy status
|
||||
- ✅ getQuantity (ver. 0.238)
|
||||
@@ -166,12 +167,12 @@ grep -r "Product::getQuantity" .
|
||||
|
||||
## Kolejność refaktoryzacji (priorytet)
|
||||
|
||||
1-13: ✅ Cache, Product, Banner, Settings, Dictionaries, ProductArchive, Filemanager, Users, Pages, Integrations, ShopPromotion, ShopCoupon, ShopStatuses
|
||||
1-20: ✅ Cache, Product, Banner, Settings, Dictionaries, ProductArchive, Filemanager, Users, Pages, Integrations, ShopPromotion, ShopCoupon, ShopStatuses, ShopPaymentMethod
|
||||
|
||||
Nastepne:
|
||||
14. **Order**
|
||||
15. **Category**
|
||||
16. **ShopAttribute**
|
||||
21. **Order**
|
||||
22. **Category**
|
||||
23. **ShopAttribute**
|
||||
|
||||
## Form Edit System
|
||||
|
||||
@@ -248,6 +249,7 @@ tests/
|
||||
│ │ ├── Coupon/CouponRepositoryTest.php
|
||||
│ │ ├── Dictionaries/DictionariesRepositoryTest.php
|
||||
│ │ ├── Integrations/IntegrationsRepositoryTest.php
|
||||
│ │ ├── PaymentMethod/PaymentMethodRepositoryTest.php
|
||||
│ │ ├── Product/ProductRepositoryTest.php
|
||||
│ │ ├── Promotion/PromotionRepositoryTest.php
|
||||
│ │ ├── Settings/SettingsRepositoryTest.php
|
||||
@@ -261,12 +263,13 @@ tests/
|
||||
│ ├── ProductArchiveControllerTest.php
|
||||
│ ├── SettingsControllerTest.php
|
||||
│ ├── ShopCouponControllerTest.php
|
||||
│ ├── ShopPaymentMethodControllerTest.php
|
||||
│ ├── ShopPromotionControllerTest.php
|
||||
│ ├── ShopStatusesControllerTest.php
|
||||
│ └── UsersControllerTest.php
|
||||
└── Integration/
|
||||
```
|
||||
**Łącznie: 254 testów, 736 asercji**
|
||||
**Łącznie: 280 testów, 828 asercji**
|
||||
|
||||
Pelna dokumentacja testow: `TESTING.md`
|
||||
|
||||
|
||||
138
docs/SHOP_PAYMENT_METHOD_REFACTOR_PLAN.md
Normal file
138
docs/SHOP_PAYMENT_METHOD_REFACTOR_PLAN.md
Normal file
@@ -0,0 +1,138 @@
|
||||
# Plan Refaktoryzacji: shop_payment_method
|
||||
|
||||
Data utworzenia: 2026-02-14
|
||||
Status: ZREALIZOWANY (Etapy 1-4 zakonczone: 2026-02-14)
|
||||
|
||||
## 1. Cel
|
||||
|
||||
Pelna migracja modulu `/admin/shop_payment_method/*` do obecnego standardu projektu:
|
||||
- `Domain/*` dla logiki danych,
|
||||
- `admin/Controllers/*` z DI dla routingu,
|
||||
- widoki oparte o `components/table-list` i `components/form-edit`,
|
||||
- usuniecie legacy klas/podpiecie zaleznosci.
|
||||
|
||||
## 2. Stan obecny (inwentaryzacja)
|
||||
|
||||
Aktualny modul jest legacy i opiera sie o `grid`:
|
||||
- `autoload/admin/controls/class.ShopPaymentMethod.php`
|
||||
- `autoload/admin/factory/class.ShopPaymentMethod.php`
|
||||
- `autoload/admin/view/class.ShopPaymentMethod.php` (pusta)
|
||||
- `admin/templates/shop-payment-method/view-list.php` (grid + inline edit)
|
||||
- menu: `admin/templates/site/main-layout.php` -> `/admin/shop_payment_method/view_list/`
|
||||
|
||||
Zaleznosci wykryte poza modulem:
|
||||
- `autoload/admin/controls/class.ShopTransport.php` korzysta z `admin\\factory\\ShopPaymentMethod::payments_list()`
|
||||
- `autoload/front/factory/class.ShopPaymentMethod.php` ma bezposrednie zapytania do `pp_shop_payment_methods`
|
||||
- `autoload/shop/class.PaymentMethod.php` ma bezposrednie zapytania do `pp_shop_payment_methods`
|
||||
- `cron.php` korzysta z `front\\factory\\ShopPaymentMethod::get_apilo_payment_method_id()`
|
||||
|
||||
## 3. Zakres refaktoru
|
||||
|
||||
W zakresie:
|
||||
1. Nowe repozytorium domenowe dla metod platnosci.
|
||||
2. Nowy kontroler admin z DI i routingiem kanonicznym.
|
||||
3. Nowe widoki listy i edycji (bez legacy `grid`).
|
||||
4. Przepiecie zaleznosci (`ShopTransport`, `front\\factory\\ShopPaymentMethod`, `shop\\PaymentMethod`) na nowe API.
|
||||
5. Cleanup legacy klas/plikow zwiazanych z modulem.
|
||||
6. Testy jednostkowe + aktualizacja dokumentacji.
|
||||
|
||||
Poza zakresem (na ten etap):
|
||||
1. Refaktoryzacja calego modulu `shop_transport` (zrobimy tylko przepiecie zaleznosci dot. payment methods).
|
||||
2. Zmiany biznesowe w checkout poza zachowaniem obecnej logiki.
|
||||
|
||||
## 4. Architektura docelowa
|
||||
|
||||
Planowane nowe pliki:
|
||||
- `autoload/Domain/PaymentMethod/PaymentMethodRepository.php`
|
||||
- `autoload/admin/Controllers/ShopPaymentMethodController.php`
|
||||
- `admin/templates/shop-payment-method/payment-methods-list.php`
|
||||
- `admin/templates/shop-payment-method/payment-method-edit.php`
|
||||
|
||||
Planowane aktualizacje:
|
||||
- `autoload/admin/class.Site.php` (rejestracja `ShopPaymentMethod` w DI routerze)
|
||||
- `admin/templates/site/main-layout.php` (kanoniczny URL `/admin/shop_payment_method/list/`)
|
||||
- `autoload/admin/controls/class.ShopTransport.php` (usuniecie zaleznosci od legacy factory)
|
||||
- `autoload/front/factory/class.ShopPaymentMethod.php` (fasada delegujaca do Domain repo)
|
||||
- `autoload/shop/class.PaymentMethod.php` (fasada delegujaca do Domain repo)
|
||||
|
||||
Planowane usuniecia:
|
||||
- `autoload/admin/controls/class.ShopPaymentMethod.php`
|
||||
- `autoload/admin/factory/class.ShopPaymentMethod.php`
|
||||
- `autoload/admin/view/class.ShopPaymentMethod.php`
|
||||
- `admin/templates/shop-payment-method/view-list.php`
|
||||
|
||||
## 5. Etapy realizacji (Human In The Loop)
|
||||
|
||||
### Etap 1: Domain + testy repozytorium
|
||||
Zakres:
|
||||
- utworzenie `PaymentMethodRepository` z metodami:
|
||||
- `listForAdmin(...)`
|
||||
- `find(int $id)`
|
||||
- `save(int $id, array $data)`
|
||||
- `allActive()`
|
||||
- `findActiveById(int $id)`
|
||||
- `isActive(int $id)`
|
||||
- `getApiloPaymentTypeId(int $id)`
|
||||
- `forTransport(int $transportId)`
|
||||
- dodanie testu: `tests/Unit/Domain/PaymentMethod/PaymentMethodRepositoryTest.php`
|
||||
|
||||
Checkpoint:
|
||||
- STOP i prosba o akceptacje po wdrozeniu etapu 1.
|
||||
|
||||
### Etap 2: Admin Controller + routing + nowe widoki
|
||||
Zakres:
|
||||
- nowy `ShopPaymentMethodController` (akcje: `list`, `edit`, `save`)
|
||||
- migracja listy/edycji na `table-list` + `form-edit`
|
||||
- podpiecie w `admin\\Site` (DI factory map)
|
||||
- kompatybilnosc URL:
|
||||
- kanoniczne: `/admin/shop_payment_method/list|edit|save/`
|
||||
- aliasy legacy do decyzji po wdrozeniu (proponuje: tymczasowo wlaczyc)
|
||||
- test kontrolera: `tests/Unit/admin/Controllers/ShopPaymentMethodControllerTest.php`
|
||||
|
||||
Checkpoint:
|
||||
- STOP i prosba o akceptacje po wdrozeniu etapu 2.
|
||||
|
||||
### Etap 3: Przepiecie zaleznosci miedzymodulowych
|
||||
Zakres:
|
||||
- `ShopTransport` pobiera liste platnosci przez nowe repozytorium (bez legacy factory)
|
||||
- `front\\factory\\ShopPaymentMethod` jako fasada do repozytorium domenowego
|
||||
- `shop\\PaymentMethod` jako fasada do repozytorium domenowego
|
||||
- zachowanie dotychczasowych podpisow metod (BC)
|
||||
|
||||
Checkpoint:
|
||||
- STOP i prosba o akceptacje po wdrozeniu etapu 3.
|
||||
|
||||
### Etap 4: Cleanup + finalne testy + dokumentacja
|
||||
Zakres:
|
||||
- usuniecie legacy klas/plikow dla `shop_payment_method`
|
||||
- uruchomienie testow:
|
||||
- najpierw targetowane testy PaymentMethod,
|
||||
- potem caly suite (`composer test` lub `./test.ps1`)
|
||||
- aktualizacja dokumentacji:
|
||||
- `docs/DATABASE_STRUCTURE.md`
|
||||
- `docs/PROJECT_STRUCTURE.md`
|
||||
- `docs/REFACTORING_PLAN.md`
|
||||
- `docs/CHANGELOG.md`
|
||||
- `docs/TESTING.md`
|
||||
|
||||
Checkpoint:
|
||||
- STOP i prosba o finalna akceptacje przed etapem release (zip/commit/push wg procedury KONIEC PRACY, jesli zlecisz).
|
||||
|
||||
## 6. Ryzyka i kontrola regresji
|
||||
|
||||
1. Ryzyko: utrata kompatybilnosci URL (`view_list`).
|
||||
Kontrola: tymczasowe aliasy lub redirect + test akcji.
|
||||
|
||||
2. Ryzyko: regresja checkout przy pobieraniu metod platnosci.
|
||||
Kontrola: zachowanie podpisow metod we `front\\factory\\ShopPaymentMethod` i `shop\\PaymentMethod`, testy repozytorium.
|
||||
|
||||
3. Ryzyko: `ShopTransport` przestanie pokazywac metody platnosci.
|
||||
Kontrola: jawne przepiecie zaleznosci i test manualny widoku edycji transportu.
|
||||
|
||||
## 7. Kryteria akceptacji
|
||||
|
||||
1. `/admin/shop_payment_method/list/` dziala na nowym kontrolerze i nowym widoku.
|
||||
2. `/admin/shop_payment_method/edit/id={id}` i zapis dzialaja bez `grid`.
|
||||
3. Brak zaleznosci od legacy `admin\\controls\\ShopPaymentMethod` i `admin\\factory\\ShopPaymentMethod`.
|
||||
4. `ShopTransport`, frontend checkout i `cron.php` dzialaja na niezmienionych API publicznych.
|
||||
5. Nowe testy przechodza, a pelny suite nie ma regresji.
|
||||
@@ -33,10 +33,10 @@ Alternatywnie (Git Bash):
|
||||
|
||||
## Aktualny stan suite
|
||||
|
||||
Ostatnio zweryfikowano: 2026-02-13
|
||||
Ostatnio zweryfikowano: 2026-02-14
|
||||
|
||||
```text
|
||||
OK (254 tests, 736 assertions)
|
||||
OK (280 tests, 828 assertions)
|
||||
```
|
||||
|
||||
## Struktura testow
|
||||
@@ -52,6 +52,7 @@ tests/
|
||||
| | |-- Coupon/CouponRepositoryTest.php
|
||||
| | |-- Dictionaries/DictionariesRepositoryTest.php
|
||||
| | |-- Integrations/IntegrationsRepositoryTest.php
|
||||
| | |-- PaymentMethod/PaymentMethodRepositoryTest.php
|
||||
| | |-- Product/ProductRepositoryTest.php
|
||||
| | |-- Promotion/PromotionRepositoryTest.php
|
||||
| | |-- Settings/SettingsRepositoryTest.php
|
||||
@@ -65,6 +66,7 @@ tests/
|
||||
| |-- ProductArchiveControllerTest.php
|
||||
| |-- SettingsControllerTest.php
|
||||
| |-- ShopCouponControllerTest.php
|
||||
| |-- ShopPaymentMethodControllerTest.php
|
||||
| |-- ShopPromotionControllerTest.php
|
||||
| |-- ShopStatusesControllerTest.php
|
||||
| `-- UsersControllerTest.php
|
||||
|
||||
@@ -152,19 +152,83 @@ class IntegrationsRepositoryTest extends TestCase
|
||||
$this->assertNull($this->repository->apiloGetAccessToken());
|
||||
}
|
||||
|
||||
public function testShouldRefreshAccessTokenReturnsFalseForFarFutureDate(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->repository);
|
||||
$method = $reflection->getMethod('shouldRefreshAccessToken');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$future = date('Y-m-d H:i:s', time() + 3600);
|
||||
$result = $method->invoke($this->repository, $future, 300);
|
||||
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testShouldRefreshAccessTokenReturnsTrueForNearExpiryDate(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->repository);
|
||||
$method = $reflection->getMethod('shouldRefreshAccessToken');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$near = date('Y-m-d H:i:s', time() + 120);
|
||||
$result = $method->invoke($this->repository, $near, 300);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testApiloFetchListThrowsForInvalidType(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->repository->apiloFetchList('invalid');
|
||||
}
|
||||
|
||||
public function testApiloFetchListResultReturnsDetailedErrorWhenConfigMissing(): void
|
||||
{
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->expects($this->once())
|
||||
->method('fetchAll')
|
||||
->with(\PDO::FETCH_ASSOC)
|
||||
->willReturn([]);
|
||||
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT * FROM pp_shop_apilo_settings')
|
||||
->willReturn($stmt);
|
||||
|
||||
$result = $this->repository->apiloFetchListResult('payment');
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertFalse((bool)($result['success'] ?? true));
|
||||
$this->assertStringContainsString('Brakuje konfiguracji Apilo', (string)($result['message'] ?? ''));
|
||||
}
|
||||
|
||||
public function testApiloIntegrationStatusReturnsMissingConfigMessage(): void
|
||||
{
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->expects($this->once())
|
||||
->method('fetchAll')
|
||||
->with(\PDO::FETCH_ASSOC)
|
||||
->willReturn([]);
|
||||
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT * FROM pp_shop_apilo_settings')
|
||||
->willReturn($stmt);
|
||||
|
||||
$status = $this->repository->apiloIntegrationStatus();
|
||||
|
||||
$this->assertIsArray($status);
|
||||
$this->assertFalse((bool)($status['is_valid'] ?? true));
|
||||
$this->assertStringContainsString('Brakuje konfiguracji Apilo', (string)($status['message'] ?? ''));
|
||||
}
|
||||
|
||||
public function testAllPublicMethodsExist(): void
|
||||
{
|
||||
$expectedMethods = [
|
||||
'getSettings', 'getSetting', 'saveSetting',
|
||||
'linkProduct', 'unlinkProduct',
|
||||
'apiloAuthorize', 'apiloGetAccessToken',
|
||||
'apiloFetchList', 'apiloProductSearch', 'apiloCreateProduct',
|
||||
'apiloAuthorize', 'apiloGetAccessToken', 'apiloKeepalive', 'apiloIntegrationStatus',
|
||||
'apiloFetchList', 'apiloFetchListResult', 'apiloProductSearch', 'apiloCreateProduct',
|
||||
'getProductSku', 'shopproImportProduct',
|
||||
];
|
||||
|
||||
@@ -201,4 +265,37 @@ class IntegrationsRepositoryTest extends TestCase
|
||||
$settings = $this->repository->getSettings('shoppro');
|
||||
$this->assertSame('test.com', $settings['domain']);
|
||||
}
|
||||
|
||||
public function testNormalizeApiloMapListRejectsErrorPayload(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->repository);
|
||||
$method = $reflection->getMethod('normalizeApiloMapList');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->repository, [
|
||||
'message' => 'Missing JWT token',
|
||||
'code' => 401,
|
||||
]);
|
||||
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testNormalizeApiloMapListAcceptsIdNameList(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->repository);
|
||||
$method = $reflection->getMethod('normalizeApiloMapList');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$payload = [
|
||||
['id' => '1', 'name' => 'Przelew'],
|
||||
['id' => '2', 'name' => 'Karta'],
|
||||
];
|
||||
|
||||
$result = $method->invoke($this->repository, $payload);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertSame('1', (string)$result[0]['id']);
|
||||
$this->assertSame('Przelew', (string)$result[0]['name']);
|
||||
}
|
||||
}
|
||||
|
||||
337
tests/Unit/Domain/PaymentMethod/PaymentMethodRepositoryTest.php
Normal file
337
tests/Unit/Domain/PaymentMethod/PaymentMethodRepositoryTest.php
Normal file
@@ -0,0 +1,337 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Domain\PaymentMethod;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Domain\PaymentMethod\PaymentMethodRepository;
|
||||
|
||||
class PaymentMethodRepositoryTest extends TestCase
|
||||
{
|
||||
public function testFindReturnsNullForInvalidId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('get');
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$this->assertNull($repository->find(0));
|
||||
}
|
||||
|
||||
public function testFindReturnsNullWhenNotFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_payment_methods', '*', ['id' => 10])
|
||||
->willReturn(null);
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$this->assertNull($repository->find(10));
|
||||
}
|
||||
|
||||
public function testFindNormalizesData(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_payment_methods', '*', ['id' => 11])
|
||||
->willReturn([
|
||||
'id' => '11',
|
||||
'name' => ' Przelew ',
|
||||
'description' => null,
|
||||
'status' => '1',
|
||||
'apilo_payment_type_id' => '7',
|
||||
]);
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$result = $repository->find(11);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertSame(11, $result['id']);
|
||||
$this->assertSame('Przelew', $result['name']);
|
||||
$this->assertSame('', $result['description']);
|
||||
$this->assertSame(1, $result['status']);
|
||||
$this->assertSame(7, $result['apilo_payment_type_id']);
|
||||
}
|
||||
|
||||
public function testSaveUpdatesRowAndReturnsId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$updateRow = null;
|
||||
$updateWhere = null;
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('update')
|
||||
->willReturnCallback(function ($table, $row, $where) use (&$updateRow, &$updateWhere) {
|
||||
$this->assertSame('pp_shop_payment_methods', $table);
|
||||
$updateRow = $row;
|
||||
$updateWhere = $where;
|
||||
return true;
|
||||
});
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$id = $repository->save(3, [
|
||||
'description' => ' test ',
|
||||
'status' => 'on',
|
||||
'apilo_payment_type_id' => '22',
|
||||
]);
|
||||
|
||||
$this->assertSame(3, $id);
|
||||
$this->assertSame('test', $updateRow['description']);
|
||||
$this->assertSame(1, $updateRow['status']);
|
||||
$this->assertSame(22, $updateRow['apilo_payment_type_id']);
|
||||
$this->assertSame(['id' => 3], $updateWhere);
|
||||
}
|
||||
|
||||
public function testSavePreservesNonNumericApiloPaymentTypeId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$updateRow = null;
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('update')
|
||||
->willReturnCallback(function ($table, $row) use (&$updateRow) {
|
||||
$this->assertSame('pp_shop_payment_methods', $table);
|
||||
$updateRow = $row;
|
||||
return true;
|
||||
});
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$repository->save(4, [
|
||||
'description' => 'X',
|
||||
'status' => 1,
|
||||
'apilo_payment_type_id' => 'CASH_ON_DELIVERY',
|
||||
]);
|
||||
|
||||
$this->assertSame('CASH_ON_DELIVERY', $updateRow['apilo_payment_type_id']);
|
||||
}
|
||||
|
||||
public function testSaveReturnsNullForInvalidId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('update');
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$this->assertNull($repository->save(0, ['status' => 1]));
|
||||
}
|
||||
|
||||
public function testListForAdminWhitelistsSortAndDirection(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$queries = [];
|
||||
|
||||
$mockDb->method('query')
|
||||
->willReturnCallback(function ($sql, $params = []) use (&$queries) {
|
||||
$queries[] = ['sql' => $sql, 'params' => $params];
|
||||
|
||||
if (strpos($sql, 'COUNT(0)') !== false) {
|
||||
return new class {
|
||||
public function fetchAll()
|
||||
{
|
||||
return [[1]];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return new class {
|
||||
public function fetchAll()
|
||||
{
|
||||
return [[
|
||||
'id' => 1,
|
||||
'name' => 'Przelew',
|
||||
'description' => 'Opis',
|
||||
'status' => 1,
|
||||
'apilo_payment_type_id' => 5,
|
||||
]];
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$result = $repository->listForAdmin(
|
||||
[],
|
||||
'name DESC; DROP TABLE pp_shop_payment_methods; --',
|
||||
'DESC; DELETE FROM pp_users; --',
|
||||
1,
|
||||
999
|
||||
);
|
||||
|
||||
$this->assertCount(2, $queries);
|
||||
$dataSql = $queries[1]['sql'];
|
||||
|
||||
$this->assertMatchesRegularExpression('/ORDER BY\s+spm\.name\s+ASC,\s+spm\.id\s+ASC/i', $dataSql);
|
||||
$this->assertStringNotContainsString('DROP TABLE', $dataSql);
|
||||
$this->assertStringNotContainsString('DELETE FROM pp_users', $dataSql);
|
||||
$this->assertMatchesRegularExpression('/LIMIT\s+100\s+OFFSET\s+0/i', $dataSql);
|
||||
$this->assertSame(1, (int)$result['items'][0]['id']);
|
||||
}
|
||||
|
||||
public function testAllActiveReturnsNormalizedRows(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_shop_payment_methods', '*', [
|
||||
'status' => 1,
|
||||
'ORDER' => ['id' => 'ASC'],
|
||||
])
|
||||
->willReturn([
|
||||
[
|
||||
'id' => '2',
|
||||
'name' => ' PayU ',
|
||||
'description' => '',
|
||||
'status' => '1',
|
||||
'apilo_payment_type_id' => null,
|
||||
],
|
||||
]);
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$rows = $repository->allActive();
|
||||
|
||||
$this->assertCount(1, $rows);
|
||||
$this->assertSame(2, $rows[0]['id']);
|
||||
$this->assertSame('PayU', $rows[0]['name']);
|
||||
$this->assertSame(1, $rows[0]['status']);
|
||||
$this->assertNull($rows[0]['apilo_payment_type_id']);
|
||||
}
|
||||
|
||||
public function testAllForAdminReturnsRowsIncludingInactive(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_shop_payment_methods', '*', [
|
||||
'ORDER' => ['name' => 'ASC'],
|
||||
])
|
||||
->willReturn([
|
||||
[
|
||||
'id' => '1',
|
||||
'name' => 'Przelew',
|
||||
'description' => '',
|
||||
'status' => '1',
|
||||
'apilo_payment_type_id' => null,
|
||||
],
|
||||
[
|
||||
'id' => '2',
|
||||
'name' => 'PayPo',
|
||||
'description' => '',
|
||||
'status' => '0',
|
||||
'apilo_payment_type_id' => null,
|
||||
],
|
||||
]);
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$rows = $repository->allForAdmin();
|
||||
|
||||
$this->assertCount(2, $rows);
|
||||
$this->assertSame(1, $rows[0]['id']);
|
||||
$this->assertSame(2, $rows[1]['id']);
|
||||
$this->assertSame(0, $rows[1]['status']);
|
||||
}
|
||||
|
||||
public function testFindActiveByIdReturnsNullForNotFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_payment_methods', '*', [
|
||||
'AND' => [
|
||||
'id' => 4,
|
||||
'status' => 1,
|
||||
],
|
||||
])
|
||||
->willReturn(null);
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$this->assertNull($repository->findActiveById(4));
|
||||
}
|
||||
|
||||
public function testFindKeepsNonNumericApiloPaymentTypeId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_payment_methods', '*', ['id' => 12])
|
||||
->willReturn([
|
||||
'id' => '12',
|
||||
'name' => 'PayPo',
|
||||
'description' => '',
|
||||
'status' => '1',
|
||||
'apilo_payment_type_id' => 'PAYPO_DEFERRED',
|
||||
]);
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$result = $repository->find(12);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertSame('PAYPO_DEFERRED', $result['apilo_payment_type_id']);
|
||||
}
|
||||
|
||||
public function testIsActiveNormalizesStatusValue(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_payment_methods', 'status', ['id' => 5])
|
||||
->willReturn('0');
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$this->assertSame(0, $repository->isActive(5));
|
||||
}
|
||||
|
||||
public function testGetApiloPaymentTypeIdHandlesNullAndInt(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('get')
|
||||
->willReturnOnConsecutiveCalls(null, '8');
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$this->assertNull($repository->getApiloPaymentTypeId(1));
|
||||
$this->assertSame(8, $repository->getApiloPaymentTypeId(2));
|
||||
}
|
||||
|
||||
public function testGetApiloPaymentTypeIdReturnsStringForNonNumericValue(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_payment_methods', 'apilo_payment_type_id', ['id' => 3])
|
||||
->willReturn('BANK_TRANSFER');
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$this->assertSame('BANK_TRANSFER', $repository->getApiloPaymentTypeId(3));
|
||||
}
|
||||
|
||||
public function testForTransportReturnsRows(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$capturedParams = null;
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('query')
|
||||
->willReturnCallback(function ($sql, $params = []) use (&$capturedParams) {
|
||||
$this->assertStringContainsString('pp_shop_transport_payment_methods', $sql);
|
||||
$capturedParams = $params;
|
||||
|
||||
return new class {
|
||||
public function fetchAll()
|
||||
{
|
||||
return [[
|
||||
'id' => '9',
|
||||
'name' => 'Karta',
|
||||
'description' => 'Opis',
|
||||
'status' => 1,
|
||||
'apilo_payment_type_id' => '4',
|
||||
]];
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
$repository = new PaymentMethodRepository($mockDb);
|
||||
$rows = $repository->forTransport(12);
|
||||
|
||||
$this->assertSame([':transport_id' => 12], $capturedParams);
|
||||
$this->assertCount(1, $rows);
|
||||
$this->assertSame(9, $rows[0]['id']);
|
||||
$this->assertSame(4, $rows[0]['apilo_payment_type_id']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace Tests\Unit\admin\Controllers;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use admin\Controllers\ShopPaymentMethodController;
|
||||
use Domain\PaymentMethod\PaymentMethodRepository;
|
||||
|
||||
class ShopPaymentMethodControllerTest extends TestCase
|
||||
{
|
||||
private $repository;
|
||||
private $controller;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->repository = $this->createMock(PaymentMethodRepository::class);
|
||||
$this->controller = new ShopPaymentMethodController($this->repository);
|
||||
}
|
||||
|
||||
public function testConstructorAcceptsRepository(): void
|
||||
{
|
||||
$controller = new ShopPaymentMethodController($this->repository);
|
||||
$this->assertInstanceOf(ShopPaymentMethodController::class, $controller);
|
||||
}
|
||||
|
||||
public function testHasMainActionMethods(): void
|
||||
{
|
||||
$this->assertTrue(method_exists($this->controller, 'list'));
|
||||
$this->assertTrue(method_exists($this->controller, 'edit'));
|
||||
$this->assertTrue(method_exists($this->controller, 'save'));
|
||||
}
|
||||
|
||||
public function testHasNoLegacyAliasMethods(): void
|
||||
{
|
||||
$this->assertFalse(method_exists($this->controller, 'view_list'));
|
||||
$this->assertFalse(method_exists($this->controller, 'payment_method_edit'));
|
||||
$this->assertFalse(method_exists($this->controller, 'payment_method_save'));
|
||||
}
|
||||
|
||||
public function testActionMethodReturnTypes(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->controller);
|
||||
|
||||
$this->assertEquals('string', (string)$reflection->getMethod('list')->getReturnType());
|
||||
$this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType());
|
||||
$this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType());
|
||||
}
|
||||
|
||||
public function testConstructorRequiresPaymentMethodRepository(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(ShopPaymentMethodController::class);
|
||||
$constructor = $reflection->getConstructor();
|
||||
$params = $constructor->getParameters();
|
||||
|
||||
$this->assertCount(1, $params);
|
||||
$this->assertEquals('Domain\PaymentMethod\PaymentMethodRepository', $params[0]->getType()->getName());
|
||||
}
|
||||
}
|
||||
BIN
updates/0.20/ver_0.269.zip
Normal file
BIN
updates/0.20/ver_0.269.zip
Normal file
Binary file not shown.
4
updates/0.20/ver_0.269_files.txt
Normal file
4
updates/0.20/ver_0.269_files.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
F: ../admin/templates/shop-payment-method/view-list.php
|
||||
F: ../autoload/admin/controls/class.ShopPaymentMethod.php
|
||||
F: ../autoload/admin/factory/class.ShopPaymentMethod.php
|
||||
F: ../autoload/admin/view/class.ShopPaymentMethod.php
|
||||
@@ -1,3 +1,12 @@
|
||||
<b>ver. 0.269 - 14.02.2026</b><br />
|
||||
- NEW - migracja modulu `ShopPaymentMethod` do architektury Domain + DI (`Domain\PaymentMethod\PaymentMethodRepository`, `admin\Controllers\ShopPaymentMethodController`)
|
||||
- UPDATE - modul `/admin/shop_payment_method/*` przepiety z legacy `grid/gridEdit` na `components/table-list` i `components/form-edit` (nowe widoki listy i edycji)
|
||||
- UPDATE - przepiecie zaleznosci na nowe repozytorium: `admin\controls\ShopTransport`, `front\factory\ShopPaymentMethod`, `shop\PaymentMethod`
|
||||
- CLEANUP - usuniete legacy klasy/pliki: `autoload/admin/controls/class.ShopPaymentMethod.php`, `autoload/admin/factory/class.ShopPaymentMethod.php`, `autoload/admin/view/class.ShopPaymentMethod.php`, `admin/templates/shop-payment-method/view-list.php`
|
||||
- UPDATE - Apilo: dodane automatyczne odswiezanie tokenu przed wygasnieciem (`apiloKeepalive`) oraz bardziej szczegolowe komunikaty bledow integracji
|
||||
- UPDATE - testy: `OK (280 tests, 828 assertions)` + nowe pliki testowe `PaymentMethodRepositoryTest`, `ShopPaymentMethodControllerTest`
|
||||
- UPDATE - pliki aktualizacji: `updates/0.20/ver_0.269.zip`, `ver_0.269_files.txt`
|
||||
<hr>
|
||||
<b>ver. 0.268 - 14.02.2026</b><br />
|
||||
- NEW - migracja modulu `ShopStatuses` do architektury Domain + DI (`Domain\ShopStatus\ShopStatusRepository`, `admin\Controllers\ShopStatusesController`)
|
||||
- UPDATE - modul `/admin/shop_statuses/*` przepiety z legacy `grid/gridEdit` na `components/table-list` i `components/form-edit`
|
||||
@@ -482,4 +491,3 @@
|
||||
<b>ver. 0.142</b><br />
|
||||
- FIX - poprawa adresu strony głównej
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?
|
||||
$current_ver = 268;
|
||||
$current_ver = 269;
|
||||
|
||||
for ($i = 1; $i <= $current_ver; $i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user