1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FluxSE\PayumStripe\Action; |
6
|
|
|
|
7
|
|
|
use ArrayObject; |
8
|
|
|
use FluxSE\PayumStripe\Request\Api\Resource\CreateRefund; |
9
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
10
|
|
|
use Payum\Core\Request\Refund; |
11
|
|
|
use Stripe\PaymentIntent; |
12
|
|
|
use Stripe\Refund as StripeRefund; |
13
|
|
|
|
14
|
|
|
final class RefundAction extends AbstractPaymentIntentAwareAction |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param Refund $request |
18
|
|
|
*/ |
19
|
|
|
public function execute($request): void |
20
|
|
|
{ |
21
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
22
|
|
|
|
23
|
|
|
/** @var ArrayObject $model */ |
24
|
|
|
$model = $request->getModel(); |
25
|
|
|
|
26
|
|
|
$object = $model['object'] ?? null; |
27
|
|
|
if (PaymentIntent::OBJECT_NAME !== $object) { |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$id = $model['id'] ?? null; |
32
|
|
|
if (empty($id)) { |
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$refundModel = new ArrayObject([ |
37
|
|
|
'payment_intent' => $id, |
38
|
|
|
]); |
39
|
|
|
$this->embedNotifyTokenHash($refundModel, $request); |
40
|
|
|
|
41
|
|
|
$refundRequest = new CreateRefund($refundModel->getArrayCopy()); |
42
|
|
|
$this->gateway->execute($refundRequest); |
43
|
|
|
|
44
|
|
|
/** @var StripeRefund $refund */ |
45
|
|
|
$refund = $refundRequest->getApiResource(); |
46
|
|
|
$model->exchangeArray($refund->toArray()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The token hash will be stored to a different |
51
|
|
|
* metadata key to avoid consuming the default one. |
52
|
|
|
*/ |
53
|
|
|
public function getTokenHashMetadataKeyName(): string |
54
|
|
|
{ |
55
|
|
|
return TokenHashKeysInterface::REFUND_TOKEN_HASH_KEY_NAME; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function supports($request): bool |
59
|
|
|
{ |
60
|
|
|
if (false === $request instanceof Refund) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $request->getModel() instanceof ArrayObject; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|