Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper actions to easier execute common actions #969

Merged
merged 5 commits into from
Nov 17, 2023
Merged

Conversation

pierredup
Copy link
Member

Add helper methods on the Payum class to make it easier to execute specific actions:

Capture

Capturing a payment

$response = $payum->capture($_REQUEST);

$response->send();

changes to capture.php script

- $token = $payum->getHttpRequestVerifier()->verify($_REQUEST);
- $gateway = $payum->getGateway($token->getGatewayName());
- 
- /** @var \Payum\Core\GatewayInterface $gateway */
- if ($reply = $gateway->execute(new Capture($token), true)) {
-     if ($reply instanceof HttpRedirect) {
-         header("Location: ".$reply->getUrl());
-         die();
-     } elseif ($reply instanceof HttpPostRedirect) {
-         echo $reply->getContent();
-         die();
-     }
- 
-     throw new \LogicException('Unsupported reply', null, $reply);
- }
- 
- /** @var \Payum\Core\Payum $payum */
- $payum->getHttpRequestVerifier()->invalidate($token);
- 
- header("Location: ".$token->getAfterUrl());
- 
+ 
+ $response = $payum->capture();
+
+ $response->send();

Done

Finishing a payment

$payment = $payum->done($_REQUEST);

assert($payment instanceof PaymentInterface);

changes to done.php script

- /** @var \Payum\Core\Payum $payum */
- $token = $payum->getHttpRequestVerifier()->verify($_REQUEST);
- $gateway = $payum->getGateway($token->getGatewayName());
- 
- $payum->getHttpRequestVerifier()->invalidate($token);
- $gateway->execute($status = new GetHumanStatus($token));
- $payment = $status->getFirstModel();
+ $payment = $payum->done($_REQUEST);

header('Content-Type: application/json');
echo json_encode([
    'order' => [
        'total_amount' => $payment->getTotalAmount(),
        'currency_code' => $payment->getCurrencyCode(),
        'details' => $payment->getDetails(),
    ],
]);

Notify

Receiving payment notification

$response = $payum->notify($_REQUEST);

$response->send()

changes to notify.php script

- $token = $payum->getHttpRequestVerifier()->verify($_REQUEST);
- $gateway = $payum->getGateway($token->getGatewayName());
- 
- try {
-     $gateway->execute(new Notify($token));
- 
-     http_response_code(204);
-     echo 'OK';
- } catch (HttpResponse $reply) {
-     foreach ($reply->getHeaders() as $name => $value) {
-         header("$name: $value");
-     }
- 
-     http_response_code($reply->getStatusCode());
-     echo ($reply->getContent());
- 
-     exit;
- } catch (ReplyInterface $reply) {
-     throw new \LogicException('Unsupported reply', null, $reply);
- }
+ $response = $payum->notify($_REQUEST);
+ 
+ $response->send()

@pierredup pierredup added this to the 2.0.0 milestone Nov 16, 2023
@pierredup pierredup self-assigned this Nov 16, 2023
@pierredup pierredup merged commit f1664ed into master Nov 17, 2023
8 checks passed
@pierredup pierredup deleted the helper-methods branch November 17, 2023 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants