PayPlusLogicTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Http\logic\api\PayPlusLogic;
  4. use App\Services\PayPlus;
  5. use Tests\TestCase;
  6. class PayPlusLogicTest extends TestCase
  7. {
  8. /** @test */
  9. public function it_builds_payment_payload_with_configured_method_mapping()
  10. {
  11. $service = new PayPlus([
  12. 'currency' => 'USD',
  13. 'return' => 'https://example.com/return',
  14. 'payment_methods' => [
  15. 1 => 8,
  16. 2 => 2,
  17. ],
  18. ]);
  19. $logic = new PayPlusLogic($service);
  20. $payload = $logic->buildPaymentPayload([
  21. 'order_sn' => 'P100',
  22. 'amount' => 12.34,
  23. 'user_id' => 10001,
  24. 'user_email' => 'user@example.com',
  25. 'user_phone' => '1234567890',
  26. 'user_name' => 'Nico Smith',
  27. 'buy_ip' => '8.8.8.8',
  28. 'pay_method' => 2,
  29. ]);
  30. $this->assertSame('P100', $payload['platform_order_id']);
  31. $this->assertSame('RECHARGE', $payload['order_type']);
  32. $this->assertSame('12.34', $payload['amount']);
  33. $this->assertSame(2, $payload['payment_method']);
  34. $this->assertSame('10001', $payload['account_info']['merchant_user_id']);
  35. $this->assertSame('Nico', $payload['account_info']['first_name']);
  36. $this->assertSame('Smith', $payload['account_info']['last_name']);
  37. }
  38. /** @test */
  39. public function it_maps_successful_capture_only_as_paid()
  40. {
  41. $logic = new PayPlusLogic(new PayPlus([]));
  42. $this->assertTrue($logic->isSuccessfulPayment([
  43. 'event' => 'PAYMENT.CAPTURE.COMPLETED',
  44. 'event_detail_name' => 'payment_captured',
  45. 'data' => ['order_status' => 3],
  46. ]));
  47. $this->assertFalse($logic->isSuccessfulPayment([
  48. 'event' => 'PAYMENT.CAPTURE.COMPLETED',
  49. 'event_detail_name' => 'payment_declined',
  50. 'data' => ['order_status' => 4],
  51. ]));
  52. }
  53. }