Drop refund handling, finalize captures via webhook, add profanity filter
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
35f5d1acfb
commit
2e3abf33d9
11 files changed
+420
-82
No files matched your search
@@ -5,6 +5,7 @@ namespace StreamGoals\Rest;
|
||||
|
||||
use StreamGoals\Core\Money;
|
||||
use StreamGoals\Core\Settings;
|
||||
use StreamGoals\PayPal\CaptureFinalizer;
|
||||
use StreamGoals\PayPal\Client;
|
||||
use StreamGoals\PayPal\DonationStore;
|
||||
use StreamGoals\PayPal\OrderValidator;
|
||||
@@ -112,18 +113,19 @@ final class DonateController {
|
||||
return new \WP_Error( 'sg_paypal', __( 'The payment could not be completed. You have not been charged.', 'streamgoals-donate' ), array( 'status' => 502 ) );
|
||||
}
|
||||
|
||||
if ( 'COMPLETED' !== $cap['status'] || '' === $cap['capture_id'] ) {
|
||||
// e.g. PENDING (e-check/review). The COMPLETED webhook will finalize it.
|
||||
$res = CaptureFinalizer::finalize(
|
||||
$row,
|
||||
(string) $cap['status'],
|
||||
(string) $cap['capture_id'],
|
||||
$cap['amount'],
|
||||
array( DonationStore::class, 'mark_completed' ),
|
||||
array( DonationStore::class, 'notify_applied' )
|
||||
);
|
||||
if ( CaptureFinalizer::PENDING === $res ) {
|
||||
// PENDING capture (e-check/review) or amount mismatch: stay pending; the COMPLETED webhook finalizes it.
|
||||
error_log( 'StreamGoals: capture for donation ' . $row->id . ' not finalized (status ' . $cap['status'] . '); awaiting webhook' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
|
||||
return new \WP_REST_Response( array( 'status' => 'processing' ), 202 );
|
||||
}
|
||||
$amt = $cap['amount'];
|
||||
if ( ! $amt || $amt->minor !== (int) $row->total_minor || $amt->currency !== $row->currency ) {
|
||||
error_log( 'StreamGoals: captured amount mismatch for donation ' . $row->id ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
|
||||
return new \WP_REST_Response( array( 'status' => 'processing' ), 202 );
|
||||
}
|
||||
if ( DonationStore::mark_completed( (int) $row->id, $cap['capture_id'] ) ) {
|
||||
DonationStore::notify_applied( (int) $row->id );
|
||||
}
|
||||
return rest_ensure_response( array( 'status' => 'completed' ) );
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user