Skip to content

Commit

Permalink
feat: test rest of api
Browse files Browse the repository at this point in the history
  • Loading branch information
kajetan-nobel committed Oct 3, 2023
1 parent 1107802 commit 1d976c7
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/DTO/Api/TransactionDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TransactionDto extends BaseDto
'billing' => BillingDto::class,
'shipping' => BillingDto::class,
'card' => CardDto::class,
'additionalData' => CardAdditionalDataDto::class,
// 'additionalData' => 'array' @todo
// 'multipayout' => 'array' @todo
// 'invoice' => 'array' @todo
];
Expand Down
6 changes: 3 additions & 3 deletions src/DTO/Responses/PaymentResponseDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Routegroup\Imoje\Payment\DTO\Casts\PaymentDto;
use Routegroup\Imoje\Payment\Factories\Api\PaymentDtoFactory;
use Routegroup\Imoje\Payment\Factories\Responses\PaymentResponseDtoFactory;

/**
* @property-read PaymentDto $payment
Expand All @@ -19,8 +19,8 @@ class PaymentResponseDto extends ResponseDto
'payment' => PaymentDto::class,
];

protected static function newFactory(): PaymentDtoFactory
protected static function newFactory(): PaymentResponseDtoFactory
{
return PaymentDtoFactory::new();
return PaymentResponseDtoFactory::new();
}
}
6 changes: 2 additions & 4 deletions src/Factories/Api/TransactionDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ class TransactionDtoFactory extends Factory
public function definition(): array
{
return [
'amount' => $this->faker->numberBetween(1, 100) * 100,
'amount' => $this->faker->numberBetween(1, 100000) * 100,
'currency' => Currency::PLN,
'orderId' => $this->faker->uuid,
'orderId' => $this->faker->unique()->uuid,
'paymentMethod' => PaymentMethod::PAY_BY_LINK,
'paymentMethodCode' => PaymentMethodCode::IPKO,
'successReturnUrl' => 'https://imoje.requestcatcher.com',
'failureReturnUrl' => 'https://imoje.requestcatcher.com',
'customer' => CustomerDto::factory(),
'billing' => BillingDto::factory(),
'shipping' => BillingDto::factory(),
// 'validTo' => '',
// 'title' => '',
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Factories/Casts/ActionDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function definition(): array
{
return [
'type' => ActionType::REDIRECT,
'url' => '',
'url' => "https://sandbox.paywall.imoje.pl/redirect/{$this->faker->uuid}/{$this->faker->uuid}",
'method' => 'GET',
'contentType' => '',
'contentBodyRaw' => '',
Expand Down
10 changes: 8 additions & 2 deletions src/Factories/Casts/CustomerDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ public function definition(): array
'firstName' => $this->faker->firstName,
'lastName' => $this->faker->lastName,
'email' => $this->faker->email,
'cid' => $this->faker->numerify('##############'),
'company' => $this->faker->company,
'phone' => $this->faker->numerify('#########'),
];
}

public function asCard(): static
{
return $this->state([
'cid' => $this->faker->numerify('##############'),
'company' => $this->faker->company,
]);
}
}
8 changes: 4 additions & 4 deletions src/Factories/Casts/PaymentDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public function definition(): array

return [
'id' => $this->faker->unique()->uuid,
'url' => '#',
'url' => "https://sandbox.paywall.imoje.pl/pay/{$this->faker->uuid}",
'serviceId' => config('services.imoje.service_key'),
'orderId' => $this->faker->unique()->uuid,
'title' => $this->faker->unique()->uuid,
'simp' => '',
'amount' => $this->faker->numberBetween(1, 1000) * 100,
'currency' => Currency::PLN,
'returnUrl' => '#',
'successReturnUrl' => '#',
'failureReturnUrl' => '#',
'returnUrl' => 'https://imoje.requestcatcher.com',
'successReturnUrl' => 'https://imoje.requestcatcher.com',
'failureReturnUrl' => 'https://imoje.requestcatcher.com',
'customer' => CustomerDto::factory(),
'isActive' => true,
'validTo' => null,
Expand Down
17 changes: 14 additions & 3 deletions src/Factories/Casts/TransactionDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ public function definition(): array
'created' => $now->timestamp,
'modified' => $now->timestamp,
'serviceId' => config('services.imoje.service_key'),
'amount' => $this->faker->numberBetween(1, 100) * 100,
'amount' => $this->faker->numberBetween(1, 1000) * 100,
'currency' => Currency::PLN,
'orderId' => $this->faker->unique()->uuid,
'paymentMethod' => $this->faker->randomElement(PaymentMethod::cases()),
'paymentMethodCode' => $this->faker->randomElement(PaymentMethodCode::cases()),
'paymentMethod' => PaymentMethod::PAY_BY_LINK,
'paymentMethodCode' => PaymentMethodCode::IPKO,
];
}

public function asApiPending(): static
{
return $this->state([
'type' => TransactionType::SALE,
'status' => TransactionStatus::PENDING,
'source' => TransactionSource::API,
'notificationUrl' => 'https://imoje.requestcatcher.com/',

]);
}

public function asOneClick(): static
{
return $this->state([
Expand Down
30 changes: 29 additions & 1 deletion src/Factories/Responses/CancelPaymentResponseDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,43 @@

namespace Routegroup\Imoje\Payment\Factories\Responses;

use Routegroup\Imoje\Payment\DTO\Casts\CustomerDto;
use Routegroup\Imoje\Payment\DTO\Responses\CancelPaymentResponseDto;
use Routegroup\Imoje\Payment\Factories\Factory;
use Routegroup\Imoje\Payment\Types\Currency;
use Routegroup\Imoje\Payment\Types\TransactionStatus;

class CancelPaymentResponseDtoFactory extends Factory
{
protected $model = CancelPaymentResponseDto::class;

public function definition(): array
{
return [];
$now = now();

return [
'id' => $this->faker->unique()->uuid,
'url' => "https://sandbox.paywall.imoje.pl/pay/{$this->faker->unique()->uuid}",
'serviceId' => config('services.imoje.service_key'),
'orderId' => $this->faker->unique()->uuid,
'title' => '',
'simp' => '',
'amount' => $this->faker->numberBetween(1, 1000) * 100,
'currency' => Currency::PLN,
'status' => TransactionStatus::CANCELLED,
'isActive' => true,
'validTo' => null,
'created' => $now->timestamp,
'modified' => $now->timestamp,
'isGenerated' => false,
'isUsed' => false,
'usedAt' => null,
'isConfirmVisited' => false,
'confirmVisitedAt' => null,
'returnUrl' => 'https://imoje.requestcatcher.com',
'failureReturnUrl' => 'https://imoje.requestcatcher.com',
'successReturnUrl' => 'https://imoje.requestcatcher.com',
'customer' => CustomerDto::factory(),
];
}
}
21 changes: 21 additions & 0 deletions src/Factories/Responses/PaymentResponseDtoFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Routegroup\Imoje\Payment\Factories\Responses;

use Routegroup\Imoje\Payment\DTO\Casts\PaymentDto;
use Routegroup\Imoje\Payment\DTO\Responses\PaymentResponseDto;
use Routegroup\Imoje\Payment\Factories\Factory;

class PaymentResponseDtoFactory extends Factory
{
protected $model = PaymentResponseDto::class;

public function definition(): array
{
return [
'payment' => PaymentDto::factory(),
];
}
}
2 changes: 1 addition & 1 deletion src/Factories/Responses/TransactionResponseDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TransactionResponseDtoFactory extends Factory
public function definition(): array
{
return [
'transaction' => TransactionDto::factory(),
'transaction' => TransactionDto::factory()->asApiPending(),
'action' => ActionDto::factory(),
];
}
Expand Down
27 changes: 27 additions & 0 deletions tests/Lib/ApiTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php

use Illuminate\Support\Facades\Http;
use Routegroup\Imoje\Payment\DTO\Api\CancelPaymentDto;
use Routegroup\Imoje\Payment\DTO\Api\ChargeProfileDto;
use Routegroup\Imoje\Payment\DTO\Api\PaymentDto;
use Routegroup\Imoje\Payment\DTO\Api\RefundDto;
use Routegroup\Imoje\Payment\DTO\Api\TransactionDto;
use Routegroup\Imoje\Payment\DTO\Responses\CancelPaymentResponseDto;
use Routegroup\Imoje\Payment\DTO\Responses\ChargeProfileResponseDto;
use Routegroup\Imoje\Payment\DTO\Responses\PaymentResponseDto;
use Routegroup\Imoje\Payment\DTO\Responses\ProfileResponseDto;
use Routegroup\Imoje\Payment\DTO\Responses\RefundResponseDto;
use Routegroup\Imoje\Payment\DTO\Responses\TransactionResponseDto;
use Routegroup\Imoje\Payment\Lib\Api;

beforeEach(function (): void {
Expand All @@ -21,6 +27,27 @@
$response = $mockRequest($this->api);
expect($response)->toBeInstanceOf($instance);
})->with([
'successfully calls create transaction' => [
fn (Api $api) => [
$api->url->createTransactionUrl() => Http::response(TransactionResponseDto::factory()->make()->toArray()),
],
fn (Api $api) => $api->createTransaction(TransactionDto::factory()->make()),
TransactionResponseDto::class,
],
'successfully calls create payment' => [
fn (Api $api) => [
$api->url->createPaymentUrl() => Http::response(PaymentResponseDto::factory()->make()->toArray()),
],
fn (Api $api) => $api->createPayment(PaymentDto::factory()->make()),
PaymentResponseDto::class,
],
'successfully calls cancel payment' => [
fn (Api $api) => [
$api->url->createCancelPaymentUrl() => Http::response(CancelPaymentResponseDto::factory()->make()->toArray()),
],
fn (Api $api) => $api->cancelPayment(CancelPaymentDto::factory()->make()),
CancelPaymentResponseDto::class,
],
'successfully calls refund' => [
fn (Api $api) => [
$api->url->createRefundUrl('$transaction_id$') => Http::response(RefundResponseDto::factory()->make()->toArray()),
Expand Down

0 comments on commit 1d976c7

Please sign in to comment.