Skip to content

Commit

Permalink
Merge branch 'release/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed May 30, 2022
2 parents 661e1b8 + 36ea9c7 commit e9ce51f
Show file tree
Hide file tree
Showing 20 changed files with 342 additions and 133 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ jobs:
phpstan:
uses: pronamic/actions/.github/workflows/phpstan.yml@main

psalm:
uses: pronamic/actions/.github/workflows/psalm.yml@main

phpunit:
uses: pronamic/actions/.github/workflows/phpunit.yml@main

Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## [Unreleased][unreleased]
-

## [4.2.0] - 2022-05-30
### Added
- Added support for other currencies in WordPress admin test meta box.
- Added support for required field in payment gateway settings API.
- Added payment charged back amount support. ([pronamic/wp-pronamic-pay#165](https://github.com/pronamic/wp-pronamic-pay/issues/165), [pronamic/wp-pronamic-pay#170](https://github.com/pronamic/wp-pronamic-pay/issues/170))

### Changed
- Updated logos library to version `1.8.2`.
- Add payment note on invalid gateway configuration ID. ([#pronamic/wp-pronamic-pay#195](https://github.com/pronamic/wp-pronamic-pay/issues/195))
- Add gateway ID to payment gateway JSON for convenience.

### Fixed
- Continue processing other gateways on error when updating active payment methods.

## [4.1.3] - 2022-05-04
### Changed
- Solved some PHPStan and Psalm errors.
Expand Down Expand Up @@ -487,7 +501,8 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## 1.0.0
- First release.

[unreleased]: https://github.com/pronamic/wp-pay-core/compare/4.1.3...HEAD
[unreleased]: https://github.com/pronamic/wp-pay-core/compare/4.2.0...HEAD
[4.2.0]: https://github.com/pronamic/wp-pay-core/compare/4.1.3...4.2.0
[4.1.3]: https://github.com/pronamic/wp-pay-core/compare/4.1.2...4.1.3
[4.1.2]: https://github.com/pronamic/wp-pay-core/compare/4.1.1...4.1.2
[4.1.1]: https://github.com/pronamic/wp-pay-core/compare/4.1.0...4.1.1
Expand Down
82 changes: 41 additions & 41 deletions docs/hooks.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wp-pay/core",
"version": "4.1.3",
"version": "4.2.0",
"description": "Core components for the WordPress payment processing library.",
"repository": {
"type": "git",
Expand Down
14 changes: 10 additions & 4 deletions src/Admin/AdminModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,22 @@ public function maybe_test_payment() {
}

// Amount.
$string = \filter_input( INPUT_POST, 'test_amount', \FILTER_SANITIZE_STRING );
$currency_code = 'EUR';

if ( \array_key_exists( 'test_currency_code', $_POST ) ) {
$currency_code = \sanitize_text_field( \wp_unslash( $_POST['test_currency_code'] ) );
}

$value = \filter_input( INPUT_POST, 'test_amount', \FILTER_SANITIZE_STRING );

try {
$amount = Number::from_string( $string );
$amount = Number::from_string( $value );
} catch ( \Exception $e ) {
\wp_die( \esc_html( $e->getMessage() ) );
}

$price = new Money( $amount, $currency_code );

/*
* Payment.
*/
Expand Down Expand Up @@ -728,8 +736,6 @@ public function maybe_test_payment() {

$line = $payment->lines->new_line();

$price = new Money( $amount, 'EUR' );

$line->set_name( __( 'Test', 'pronamic_ideal' ) );
$line->set_unit_price( $price );
$line->set_quantity( 1 );
Expand Down
41 changes: 30 additions & 11 deletions src/Admin/AdminPaymentPostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,29 +529,48 @@ public function custom_columns( $column, $post_id ) {
case 'pronamic_payment_amount':
$total_amount = $payment->get_total_amount();

$refunded_value = null;
$remaining_amount = $total_amount;

$tip = [];

$refunded_amount = $payment->get_refunded_amount();

if ( null !== $refunded_amount ) {
$refunded_value = $refunded_amount->get_value();
$remaining_amount = $remaining_amount->subtract( $refunded_amount );

$tip[] = \sprintf(
/* translators: %s: formatted amount */
__( '%s refunded', 'pronamic_ideal' ),
$refunded_amount->format_i18n()
);
}

$charged_back_amount = $payment->get_charged_back_amount();

if ( null !== $charged_back_amount ) {
$remaining_amount = $remaining_amount->subtract( $charged_back_amount );

$tip[] = \sprintf(
/* translators: %s: formatted amount */
__( '%s charged back', 'pronamic_ideal' ),
$charged_back_amount->format_i18n()
);
}

// Check refunded amount.
if ( empty( $refunded_value ) ) {
if ( $total_amount->get_value() === $remaining_amount->get_value() ) {
echo esc_html( $total_amount->format_i18n() );

break;
}

// Show original amount and refunded amount.
if ( null !== $refunded_amount ) {
echo \sprintf(
'<del>%1$s</del> %2$s',
esc_html( $total_amount->format_i18n() ),
\esc_html( $total_amount->subtract( $refunded_amount )->format_i18n() )
);
}
// Show original amount and remaining amount.
echo \sprintf(
'<del class="pronamic-pay-tip" data-toggle="tooltip" data-placement="top" title="%3$s">%1$s</del> %2$s',
esc_html( $total_amount->format_i18n() ),
\esc_html( $remaining_amount->format_i18n() ),
\esc_html( implode( ', ', $tip ) )
);

break;
case 'pronamic_payment_date':
Expand Down
2 changes: 1 addition & 1 deletion src/Cards.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function get_card( $bic_or_brand ) {
*/
public function get_card_logo_url( $brand ) {
return sprintf(
'https://cdn.wp-pay.org/jsdelivr.net/npm/@wp-pay/logos@1.6.6/dist/cards/%1$s/card-%1$s-logo-_x80.svg',
'https://cdn.wp-pay.org/jsdelivr.net/npm/@wp-pay/logos@1.8.2/dist/cards/%1$s/card-%1$s-logo-_x80.svg',
$brand
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public static function get_icon_url( $method = null, $size = null ) {
}

return \sprintf(
'https://cdn.wp-pay.org/jsdelivr.net/npm/@wp-pay/logos@1.7.1/dist/methods/%1$s/method-%1$s-%2$s.svg',
'https://cdn.wp-pay.org/jsdelivr.net/npm/@wp-pay/logos@1.8.2/dist/methods/%1$s/method-%1$s-%2$s.svg',
\str_replace( '_', '-', $method ),
$size
);
Expand Down Expand Up @@ -652,7 +652,7 @@ public static function update_active_payment_methods() {
$payment_methods = $gateway->get_transient_available_payment_methods( false );
} catch ( \Exception $e ) {
// Do not update active payment methods on error.
return;
continue;
}

if ( null === $payment_methods ) {
Expand Down
37 changes: 37 additions & 0 deletions src/Payments/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class Payment extends PaymentInfo {
*/
private $refunded_amount;

/**
* Charged back amount.
*
* @var Money|null
*/
private $charged_back_amount;

/**
* The status of this payment.
*
Expand Down Expand Up @@ -245,6 +252,25 @@ public function set_refunded_amount( $refunded_amount ) {
$this->refunded_amount = $refunded_amount;
}

/**
* Get charged back amount.
*
* @return Money|null
*/
public function get_charged_back_amount(): ?Money {
return $this->charged_back_amount;
}

/**
* Set charged back amount.
*
* @param Money|null $charged_back_amount Charged back amount.
* @return void
*/
public function set_charged_back_amount( ?Money $charged_back_amount ) {
$this->charged_back_amount = $charged_back_amount;
}

/**
* Get the payment status.
*
Expand Down Expand Up @@ -710,6 +736,10 @@ public static function from_json( $json, $payment = null ) {
$payment->set_refunded_amount( MoneyJsonTransformer::from_json( $json->refunded_amount ) );
}

if ( isset( $json->charged_back_amount ) ) {
$payment->set_charged_back_amount( MoneyJsonTransformer::from_json( $json->charged_back_amount ) );
}

if ( isset( $json->expiry_date ) ) {
$payment->set_expiry_date( new DateTime( $json->expiry_date ) );
}
Expand Down Expand Up @@ -792,6 +822,13 @@ public function get_json() {
$properties['refunded_amount'] = $refunded_amount->jsonSerialize();
}

// Charged back amount.
$charged_back_amount = $this->get_charged_back_amount();

if ( null !== $charged_back_amount ) {
$properties['charged_back_amount'] = $charged_back_amount->jsonSerialize();
}

// Subscriptions.
$subscriptions = $this->get_subscriptions();

Expand Down
5 changes: 3 additions & 2 deletions src/Payments/PaymentInfoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ public static function to_json( PaymentInfo $payment_info ) {

if ( null !== $config_id ) {
$object->gateway = (object) [
'$ref' => \rest_url(
'$ref' => \rest_url(
\sprintf(
'/%s/%s/%d',
'pronamic-pay/v1',
'gateways',
$config_id
)
),
'post_id' => $config_id,
'post_id' => $config_id,
'gateway_id' => \get_post_meta( $config_id, '_pronamic_gateway_id', true ),
];
}

Expand Down
5 changes: 3 additions & 2 deletions src/Payments/PaymentsDataStoreCPT.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ public function create( Payment $payment ) {

$result = wp_insert_post(
/**
* PHPStan doesn't like our custom `pronamic_payment` argument.
* The 'pronamic_payment' key is not an official argument for the
* WordPress `wp_insert_post` function.
*
* @todo Eliminate use of custom `pronamic_payment` argument.
* @todo Simplify storing payments.
* @phpstan-ignore-next-line
*/
[
Expand Down
Loading

0 comments on commit e9ce51f

Please sign in to comment.