forked from LiveCarta/PayPal-PHP-Server-SDK
209 lines
6.5 KiB
PHP
209 lines
6.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* PaypalServerSDKLib
|
|
*
|
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
*/
|
|
|
|
namespace PaypalServerSDKLib\Tests\UnitTests;
|
|
|
|
use PaypalServerSDKLib\Controllers\PaymentsController;
|
|
use PaypalServerSDKLib\Models\Builders\CaptureRequestBuilder;
|
|
use PaypalServerSDKLib\Models\Builders\MoneyBuilder;
|
|
use PaypalServerSDKLib\Models\Builders\RefundRequestBuilder;
|
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
|
|
|
class PaymentsControllerTest extends BaseTestController
|
|
{
|
|
/**
|
|
* @var PaymentsController PaymentsController instance
|
|
*/
|
|
protected static $controller;
|
|
private const NON_EXISTENT_AUTHORIZATION_ID = 'authorization_id8';
|
|
private const NON_EXISTENT_CAPTURE_ID = 'capture_id';
|
|
private const NON_EXISTENT_REFUND_ID = 'refund_id';
|
|
private const ALREADY_AUTHORIZED_ID = '3BJ81821K7933911P';
|
|
|
|
/**
|
|
* Setup test class
|
|
*/
|
|
public static function setUpBeforeClass(): void
|
|
{
|
|
self::$controller = parent::getClient()->getPaymentsController();
|
|
}
|
|
|
|
public function testAuthorizationsGetWithStatus404()
|
|
{
|
|
// Perform API call
|
|
$result = self::$controller->authorizationsGet(self::NON_EXISTENT_AUTHORIZATION_ID);
|
|
|
|
$headers = [];
|
|
$headers['Content-Type'] = ['application/json;charset=UTF-8', true];
|
|
|
|
// Assert result with expected response
|
|
$this->assertTrue($result->isError());
|
|
$this->newTestCase($result->getResult())
|
|
->expectStatus(404)
|
|
->allowExtraHeaders()
|
|
->expectHeaders($headers)
|
|
->assert();
|
|
}
|
|
|
|
public function testCapturesGetWithStatus404()
|
|
{
|
|
// Perform API call
|
|
$result = self::$controller->capturesGet(self::NON_EXISTENT_CAPTURE_ID);
|
|
|
|
$headers = [];
|
|
$headers['Content-Type'] = ['application/json;charset=UTF-8', true];
|
|
|
|
// Assert result with expected response
|
|
$this->assertTrue($result->isError());
|
|
$this->newTestCase($result->getResult())
|
|
->expectStatus(404)
|
|
->allowExtraHeaders()
|
|
->expectHeaders($headers)
|
|
->assert();
|
|
}
|
|
|
|
public function testRefundsGetWithStatus404()
|
|
{
|
|
// Perform API call
|
|
$result = self::$controller->refundsGet(self::NON_EXISTENT_REFUND_ID);
|
|
|
|
$headers = [];
|
|
$headers['Content-Type'] = ['application/json', true];
|
|
|
|
// Assert result with expected response
|
|
$this->assertTrue($result->isError());
|
|
$this->newTestCase($result->getResult())
|
|
->expectStatus(404)
|
|
->allowExtraHeaders()
|
|
->expectHeaders($headers)
|
|
->assert();
|
|
}
|
|
|
|
public function testAuthorizationsCaptureWithStatus404()
|
|
{
|
|
// Parameters for the API call
|
|
$request = [
|
|
'body' => CaptureRequestBuilder::init()->finalCapture(false)->build(),
|
|
'authorizationId' => self::NON_EXISTENT_AUTHORIZATION_ID,
|
|
'prefer' => 'return=minimal'
|
|
];
|
|
// Perform API call
|
|
$result = self::$controller->authorizationsCapture($request);
|
|
|
|
$headers = [];
|
|
$headers['Content-Type'] = ['application/json;charset=UTF-8', true];
|
|
|
|
// Assert result with expected response
|
|
$this->assertTrue($result->isError());
|
|
$this->newTestCase($result->getResult())
|
|
->expectStatus(404)
|
|
->allowExtraHeaders()
|
|
->expectHeaders($headers)
|
|
->assert();
|
|
}
|
|
|
|
public function testAuthorizationsReauthorizeWithStatus404()
|
|
{
|
|
// Parameters for the API call
|
|
$request = [
|
|
'authorizationId' => self::NON_EXISTENT_AUTHORIZATION_ID,
|
|
'prefer' => 'return=minimal'
|
|
];
|
|
// Perform API call
|
|
$result = self::$controller->authorizationsReauthorize($request);
|
|
|
|
$headers = [];
|
|
$headers['Content-Type'] = ['application/json;charset=UTF-8', true];
|
|
|
|
// Assert result with expected response
|
|
$this->assertTrue($result->isError());
|
|
$this->newTestCase($result->getResult())
|
|
->expectStatus(404)
|
|
->allowExtraHeaders()
|
|
->expectHeaders($headers)
|
|
->assert();
|
|
}
|
|
|
|
public function testAuthorizationsVoidWithStatus404()
|
|
{
|
|
// Parameters for the API call
|
|
$request = [
|
|
'authorizationId' => self::NON_EXISTENT_AUTHORIZATION_ID,
|
|
'prefer' => 'return=minimal'
|
|
];
|
|
// Perform API call
|
|
$result = self::$controller->authorizationsVoid($request);
|
|
|
|
$headers = [];
|
|
$headers['Content-Type'] = ['application/json', true];
|
|
|
|
// Assert result with expected response
|
|
$this->assertTrue($result->isError());
|
|
$this->newTestCase($result->getResult())
|
|
->expectStatus(404)
|
|
->allowExtraHeaders()
|
|
->expectHeaders($headers)
|
|
->assert();
|
|
}
|
|
|
|
public function testAuthorizationsVoidWithStatus422()
|
|
{
|
|
// Parameters for the API call
|
|
$request = [
|
|
'authorizationId' => self::ALREADY_AUTHORIZED_ID,
|
|
'prefer' => 'return=minimal'
|
|
];
|
|
// Perform API call
|
|
$result = self::$controller->authorizationsVoid($request);
|
|
|
|
$headers = [];
|
|
$headers['Content-Type'] = ['application/json', true];
|
|
|
|
// Assert result with expected response
|
|
$this->assertTrue($result->isError());
|
|
$this->newTestCase($result->getResult())
|
|
->expectStatus(422)
|
|
->allowExtraHeaders()
|
|
->expectHeaders($headers)
|
|
->assert();
|
|
}
|
|
|
|
public function testCapturesRefundWithStatus404()
|
|
{
|
|
// Parameters for the API call
|
|
$request = [
|
|
'captureId' => self::NON_EXISTENT_CAPTURE_ID,
|
|
'prefer' => 'return=minimal',
|
|
'body' => RefundRequestBuilder::init()
|
|
->amount(
|
|
MoneyBuilder::init(
|
|
'USD',
|
|
'1.44'
|
|
)->build()
|
|
)
|
|
->noteToPayer('Defective product')
|
|
->build()
|
|
];
|
|
// Perform API call
|
|
$result = self::$controller->capturesRefund($request);
|
|
|
|
$headers = [];
|
|
$headers['Content-Type'] = ['application/json', true];
|
|
|
|
// Assert result with expected response
|
|
$this->assertTrue($result->isError());
|
|
$this->newTestCase($result->getResult())
|
|
->expectStatus(404)
|
|
->allowExtraHeaders()
|
|
->expectHeaders($headers)
|
|
->assert();
|
|
}
|
|
}
|