Skip to content

Commit

Permalink
feat: cria classe para os dados de pagamento
Browse files Browse the repository at this point in the history
  • Loading branch information
valdeir2000 committed Aug 18, 2020
1 parent 5ab803a commit b0c09e7
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 0 deletions.
226 changes: 226 additions & 0 deletions upload/system/library/PagSeguro/src/Domains/Payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
<?php

namespace ValdeirPsr\PagSeguro\Domains;

class Payment
{
/** @var string */
private $mode;

/** @var Sender */
private $sender;

/** @var string */
private $currency;

/** @var string */
private $notificationUrl;

/** @var CartItem[] */
private $items = [];

/** @var float */
private $extraAmount;

/** @var string */
private $reference;

/** @var Shipping */
private $shipping;

/**
* Define os modo
*
* @param string $value
*
* @return self
*/
public function setMode(string $value): self
{
$this->mode = $value;

return $this;
}

/**
* @return string
*/
public function getMode(): string
{
return $this->model;
}

/**
* Define os dados do comprador
*
* @param Sender $value
*
* @return self
*/
public function setSender(Sender $value): self
{
$this->sender = $value;

return $this;
}

/**
* @return Sender
*/
public function getSender(): Sender
{
return $this->sender;
}

/**
* Define a moeda de pagamento
*
* @param string $value
*
* @return self
*/
public function setCurrency(string $value): self
{
$this->currency = $value;

return $this;
}

/**
* @return string
*/
public function getCurrency(): string
{
return $this->currency;
}

/**
* Define a URL de notificação
*
* @param string $value
*
* @return self
*/
public function setNotificationUrl(string $value): self
{
$this->notificationUrl = $value;

return $this;
}

/**
* @return string
*/
public function getNotificationUrl(): string
{
return $this->notificationUrl;
}

/**
* Define os items comprados
*
* @param CartItem[] $values
*
* @return self
*/
public function setCartItems(array $values = []): self
{
$this->items = [];

foreach ($values as $value) {
$this->addCartItem($value);
}

return $this;
}

/**
* Adiciona um item aos itens comprados
*
* @param CartItem $value
*
* @return self
*/
public function addCartItem(CartItem $value): self
{
$this->items[] = $value;

return $this;
}

/**
* @return CartItem[]
*/
public function getCartItems(): array
{
return $this->items;
}

/**
* Define o valores extras:
* - valor positivo para acŕescimo;
* - valor negativo para desconto
*
* @param float $value
*
* @return self
*/
public function setExtraAmount(float $value): self
{
$this->extraAmount = $value;

return $this;
}

/**
* @return float
*/
public function getExtraAmount(): float
{
return $this->extraAmount;
}

/**
* Define referencia para o pedidos, como ID do pedido
*
* @param string $value
*
* @return self
*/
public function setReference(string $value): self
{
$this->reference = $value;

return $this;
}

/**
* @return string
*/
public function getReference(): string
{
return $this->reference;
}

/**
* Define os dados de entrega
*
* @param Shipping $value
*
* @return self
*/
public function setShipping(Shipping $value): self
{
$this->shipping = $value;

return $this;
}

/**
* @return Shipping
*/
public function getShipping(): Shipping
{
return $this->shipping;
}
}
16 changes: 16 additions & 0 deletions upload/system/library/PagSeguro/tests/unit/Domains/PaymentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use PHPUnit\Framework\TestCase;
use ValdeirPsr\PagSeguro\Domains\Payment;

class PaymentTest extends TestCase
{
/**
* @test
*/
public function newInstance()
{
$instance = new Payment();
$this->assertInstanceOf(Payment::class, $instance);
}
}

0 comments on commit b0c09e7

Please sign in to comment.