Skip to content

Commit

Permalink
Remove Carbon dependency from WordPress Plug-in
Browse files Browse the repository at this point in the history
  • Loading branch information
daanrijpkemacb committed Nov 25, 2023
1 parent 9c0320e commit 24df9a1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
18 changes: 14 additions & 4 deletions bluem-integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
}

use Bluem\BluemPHP\Bluem;
use Carbon\Carbon;

function bluem_woocommerce_integrations_settings_section() {
echo '<p><a id="tab_integrations"></a></p>';
Expand Down Expand Up @@ -504,7 +503,7 @@ function bluem_woocommerce_integration_wpcf7_submit() {
wp_redirect( $transactionURL );
exit;
} catch (\Exception $e) {
var_dump($e->getMessage());
exit("Error");
}
}
else
Expand Down Expand Up @@ -975,7 +974,10 @@ function bluem_woocommerce_integration_gform_submit( $entry, $form ) {
}
die;
} catch (\Exception $e) {
var_dump($e->getMessage());
echo json_encode([
'success' => false
]);
die();
}
}
}
Expand Down Expand Up @@ -1176,12 +1178,20 @@ function bluem_woocommerce_integration_gform_callback()

$payload = json_decode(json_encode($newPayload));

$mandateDateTimeFormatted = '';
try {
$mandateDateTime = new DateTimeImmutable($payload->report->DateTime);
$mandateDateTimeFormatted = $mandateDateTime->format('d-m-Y H:i');
} catch (Exception $e) {
}


if ($value['field_name'] === 'bluem_mandate_accountname') {
$newValue = $payload->report->DebtorAccountName;
} elseif ($value['field_name'] === 'bluem_mandate_request_id') {
$newValue = $payload->report->MandateRequestID;
} elseif ($value['field_name'] === 'bluem_mandate_datetime') {
$newValue = Carbon::parse($payload->report->DateTime)->format('d-m-Y H:i');
$newValue = $mandateDateTimeFormatted;
} elseif ($value['field_name'] === 'bluem_mandate_iban') {
$newValue = $payload->report->DebtorIBAN;
}
Expand Down
14 changes: 8 additions & 6 deletions bluem-interface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use Carbon\Carbon;

// @todo create a language file and consistently localize everything

function bluem_get_idin_logo_html() {
Expand Down Expand Up @@ -53,8 +51,12 @@ function bluem_render_request_table( $requests, $users_by_id = [] ) {
</span>
</td>
<td width="20%"><?php bluem_render_request_user( $r, $users_by_id ); ?></td>
<?php $rdate = Carbon::parse( $r->timestamp, 'UTC' )->setTimeZone( "Europe/Amsterdam" ); ?>
<td width="15%" title="<?php echo $rdate->format( "d-m-Y H:i:s" ); ?>"><?php echo $rdate->format( "d-m-Y H:i:s" ); ?></td>
<?php
$rdate = new DateTimeImmutable( $r->timestamp, new DateTimeZone('Europe/Amsterdam'));
$rdateFormatted = $rdate->format("d-m-Y H:i:s" )

?>
<td width="15%" title="<?php echo $rdateFormatted; ?>"><?php echo $rdateFormatted; ?></td>
<td width="20%">
<?php
if ( ! is_null( $r->order_id ) && $r->order_id != "0" ) {
Expand Down Expand Up @@ -352,8 +354,8 @@ function bluem_render_requests_list( $requests ) {
<span class="bluem-request-label">
Tijdstip
</span>
<?php $rdate = strtotime( $r->timestamp ); ?>
<?php echo date( "d-m-Y H:i:s", $rdate ); ?>
<?php $rdate = new DateTimeImmutable( $r->timestamp , new DateTimeZone("Europe/Amsterdam")); ?>
<?php echo $rdate->format( "d-m-Y H:i:s" ); ?>
</div>


Expand Down
1 change: 0 additions & 1 deletion bluem-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
}

use Bluem\BluemPHP\Bluem as Bluem;
use Carbon\Carbon;

/*
* This action hook registers our PHP class as a WooCommerce payment gateway
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"require": {
"php": ">=7.4|>=8.0",
"nesbot/carbon": "^2.53",
"bluem-development/bluem-php": "^2.2|^2.3",
"symfony/polyfill-php72": "^1.22",
"symfony/polyfill-mbstring": "v1.19.0",
Expand Down
36 changes: 23 additions & 13 deletions gateways/Bluem_Bank_Based_Payment_Gateway.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

use Carbon\Carbon;

include_once __DIR__ . '/Bluem_Payment_Gateway.php';

abstract class Bluem_Bank_Based_Payment_Gateway extends Bluem_Payment_Gateway
{
private const EURO_CURRENCY = 'EUR';
/**
* @var ?string
*/
Expand Down Expand Up @@ -134,17 +133,21 @@ public function process_payment($order_id)

$bluem_payments_ideal_bic = isset($_POST['bluem_payments_ideal_bic']) ? sanitize_text_field($_POST['bluem_payments_ideal_bic']) : '';

$currency = self::EURO_CURRENCY;
// @todo: get dynamically from order

$debtorReference = $order_id;
$amount = $order->get_total();
$currency = "EUR"; // get dynamically from order
$dueDateTime = Carbon::now()->addDay();

$currentDateTime = new DateTimeImmutable();
$dueDateTime = $currentDateTime->modify('+1 day');

try {
$request = $this->bluem->CreatePaymentRequest(
$description,
$debtorReference,
$amount,
$dueDateTime,
$dueDateTime->format('Y-m-d H:i:s'),
$currency,
$entranceCode,
home_url( sprintf( 'wc-api/' . $this->id . '_callback?entranceCode=%s', $entranceCode ) )
Expand All @@ -162,7 +165,14 @@ public function process_payment($order_id)

if ( !empty( $bluem_payments_ideal_bic ) )
{
$request->selectDebtorWallet( $bluem_payments_ideal_bic );
try {
$request->selectDebtorWallet($bluem_payments_ideal_bic);
} catch (Exception $e) {
return array(
'exception' => $e->getMessage(),
'result' => 'failure'
);
}
}

// temp overrides
Expand All @@ -171,14 +181,14 @@ public function process_payment($order_id)
$request->dueDateTime = $dueDateTime->format( BLUEM_LOCAL_DATE_FORMAT ) . ".000Z";
$request->debtorReturnURL = home_url( sprintf( 'wc-api/' . $this->id . '_callback?entranceCode=%s', $entranceCode ) );

$payload = json_encode( [
'environment' => $this->bluem_config->environment,
'amount' => $amount,
'method' => $this->bankSpecificBrandID,
'currency' => $currency,
'due_date' => $request->dueDateTime,
$payload = json_encode([
'environment' => $this->bluem_config->environment,
'amount' => $amount,
'method' => $this->bankSpecificBrandID,
'currency' => $currency,
'due_date' => $request->dueDateTime,
'payment_reference' => $request->paymentReference
] );
], JSON_THROW_ON_ERROR);

// allow third parties to add additional data to the request object through this additional action
$request = apply_filters(
Expand Down

0 comments on commit 24df9a1

Please sign in to comment.