Passed
Push — master ( 5addfc...e8c424 )
by Manuel
59s queued 11s
created

example/Transaction/3-example-refund.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
use \Ticketpark\SaferpayJson\Container;
4
use \Ticketpark\SaferpayJson\Response\ErrorResponse;
5
use \Ticketpark\SaferpayJson\Request\Transaction\RefundRequest;
6
7
require_once __DIR__ . '/../../vendor/autoload.php';
8
require_once __DIR__ . '/../credentials.php';
9
10
// A transaction id you received with a successful assert request (see ../PaymentPage/2-example-assert.php)
11
12
$transactionId = 'xxx';
13
14
// Step 1:
15
// Prepare the refund request
16
// https://saferpay.github.io/jsonapi/1.2/#Payment_v1_Transaction_Refund
17
18
$requestHeader = (new Container\RequestHeader())
19
    ->setCustomerId($customerId)
20
    ->setRequestId(uniqid());
21
22
$transactionReference = (new Container\TransactionReference())
23
    ->setTransactionId($transactionId);
24
25
$amount = (new Container\Amount())
26
    ->setCurrencyCode('CHF')
27
    ->setValue(5000); // amount in cents
28
29
$refund = (new Container\Refund())
30
    ->setAmount($amount);
31
32
$response = (new RefundRequest($apiKey, $apiSecret))
33
    ->setRequestHeader($requestHeader)
34
    ->setTransactionReference($transactionReference)
35
    ->setRefund($refund)
36
    ->execute();
37
38
// Step 2:
39
// Check for successful response
40
41
/** @var \Ticketpark\SaferpayJson\Transaction\RefundResponse */
42
if ($response instanceof ErrorResponse) {
43
    die($response->getErrorMessage());
44
}
45
46
echo 'The transaction has successfully been refunded! Transaction-ID: ' . $response->getTransaction()->getId();
0 ignored issues
show
The method getTransaction() does not exist on Ticketpark\SaferpayJson\Response\ResponseInterface. It seems like you code against a sub-type of Ticketpark\SaferpayJson\Response\ResponseInterface such as Ticketpark\SaferpayJson\...mentPage\AssertResponse or Ticketpark\SaferpayJson\...orizeReferencedResponse or Ticketpark\SaferpayJson\...AuthorizeDirectResponse or Ticketpark\SaferpayJson\...nsaction\RefundResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
echo 'The transaction has successfully been refunded! Transaction-ID: ' . $response->/** @scrutinizer ignore-call */ getTransaction()->getId();
Loading history...
47