Добавлены уведомления по Сделкам и Выплатам

This commit is contained in:
Антон Н. Николаев
2021-11-16 14:06:55 +03:00
parent 1d62e6336e
commit 6b332d11ec
321 changed files with 3063 additions and 429 deletions
@@ -1,20 +1,29 @@
<?php
namespace Model\Notification;
namespace Tests\YooKassa\Model\Notification;
use PHPUnit\Framework\TestCase;
use YooKassa\Helpers\Random;
use YooKassa\Model\ConfirmationType;
use YooKassa\Model\CurrencyCode;
use YooKassa\Model\Deal\DealStatus;
use YooKassa\Model\Deal\DealType;
use YooKassa\Model\Deal\FeeMoment;
use YooKassa\Model\Notification\AbstractNotification;
use YooKassa\Model\Notification\NotificationFactory;
use YooKassa\Model\NotificationEventType;
use YooKassa\Model\NotificationType;
use YooKassa\Model\PaymentMethodType;
use YooKassa\Model\PaymentStatus;
use YooKassa\Model\Payout;
use YooKassa\Model\Payout\PayoutCancellationDetailsPartyCode;
use YooKassa\Model\Payout\PayoutCancellationDetailsReasonCode;
use YooKassa\Model\PayoutStatus;
use YooKassa\Model\ReceiptRegistrationStatus;
use YooKassa\Model\RefundStatus;
use YooKassa\Request\Deals\DealResponse;
use YooKassa\Request\Payments\PaymentResponse;
use YooKassa\Request\Payouts\PayoutResponse;
use YooKassa\Request\Refunds\RefundResponse;
class NotificationFactoryTest extends TestCase
@@ -74,6 +83,13 @@ class NotificationFactoryTest extends TestCase
case NotificationEventType::REFUND_SUCCEEDED:
$notification = $this->getRefundNotification();
break;
case NotificationEventType::DEAL_CLOSED:
$notification = $this->getDealNotification();
break;
case NotificationEventType::PAYOUT_SUCCEEDED:
case NotificationEventType::PAYOUT_CANCELED:
$notification = $this->getPayoutNotification($eventType);
break;
default:
$notification = $this->getPaymentNotification($eventType);
}
@@ -178,6 +194,83 @@ class NotificationFactoryTest extends TestCase
);
}
private function getPayoutNotification($type)
{
$cancellationDetailsParties = PayoutCancellationDetailsPartyCode::getValidValues();
$cancellationDetailsReasons = PayoutCancellationDetailsReasonCode::getValidValues();
$payoutDestinations = array(
PaymentMethodType::YOO_MONEY => array(
'type' => PaymentMethodType::YOO_MONEY,
'account_number' => Random::str(11, 33, '1234567890')
),
PaymentMethodType::BANK_CARD => array(
'type' => PaymentMethodType::BANK_CARD,
'card' => array(
'number' => Random::str(16, 18, '1234567890')
)
),
);
$payout = array(
'id' => Random::str(36, 50),
'status' => Random::value(PayoutStatus::getValidValues()),
'amount' => array('value' => Random::int(1, 10000), 'currency' => 'RUB'),
'description' => Random::str(1, Payout::MAX_LENGTH_DESCRIPTION),
'payout_destination' => $payoutDestinations[Random::value(array(PaymentMethodType::YOO_MONEY,PaymentMethodType::BANK_CARD))],
'created_at' => date(YOOKASSA_DATE, mt_rand(111111111, time())),
'test' => true,
'deal' => array('id' => Random::str(36, 50)),
'metadata' => array('order_id' => '37'),
'cancellation_details' => array(
'party' => Random::value($cancellationDetailsParties),
'reason' => Random::value($cancellationDetailsReasons)
),
);
return array(
array(
'type' => $this->getExpectedType(),
'event' => $type,
'object' => $payout,
),
);
}
private function getDealNotification()
{
$statuses = DealStatus::getValidValues();
$types = DealType::getValidValues();
$trueFalse = Random::bool();
$deal = array(
'id' => Random::str(36),
'type' => Random::value($types),
'status' => Random::value($statuses),
'description' => Random::str(128),
'balance' => array(
'value' => Random::float(0.01, 1000000.0),
'currency' => Random::value(CurrencyCode::getValidValues()),
),
'payout_balance' => array(
'value' => Random::float(0.01, 1000000.0),
'currency' => Random::value(CurrencyCode::getValidValues()),
),
'created_at' => date(YOOKASSA_DATE, Random::int(1, time())),
'expires_at' => date(YOOKASSA_DATE, Random::int(1, time())),
'fee_moment' => Random::value(FeeMoment::getEnabledValues()),
'test' => $trueFalse,
'metadata' => array(),
);
return array(
array(
'type' => $this->getExpectedType(),
'event' => NotificationEventType::DEAL_CLOSED,
'object' => $deal,
),
);
}
/**
* @return string
*/
@@ -195,6 +288,9 @@ class NotificationFactoryTest extends TestCase
return Random::value(NotificationEventType::getEnabledValues());
}
/**
* @throws \Exception
*/
private function assertObject($event, $object, $value)
{
self::assertNotNull($object);
@@ -209,6 +305,15 @@ class NotificationFactoryTest extends TestCase
self::assertTrue($object instanceof PaymentResponse);
self::assertEquals($object, new PaymentResponse($value));
break;
case NotificationEventType::PAYOUT_SUCCEEDED:
case NotificationEventType::PAYOUT_CANCELED:
self::assertTrue($object instanceof PayoutResponse);
self::assertEquals($object, new PayoutResponse($value));
break;
case NotificationEventType::DEAL_CLOSED:
self::assertTrue($object instanceof DealResponse);
self::assertEquals($object, new DealResponse($value));
break;
}
}