├── .codeclimate.yml
├── .gitignore
├── .travis.yml
├── README.md
├── composer.json
├── example
├── _prevent-access.php
├── _sandbox-credentials.php
├── cellphone-charger-checkout.php
├── create-plan.php
├── gamer-checkout.php
├── http-request.php
├── simple-checkout.php
└── travel-checkout.php
├── phpunit.xml
├── src
└── laravel
│ └── pagseguro
│ ├── Address
│ ├── Address.php
│ ├── AddressInterface.php
│ └── ValidationRules.php
│ ├── Checkout
│ ├── AbstractCheckout.php
│ ├── CellphoneChargerCheckout.php
│ ├── CheckoutInterface.php
│ ├── Facade
│ │ ├── CheckoutFacade.php
│ │ ├── DataFacade.php
│ │ └── TravelFacade.php
│ ├── GamerCheckout.php
│ ├── HasInfoTrait.php
│ ├── Information
│ │ ├── Information.php
│ │ └── InformationFactory.php
│ ├── Metadata
│ │ ├── CellphoneCharger
│ │ │ ├── CellphoneChargerInterface.php
│ │ │ └── Exporter.php
│ │ ├── Gamer
│ │ │ ├── Exporter.php
│ │ │ ├── GameInfo.php
│ │ │ └── GamerInterface.php
│ │ ├── HasMetadataInterface.php
│ │ ├── InfoInterface.php
│ │ ├── Item.php
│ │ ├── ItemGroup.php
│ │ ├── MetadataCollection.php
│ │ ├── TagableInterface.php
│ │ └── Travel
│ │ │ ├── Exporter.php
│ │ │ ├── Passenger.php
│ │ │ ├── PassengerCollection.php
│ │ │ ├── Place.php
│ │ │ ├── TravelInfo.php
│ │ │ └── TravelInterface.php
│ ├── SimpleCheckout.php
│ ├── Statement
│ │ ├── StatementInterface.php
│ │ └── Xml
│ │ │ ├── Xml.php
│ │ │ ├── XmlConfig.php
│ │ │ ├── XmlItems.php
│ │ │ ├── XmlMetadata.php
│ │ │ ├── XmlPartInterface.php
│ │ │ ├── XmlSender.php
│ │ │ └── XmlShipping.php
│ ├── TravelCheckout.php
│ └── ValidationRules.php
│ ├── Complements
│ ├── DataHydratorTrait
│ │ ├── DataHydratorConstructorTrait.php
│ │ ├── DataHydratorProtectedTrait.php
│ │ └── DataHydratorTrait.php
│ ├── Filter
│ │ └── MoneyFilter.php
│ ├── ValidateTrait.php
│ ├── ValidationRulesInterface.php
│ └── ValidationRulesTrait.php
│ ├── Config
│ ├── Config.php
│ └── application-config.php
│ ├── Credentials
│ ├── Credentials.php
│ └── CredentialsInterface.php
│ ├── Document
│ ├── CNPJ
│ │ ├── CNPJ.php
│ │ └── ValidationRules.php
│ ├── CPF
│ │ ├── CPF.php
│ │ └── ValidationRules.php
│ ├── DocumentCollection.php
│ ├── DocumentInterface.php
│ └── Passport
│ │ ├── Passport.php
│ │ └── ValidationRules.php
│ ├── Facades
│ ├── Checkout.php
│ ├── Credentials.php
│ ├── Item.php
│ ├── PagSeguro.php
│ ├── Plan.php
│ └── Transaction.php
│ ├── Http
│ ├── Request
│ │ ├── Adapter
│ │ │ ├── AdapterInterface.php
│ │ │ └── CurlAdapter.php
│ │ ├── Request.php
│ │ └── RequestInterface.php
│ └── Response
│ │ ├── Response.php
│ │ └── ResponseInterface.php
│ ├── Information
│ ├── InformationAbstract.php
│ └── InformationAbstractFactory.php
│ ├── Item
│ ├── Item.php
│ ├── ItemCollection.php
│ ├── ItemInterface.php
│ └── ValidationRules.php
│ ├── Notification
│ ├── Notification.php
│ ├── NotificationInterface.php
│ └── ValidationRules.php
│ ├── Parser
│ ├── ParserInterface.php
│ └── Xml.php
│ ├── Payment
│ └── Method
│ │ ├── Billet
│ │ ├── Billet.php
│ │ └── BilletInterface.php
│ │ ├── CreditCard
│ │ ├── CreditCard.php
│ │ └── CreditCardInterface.php
│ │ ├── DepositAccount
│ │ ├── DepositAccount.php
│ │ └── DepositAccountInterface.php
│ │ ├── Extras
│ │ ├── Extras.php
│ │ └── ExtrasInterface.php
│ │ ├── MethodAbstract.php
│ │ ├── MethodFactory.php
│ │ ├── MethodInterface.php
│ │ ├── Pix
│ │ ├── Pix.php
│ │ └── PixInterface.php
│ │ └── Transfer
│ │ ├── Transfer.php
│ │ └── TransferInterface.php
│ ├── Phone
│ ├── Phone.php
│ ├── PhoneInterface.php
│ └── ValidationRules.php
│ ├── Plans
│ ├── AbstractPlans.php
│ ├── Facade
│ │ └── DataFacade.php
│ ├── Plans.php
│ ├── PlansInterface.php
│ ├── PreApproval
│ │ ├── Expiration
│ │ │ ├── Expiration.php
│ │ │ ├── ExpirationInterface.php
│ │ │ └── ValidationRules.php
│ │ ├── PreApproval.php
│ │ ├── PreApprovalInterface.php
│ │ └── ValidationRules.php
│ └── ValidationRules.php
│ ├── Platform
│ ├── Laravel5.php
│ ├── Laravel5
│ │ ├── NotificationController.php
│ │ ├── PagSeguro.php
│ │ └── ServiceProvider.php
│ ├── Native.php
│ └── PlatformInterface.php
│ ├── Receiver
│ ├── Receiver.php
│ ├── ReceiverInterface.php
│ └── ValidationRules.php
│ ├── Remote
│ ├── Checkout.php
│ ├── ConsumerAbstract.php
│ ├── Manager.php
│ ├── Notification.php
│ ├── Plans.php
│ ├── Transaction.php
│ └── Url
│ │ └── Resolver.php
│ ├── Sender
│ ├── Sender.php
│ ├── SenderInterface.php
│ └── ValidationRules.php
│ ├── Shipping
│ ├── Shipping.php
│ ├── ShippingInterface.php
│ └── ValidationRules.php
│ └── Transaction
│ ├── Information
│ ├── Amounts.php
│ ├── Information.php
│ ├── InformationFactory.php
│ └── InformationNormalizer.php
│ ├── Status
│ ├── Status.php
│ └── StatusInterface.php
│ ├── Transaction.php
│ └── TransactionInterface.php
└── tests
├── .gitkeep
└── unit
├── Address
├── AddressTest.php
├── BaseValidationRules.php
├── PrimaryInfoTest.php
└── TerritoryInfoTest.php
├── Checkout
├── CheckoutBase.php
└── SimpleCheckoutTest.php
├── Credentials
└── CredentialsTest.php
├── Document
├── CNPJ
│ ├── CNPJTest.php
│ └── ValidationRulesTest.php
├── CPF
│ ├── CPFTest.php
│ └── ValidationRulesTest.php
└── DocumentCollectionTest.php
├── Item
├── ItemCollectionTest.php
├── ItemTest.php
└── ValidationRulesTest.php
├── Notification
├── NotificationTest.php
└── ValidationRulesTest.php
├── Parser
└── XmlTest.php
├── Payment
└── Method
│ └── FactoryTest.php
├── Phone
├── PhoneTest.php
└── ValidationRulesTest.php
├── Sender
├── SenderTest.php
└── ValidationRulesTest.php
├── Shipping
├── ShippingTest.php
└── ValidationRulesTest.php
├── Transaction
├── Information
│ ├── InformationTest.php
│ └── simple-response.xml
├── StatusTest.php
└── TransactionTest.php
├── ValidationRules.php
└── bootstrap.php
/.codeclimate.yml:
--------------------------------------------------------------------------------
1 | languages:
2 | PHP: true
3 | exclude_paths:
4 | - "example/*"
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | bin
3 | coverage
4 | composer.phar
5 | composer.lock
6 | .DS_Store
7 | ../.idea/
8 | .idea
9 | example/testeInLaravel
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | sudo: required
4 |
5 | php:
6 | - 5.6
7 | - 7.0
8 | - 7.1
9 |
10 | before_script:
11 | - travis_retry composer self-update
12 | - travis_retry composer install --prefer-source --no-interaction
13 |
14 | script: bin/phpunit
15 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "michael/laravel-pagseguro",
3 | "description": "Biblioteca de integração com o gateway de pagamento PagSeguro.",
4 | "keywords": ["framework", "laravel", "Gateway Pagamento", "PagSeguro"],
5 | "license": "MIT",
6 | "type": "library",
7 | "require": {
8 | "php": ">=5.4.0",
9 | "ext-curl": "*",
10 | "lib-curl": "*",
11 | "lib-openssl": "*",
12 | "lib-libxml": "*",
13 | "illuminate/validation": ">=4.2"
14 | },
15 | "require-dev": {
16 | "phpunit/phpunit": "^4.8.35"
17 | },
18 | "autoload": {
19 | "psr-0":{
20 | "laravel\\pagseguro\\": "src/"
21 | }
22 | },
23 | "authors": [
24 | {
25 | "name": "Michael Douglas Barbosa Araujo",
26 | "email": "michaeldouglas010790@gmail.com"
27 | },
28 | {
29 | "name": "Isaque de Souza Barbosa",
30 | "email": "isaquesb@gmail.com"
31 | },
32 | {
33 | "name": "Allan Wiese",
34 | "email": "allanwiese@gmail.com"
35 | }
36 | ],
37 | "scripts": {
38 | "test:unit": "phpunit -c phpunit.xml tests/unit --coverage-html=./tests/phpunit"
39 | },
40 | "config":{
41 | "bin-dir": "bin/"
42 | },
43 | "extra": {
44 | "laravel": {
45 | "providers": [
46 | "laravel\\pagseguro\\Platform\\Laravel5\\ServiceProvider"
47 | ],
48 | "aliases": {
49 | "PagSeguro": "laravel\\pagseguro\\Platform\\Laravel5\\PagSeguro"
50 | }
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/example/_prevent-access.php:
--------------------------------------------------------------------------------
1 | '',
5 | 'key' => ''
6 | ];
7 |
8 | if (empty($credentials['email']) || empty($credentials['key'])) {
9 | die('Informe as credenciais da SANDBOX em :' . basename(__FILE__));
10 | }
11 |
12 | return $credentials;
--------------------------------------------------------------------------------
/example/cellphone-charger-checkout.php:
--------------------------------------------------------------------------------
1 | [
23 | [
24 | 'id' => 20,
25 | 'description' => 'Recarga de Celular',
26 | 'quantity' => 1,
27 | 'amount' => 21
28 | ]
29 | ],
30 | 'sender' => [
31 | 'email' => $senderEmail,
32 | 'name' => 'Isaque de Souza Barbosa',
33 | 'documents' => [
34 | [
35 | 'number' => '40404040411',
36 | 'type' => 'CPF'
37 | ]
38 | ],
39 | 'phone' => [
40 | 'number' => '985445522',
41 | 'areaCode' => '11',
42 | ],
43 | 'bornDate' => '1988-03-21',
44 | ],
45 | 'currency' => 'BRL',
46 | 'cellphone_charger' => '+5511980840022'
47 | ];
48 |
49 | try {
50 | Config::set('use-sandbox', true);
51 | $facade = new CheckoutFacade();
52 | $credentials = new Credentials($credentialKey, $credentialEmail);
53 | $checkout = $facade->createFromArray($data);
54 | $information = $checkout->send($credentials);
55 | printf('
%s
', print_r($information, 1));
56 | printf('Clique para pagar', $information->getLink());
57 | } catch (\Exception $e) {
58 | printf('%s
', print_r((string)$e, 1));
59 | }
60 |
--------------------------------------------------------------------------------
/example/create-plan.php:
--------------------------------------------------------------------------------
1 | [
24 | 'reference' => 'plano laravel pagseguro',
25 | ],
26 |
27 |
28 | 'preApproval' => [
29 | 'name' => 'Plano ouro - mensal',
30 | 'charge' => 'AUTO', // outro valor pode ser MANUAL
31 | 'period' => 'MONTHLY', //WEEKLY, BIMONTHLY, TRIMONTHLY, SEMIANNUALLY, YEARLY
32 | 'amountPerPayment' => '125.00', // obrigatório para o charge AUTO - mais que 1.00, menos que 2000.00
33 | 'membershipFee' => '50.00', //opcional - cobrado com primeira parcela
34 | 'trialPeriodDuration' => 30, //opcional
35 | 'details' => 'Decrição do plano', //opcional
36 | ]
37 |
38 | ];
39 |
40 | try {
41 | Config::set('use-sandbox', true);
42 | $facade = new Plan();
43 | $credentials = new Credentials($credentialKey, $credentialEmail);
44 | $plan = $facade->createFromArray($plan);
45 | $information = $plan->send($credentials);
46 | printf('%s
', print_r($information, 1));
47 | printf('Clique para pagar', $information->getLink());
48 |
49 | } catch (\Exception $e) {
50 | printf('%s
', print_r((string)$e, 1));
51 | }
52 |
--------------------------------------------------------------------------------
/example/gamer-checkout.php:
--------------------------------------------------------------------------------
1 | [
23 | [
24 | 'id' => 20,
25 | 'description' => 'Game CASH',
26 | 'quantity' => 1,
27 | 'amount' => 15.6,
28 | 'shippingCost' => 0,
29 | ]
30 | ],
31 | 'sender' => [
32 | 'email' => $senderEmail,
33 | 'name' => 'Isaque de Souza Barbosa',
34 | 'documents' => [
35 | [
36 | 'number' => '40404040411',
37 | 'type' => 'CPF'
38 | ]
39 | ],
40 | 'phone' => [
41 | 'number' => '985445522',
42 | 'areaCode' => '11',
43 | ],
44 | 'bornDate' => '1988-03-21',
45 | ],
46 | 'currency' => 'BRL',
47 | 'game' => [
48 | 'gameName' => 'PS LEGEND',
49 | 'playerId' => 'BR561546S4',
50 | 'timeInGameDays' => 360,
51 | ]
52 | ];
53 |
54 | try {
55 | Config::set('use-sandbox', true);
56 | $facade = new CheckoutFacade();
57 | $credentials = new Credentials($credentialKey, $credentialEmail);
58 | $checkout = $facade->createFromArray($data);
59 | $information = $checkout->send($credentials);
60 | printf('%s
', print_r($information, 1));
61 | printf('Clique para pagar', $information->getLink());
62 | } catch (\Exception $e) {
63 | printf('%s
', print_r((string)$e, 1));
64 | }
65 |
--------------------------------------------------------------------------------
/example/http-request.php:
--------------------------------------------------------------------------------
1 | CURL_HTTP_VERSION_1_0
11 | ]);
12 | $request = new Request($adapter);
13 | $response = $request->get('https://ws.sandbox.pagseguro.uol.com.br/');
14 | if (!$response) {
15 | echo 'Fail';
16 | } else {
17 | echo $response->getRawBody();//OK
18 | }
19 |
--------------------------------------------------------------------------------
/example/simple-checkout.php:
--------------------------------------------------------------------------------
1 | [
23 | [
24 | 'id' => 18,
25 | 'description' => 'Laravel PS Simple Checkout',
26 | 'quantity' => 1,
27 | 'shippingCost' => 3.5,
28 | 'width' => 50,
29 | 'weight' => 45,
30 | 'height' => 45,
31 | 'length' => 60,
32 | 'amount' => 1.15,
33 | ]
34 | ],
35 | 'shipping' => [
36 | 'address' => [
37 | 'postalCode' => '06410030',
38 | 'street' => 'Rua da Selva',
39 | 'number' => '12',
40 | 'district' => 'Jardim dos Camargos',
41 | 'city' => 'Barueri',
42 | 'state' => 'SP',
43 | 'country' => 'BRA',
44 | ],
45 | 'type' => 2,
46 | 'cost' => 30.4,
47 | ],
48 | 'sender' => [
49 | 'email' => $senderEmail,
50 | 'name' => 'Isaque de Souza Barbosa',
51 | 'documents' => [
52 | [
53 | 'number' => '80808080822',
54 | 'type' => 'CPF'
55 | ]
56 | ],
57 | 'phone' => [
58 | 'number' => '985445522',
59 | 'areaCode' => '11'
60 | ],
61 | 'bornDate' => '1988-03-25',
62 | ]
63 | ];
64 |
65 | try {
66 | Config::set('use-sandbox', true);
67 | $facade = new CheckoutFacade();
68 | $credentials = new Credentials($credentialKey, $credentialEmail);
69 | $checkout = $facade->createFromArray($data);
70 | $information = $checkout->send($credentials);
71 | printf('%s
', print_r($information, 1));
72 | printf('Clique para pagar', $information->getLink());
73 | } catch (\Exception $e) {
74 | printf('%s
', print_r((string)$e, 1));
75 | }
76 |
--------------------------------------------------------------------------------
/example/travel-checkout.php:
--------------------------------------------------------------------------------
1 | [
23 | [
24 | 'id' => 20,
25 | 'description' => 'Passagem para BAHIA',
26 | 'quantity' => 2,
27 | 'amount' => 15.6
28 | ]
29 | ],
30 | 'sender' => [
31 | 'email' => $senderEmail,
32 | 'name' => 'Isaque de Souza Barbosa',
33 | 'documents' => [
34 | [
35 | 'number' => '40404040411',
36 | 'type' => 'CPF'
37 | ]
38 | ],
39 | 'phone' => [
40 | 'number' => '985445522',
41 | 'areaCode' => '11',
42 | ],
43 | 'bornDate' => '1988-03-21',
44 | ],
45 | 'currency' => 'BRL',
46 | 'travel' => [
47 | 'passengers' => [
48 | [
49 | 'name' => 'Isaque de Souza',
50 | 'cpf' => '40404040411',
51 | 'passport' => '4564897987'
52 | ],
53 | [
54 | 'name' => 'Vivian Pereira',
55 | 'cpf' => '80808080822',
56 | ]
57 | ],
58 | 'origin' => [
59 | 'city' => 'SAO PAULO - SP',
60 | 'airportCode' => 'CGH', //https://pt.wikipedia.org/wiki/C%C3%B3digos_IATA_de_aeroportos_brasileiros
61 | ],
62 | 'destination' => [
63 | 'city' => 'SALVADOR - BA',
64 | 'airportCode' => 'SSA',
65 | ]
66 | ]
67 | ];
68 |
69 | try {
70 | Config::set('use-sandbox', true);
71 | $facade = new CheckoutFacade();
72 | $credentials = new Credentials($credentialKey, $credentialEmail);
73 | $checkout = $facade->createFromArray($data);
74 | $information = $checkout->send($credentials);
75 | printf('%s
', print_r($information, 1));
76 | printf('Clique para pagar', $information->getLink());
77 | } catch (\Exception $e) {
78 | printf('%s
', print_r((string)$e, 1));
79 | }
80 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | ./tests/
16 |
17 |
18 |
19 |
20 | ./vendor
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Address/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-01-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'postalCode' => 'Required|numeric|digits:8',
27 | 'street' => 'Required|max:80',
28 | 'number' => 'Required|max:20',
29 | 'complement' => 'max:40',
30 | 'district' => 'Required|max:60',
31 | 'city' => 'Required|min:2|max:60',
32 | 'state' => 'Required|max:2',
33 | 'country' => 'Required|Max:3|in:BRA',
34 | ];
35 |
36 | /**
37 | * @var array
38 | */
39 | protected $messages;
40 |
41 | use ValidationRulesTrait;
42 | }
43 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/CellphoneChargerCheckout.php:
--------------------------------------------------------------------------------
1 |
17 | * @since 2016-01-12
18 | *
19 | * @copyright Laravel\PagSeguro
20 | */
21 | class CellphoneChargerCheckout extends SimpleCheckout implements CellphoneChargerInterface
22 | {
23 |
24 | /**
25 | * @var PhoneInterface
26 | */
27 | protected $phone;
28 |
29 | /**
30 | * @return PhoneInterface
31 | */
32 | public function getPhone()
33 | {
34 | return $this->phone;
35 | }
36 |
37 | /**
38 | * @param PhoneInterface $phone
39 | * @return CellphoneChargerCheckout
40 | */
41 | public function setPhone(PhoneInterface $phone)
42 | {
43 | $this->phone = $phone;
44 | return $this;
45 | }
46 |
47 | /**
48 | * @return MetadataCollection
49 | */
50 | public function getMetadata()
51 | {
52 | $exporter = new Exporter($this);
53 | $this->metadata = $exporter->getMetadata();
54 | return parent::getMetadata();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/CheckoutInterface.php:
--------------------------------------------------------------------------------
1 |
18 | * @since 2016-01-12
19 | *
20 | * @copyright Laravel\PagSeguro
21 | */
22 | interface CheckoutInterface
23 | {
24 | /**
25 | * Constructor
26 | * @param array $data Checkout data
27 | */
28 | public function __construct($data = []);
29 |
30 | /**
31 | * @return string
32 | */
33 | public function getCharset();
34 |
35 | /**
36 | * @return string
37 | */
38 | public function getCurrency();
39 |
40 | /**
41 | * @return float
42 | */
43 | public function getExtraAmount();
44 |
45 | /**
46 | * @return ItemCollection
47 | */
48 | public function getItems();
49 |
50 | /**
51 | * @return float
52 | */
53 | public function getMaxUses();
54 |
55 | /**
56 | * @return float
57 | */
58 | public function getMaxAge();
59 |
60 | /**
61 | * @return MetadataCollection
62 | */
63 | public function getMetadata();
64 |
65 | /**
66 | * @return string
67 | */
68 | public function getNotificationURL();
69 |
70 | /**
71 | * @return ReceiverInterface
72 | */
73 | public function getReceiver();
74 |
75 | /**
76 | * @return string
77 | */
78 | public function getRedirectURL();
79 |
80 | /**
81 | * @return string
82 | */
83 | public function getReference();
84 |
85 | /**
86 | * @return SenderInterface
87 | */
88 | public function getSender();
89 |
90 | /**
91 | * @return ShippingInterface
92 | */
93 | public function getShipping();
94 |
95 | /**
96 | * Send Checkout
97 | * @param CredentialsInterface $credentials
98 | * @return array
99 | */
100 | public function send(CredentialsInterface $credentials);
101 | }
102 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/GamerCheckout.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class GamerCheckout extends SimpleCheckout
17 | {
18 |
19 | use HasInfoTrait;
20 | }
21 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/HasInfoTrait.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2016-03-09
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | trait HasInfoTrait
19 | {
20 |
21 | /**
22 | * @var InfoInterface
23 | */
24 | protected $info;
25 |
26 | /**
27 | * @return InfoInterface
28 | */
29 | public function getInfo()
30 | {
31 | return $this->info;
32 | }
33 |
34 | /**
35 | * @param InfoInterface $info
36 | */
37 | public function setInfo(InfoInterface $info)
38 | {
39 | $this->info = $info;
40 | }
41 |
42 | /**
43 | * @return Metadata\MetadataCollection
44 | */
45 | public function getMetadata()
46 | {
47 | $info = $this->getInfo();
48 | if (!is_null($info)) {
49 | $exporterClass = preg_replace(
50 | '/(.*)\\\(.*)Checkout$/',
51 | '$1\Metadata\\\$2\Exporter',
52 | __CLASS__
53 | );
54 | $exporter = new $exporterClass($info);
55 | $this->metadata = $exporter->getMetadata();
56 | }
57 | return parent::getMetadata();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Information/Information.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2016-01-10
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class Information extends InformationAbstract
19 | {
20 |
21 | /**
22 | * Transaction Code
23 | * @var string
24 | */
25 | protected $code;
26 |
27 | /**
28 | * Date
29 | * @var \DateTime
30 | */
31 | protected $date;
32 |
33 | /**
34 | * Link
35 | * @var string
36 | */
37 | protected $link;
38 |
39 | /**
40 | * Transaction Code
41 | * @param string $code
42 | * @throws \InvalidArgumentException
43 | */
44 | protected function setCode($code)
45 | {
46 | if (!\is_string($code)) {
47 | throw new \InvalidArgumentException('Invalid transaction code');
48 | }
49 | $this->code = $code;
50 | }
51 |
52 | /**
53 | * Get Code
54 | * @return string
55 | */
56 | public function getCode()
57 | {
58 | return $this->code;
59 | }
60 |
61 | /**
62 | * Get Date
63 | * @return \DateTime
64 | */
65 | public function getDate()
66 | {
67 | return $this->date;
68 | }
69 |
70 | /**
71 | * @param \DateTime $date
72 | * @return Information
73 | */
74 | protected function setDate(\DateTime $date)
75 | {
76 | $this->date = $date;
77 | return $this;
78 | }
79 |
80 | /**
81 | * Get Link
82 | * @return string
83 | */
84 | public function getLink()
85 | {
86 | return $this->link;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Information/InformationFactory.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-12-10
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class InformationFactory extends InformationAbstractFactory
19 | {
20 |
21 | /**
22 | * @return Information
23 | */
24 | public function getInformation()
25 | {
26 | $map = array_fill_keys([
27 | 'code',
28 | 'link',
29 | ], null);
30 | $data = array_intersect_key($this->data, $map);
31 | $data['date'] = $this->getDate();
32 | return new Information($data);
33 | }
34 |
35 | /**
36 | * Get Date
37 | * @return \DateTimeInterface
38 | */
39 | public function getDate()
40 | {
41 | return $this->getDateTimeObject($this->data['date']);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/CellphoneCharger/CellphoneChargerInterface.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2016-01-12
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | interface CellphoneChargerInterface
20 | {
21 |
22 | /**
23 | * @return PhoneInterface
24 | */
25 | public function getPhone();
26 |
27 | /**
28 | * @param PhoneInterface $phone
29 | * @return CheckoutInterface
30 | */
31 | public function setPhone(PhoneInterface $phone);
32 | }
33 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/CellphoneCharger/Exporter.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 2016-01-12
17 | *
18 | * @copyright Laravel\PagSeguro
19 | */
20 | class Exporter implements HasMetadataInterface
21 | {
22 |
23 | /**
24 | * @var CellphoneChargerInterface
25 | */
26 | protected $exportable;
27 |
28 | /**
29 | * MetadataExport constructor.
30 | * @param CellphoneChargerInterface $exportable
31 | */
32 | public function __construct(CellphoneChargerInterface $exportable)
33 | {
34 | $this->exportable = $exportable;
35 | }
36 |
37 | /**
38 | * @return MetadataCollection
39 | */
40 | public function getMetadata()
41 | {
42 | $phone = $this->exportable->getPhone();
43 | if (!$phone) {
44 | return null;
45 | }
46 | $phoneNumber = implode('', [
47 | $phone->getCountryCode(),
48 | $phone->getAreaCode(),
49 | $phone->getNumber(),
50 | ]);
51 | $item = new Item(Item::KEY_MOBILE_NUMBER, $phoneNumber);
52 | return new MetadataCollection([$item]);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/Gamer/Exporter.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 2016-01-12
17 | *
18 | * @copyright Laravel\PagSeguro
19 | */
20 | class Exporter implements HasMetadataInterface
21 | {
22 |
23 | /**
24 | * @var GamerInterface
25 | */
26 | protected $exportable;
27 |
28 | /**
29 | * MetadataExport constructor.
30 | * @param GamerInterface $exportable
31 | */
32 | public function __construct(GamerInterface $exportable)
33 | {
34 | $this->exportable = $exportable;
35 | }
36 |
37 | /**
38 | * @return MetadataCollection
39 | */
40 | public function getMetadata()
41 | {
42 | $metadataCollection = new MetadataCollection([]);
43 | $this->appendGameName($metadataCollection);
44 | $this->appendPlayerId($metadataCollection);
45 | $this->appendTimeInGame($metadataCollection);
46 | if (!$metadataCollection->count()) {
47 | return null;
48 | }
49 | return $metadataCollection;
50 | }
51 |
52 | /**
53 | * @param MetadataCollection $metadataCollection
54 | * @return void
55 | */
56 | private function appendGameName(MetadataCollection $metadataCollection)
57 | {
58 | $gameName = $this->exportable->getGameName();
59 | if ($gameName) {
60 | $item = new Item(Item::KEY_GAME_NAME, $gameName);
61 | $metadataCollection->append($item);
62 | }
63 | }
64 |
65 | /**
66 | * @param MetadataCollection $metadataCollection
67 | * @return void
68 | */
69 | private function appendPlayerId(MetadataCollection $metadataCollection)
70 | {
71 | $playerId = $this->exportable->getPlayerId();
72 | if ($playerId) {
73 | $item = new Item(Item::KEY_PLAYER_ID, $playerId);
74 | $metadataCollection->append($item);
75 | }
76 | }
77 |
78 | /**
79 | * @param MetadataCollection $metadataCollection
80 | * @return void
81 | */
82 | private function appendTimeInGame(MetadataCollection $metadataCollection)
83 | {
84 | $timeInGameDays = $this->exportable->getTimeInGameDays();
85 | if ($timeInGameDays) {
86 | $item = new Item(Item::KEY_TIME_IN_GAME_DAYS, $timeInGameDays);
87 | $metadataCollection->append($item);
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/Gamer/GameInfo.php:
--------------------------------------------------------------------------------
1 |
17 | * @since 2016-01-12
18 | *
19 | * @copyright Laravel\PagSeguro
20 | */
21 | class GameInfo implements GamerInterface, InfoInterface
22 | {
23 |
24 | /**
25 | * @var string
26 | */
27 | protected $gameName;
28 |
29 | /**
30 | * @var string
31 | */
32 | protected $playerId;
33 |
34 | /**
35 | * @var int
36 | */
37 | protected $timeInGameDays;
38 |
39 | use DataHydratorTrait, DataHydratorProtectedTrait, DataHydratorConstructorTrait {
40 | DataHydratorProtectedTrait::hydrate insteadof DataHydratorTrait;
41 | }
42 |
43 | /**
44 | * Constructor
45 | * @param array|string $data Game Info Data
46 | */
47 | public function __construct($data = [])
48 | {
49 | $args = func_get_args();
50 | $data = null;
51 | $this->hydrateMagic(
52 | ['gameName', 'playerId', 'timeInGameDays'],
53 | $args
54 | );
55 | }
56 |
57 | /**
58 | * @return int
59 | */
60 | public function getTimeInGameDays()
61 | {
62 | return $this->timeInGameDays;
63 | }
64 |
65 | /**
66 | * @param int $timeInGameDays
67 | * @return GameInfo
68 | */
69 | protected function setTimeInGameDays($timeInGameDays)
70 | {
71 | $this->timeInGameDays = $timeInGameDays;
72 | return $this;
73 | }
74 |
75 | /**
76 | * @return string
77 | */
78 | public function getGameName()
79 | {
80 | return $this->gameName;
81 | }
82 |
83 | /**
84 | * @param string $gameName
85 | * @return GameInfo
86 | */
87 | protected function setGameName($gameName)
88 | {
89 | $this->gameName = $gameName;
90 | return $this;
91 | }
92 |
93 | /**
94 | * @return string
95 | */
96 | public function getPlayerId()
97 | {
98 | return $this->playerId;
99 | }
100 |
101 | /**
102 | * @param string $playerId
103 | * @return GameInfo
104 | */
105 | protected function setPlayerId($playerId)
106 | {
107 | $this->playerId = $playerId;
108 | return $this;
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/Gamer/GamerInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface GamerInterface
17 | {
18 |
19 | /**
20 | * @return string
21 | */
22 | public function getGameName();
23 |
24 | /**
25 | * @return string
26 | */
27 | public function getPlayerId();
28 |
29 | /**
30 | * @return int
31 | */
32 | public function getTimeInGameDays();
33 | }
34 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/HasMetadataInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface HasMetadataInterface
17 | {
18 | /**
19 | * @return MetadataCollection
20 | */
21 | public function getMetadata();
22 | }
23 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/InfoInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-03-09
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface InfoInterface
17 | {
18 | /**
19 | * InfoInterface constructor.
20 | * @param array $data
21 | */
22 | public function __construct($data = []);
23 | }
24 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/ItemGroup.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class ItemGroup extends Item
17 | {
18 | /**
19 | * @var array
20 | */
21 | protected $value = [];
22 |
23 | /**
24 | * @param string $key
25 | */
26 | protected function setKey($key)
27 | {
28 | if (null !== $key) {
29 | throw new \InvalidArgumentException('Group can\'t have key');
30 | }
31 | }
32 |
33 | /**
34 | * @param string $value
35 | */
36 | protected function setValue($value)
37 | {
38 | if (!($value instanceof MetadataCollection)) {
39 | throw new \InvalidArgumentException('Invalid metadata collection');
40 | }
41 | $this->value = $value;
42 | }
43 |
44 | /**
45 | * @return string
46 | */
47 | public function toXmlTag()
48 | {
49 | $str = <<
51 | %s
52 | %s
53 |
54 | XML;
55 | $tag = <<
57 | %s
58 |
59 | XML;
60 | $groups = [];
61 | foreach ($this->getValue() as $item) {
62 | $groups[] = sprintf($str, $item->getKey(), $item->getValue());
63 | }
64 | return sprintf($tag, implode('', $groups));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/MetadataCollection.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class MetadataCollection extends \ArrayObject
17 | {
18 | /**
19 | * Appends the value
20 | * @param TagableInterface $value
21 | * The value being appended.
22 | *
23 | * @return void
24 | */
25 | public function append($value)
26 | {
27 | if (!($value instanceof TagableInterface)) {
28 | throw new \InvalidArgumentException('Invalid tagable object');
29 | }
30 | parent::append($value);
31 | }
32 |
33 | /**
34 | * Sets the value at the specified index to newval
35 | * @param mixed $index
36 | * The index being set.
37 | *
38 | * @param TagableInterface $newval
39 | * The new value for the index.
40 | *
41 | * @return void
42 | */
43 | public function offsetSet($index, $newval)
44 | {
45 | if (!($newval instanceof TagableInterface)) {
46 | throw new \InvalidArgumentException('Invalid tagable object');
47 | }
48 | parent::offsetSet($index, $newval);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/TagableInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface TagableInterface
17 | {
18 | /**
19 | * @return string
20 | */
21 | public function getKey();
22 |
23 | /**
24 | * @return string
25 | */
26 | public function getValue();
27 |
28 | /**
29 | * @return string
30 | */
31 | public function toXmlTag();
32 | }
33 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/Travel/Passenger.php:
--------------------------------------------------------------------------------
1 |
18 | * @since 2016-01-12
19 | *
20 | * @copyright Laravel\PagSeguro
21 | */
22 | class Passenger
23 | {
24 |
25 | /**
26 | * @var string
27 | */
28 | protected $name;
29 |
30 | /**
31 | * @var CPF
32 | */
33 | protected $cpf;
34 |
35 | /**
36 | * @var Passport
37 | */
38 | protected $passport;
39 |
40 | use DataHydratorTrait, DataHydratorProtectedTrait, DataHydratorConstructorTrait {
41 | DataHydratorProtectedTrait::hydrate insteadof DataHydratorTrait;
42 | }
43 |
44 | /**
45 | * Constructor
46 | * @param array|string $data Passenger data
47 | */
48 | public function __construct($data = [])
49 | {
50 | $args = func_get_args();
51 | $data = null;
52 | $this->hydrateMagic(
53 | ['name', 'cpf', 'passport'],
54 | $args
55 | );
56 | }
57 |
58 | /**
59 | * @return string
60 | */
61 | public function getName()
62 | {
63 | return $this->name;
64 | }
65 |
66 | /**
67 | * @param string $name
68 | * @return Passenger
69 | */
70 | protected function setName($name)
71 | {
72 | $this->name = $name;
73 | return $this;
74 | }
75 |
76 | /**
77 | * @return Passport
78 | */
79 | public function getPassport()
80 | {
81 | return $this->passport;
82 | }
83 |
84 | /**
85 | * @param Passport $passport
86 | * @return Passenger
87 | */
88 | protected function setPassport($passport)
89 | {
90 | $this->passport = $passport;
91 | return $this;
92 | }
93 |
94 | /**
95 | * @return CPF
96 | */
97 | public function getCpf()
98 | {
99 | return $this->cpf;
100 | }
101 |
102 | /**
103 | * @param CPF $cpf
104 | * @return Passenger
105 | */
106 | protected function setCpf($cpf)
107 | {
108 | $this->cpf = $cpf;
109 | return $this;
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/Travel/PassengerCollection.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class PassengerCollection extends \ArrayObject
17 | {
18 | /**
19 | * Appends the value
20 | * @param TagableInterface $value
21 | * The value being appended.
22 | *
23 | * @return void
24 | */
25 | public function append($value)
26 | {
27 | if (!($value instanceof Passenger)) {
28 | throw new \InvalidArgumentException('Invalid passenger object');
29 | }
30 | parent::append($value);
31 | }
32 |
33 | /**
34 | * Sets the value at the specified index to newval
35 | * @param mixed $index
36 | * The index being set.
37 | *
38 | * @param TagableInterface $newval
39 | * The new value for the index.
40 | *
41 | * @return void
42 | */
43 | public function offsetSet($index, $newval)
44 | {
45 | if (!($newval instanceof Passenger)) {
46 | throw new \InvalidArgumentException('Invalid passenger object');
47 | }
48 | parent::offsetSet($index, $newval);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/Travel/Place.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 2016-01-12
17 | *
18 | * @copyright Laravel\PagSeguro
19 | */
20 | class Place
21 | {
22 |
23 | /**
24 | * @var string
25 | */
26 | protected $airportCode;
27 |
28 | /**
29 | * @var string
30 | */
31 | protected $city;
32 |
33 | use DataHydratorTrait, DataHydratorProtectedTrait, DataHydratorConstructorTrait {
34 | DataHydratorProtectedTrait::hydrate insteadof DataHydratorTrait;
35 | }
36 |
37 | /**
38 | * Constructor
39 | * @param array|string $data Place data
40 | */
41 | public function __construct($data = [])
42 | {
43 | $args = func_get_args();
44 | $data = null;
45 | $this->hydrateMagic(
46 | ['city', 'airportCode'],
47 | $args
48 | );
49 | }
50 |
51 | /**
52 | * @return string
53 | */
54 | public function getAirportCode()
55 | {
56 | return $this->airportCode;
57 | }
58 |
59 | /**
60 | * @param string $airportCode
61 | * @return Place
62 | */
63 | protected function setAirportCode($airportCode)
64 | {
65 | $this->airportCode = $airportCode;
66 | return $this;
67 | }
68 |
69 | /**
70 | * @return string
71 | */
72 | public function getCity()
73 | {
74 | return $this->city;
75 | }
76 |
77 | /**
78 | * @param string $city
79 | * @return Place
80 | */
81 | protected function setCity($city)
82 | {
83 | $this->city = $city;
84 | return $this;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/Travel/TravelInfo.php:
--------------------------------------------------------------------------------
1 |
17 | * @since 2016-01-12
18 | *
19 | * @copyright Laravel\PagSeguro
20 | */
21 | class TravelInfo implements TravelInterface, InfoInterface
22 | {
23 |
24 | /**
25 | * @var Place
26 | */
27 | protected $destination;
28 |
29 | /**
30 | * @var Place
31 | */
32 | protected $origin;
33 |
34 | /**
35 | * @var PassengerCollection
36 | */
37 | protected $passengers;
38 |
39 | use DataHydratorTrait, DataHydratorProtectedTrait, DataHydratorConstructorTrait {
40 | DataHydratorProtectedTrait::hydrate insteadof DataHydratorTrait;
41 | }
42 |
43 | /**
44 | * Constructor
45 | * @param array|string $data Travel Info Data
46 | */
47 | public function __construct($data = [])
48 | {
49 | $args = func_get_args();
50 | $data = null;
51 | $this->hydrateMagic(
52 | ['passengers', 'origin', 'destination'],
53 | $args
54 | );
55 | }
56 |
57 | /**
58 | * @return Place
59 | */
60 | public function getDestination()
61 | {
62 | return $this->destination;
63 | }
64 |
65 | /**
66 | * @param Place $place
67 | * @return TravelInterface
68 | */
69 | public function setDestination(Place $place)
70 | {
71 | $this->destination = $place;
72 | }
73 |
74 | /**
75 | * @return Place
76 | */
77 | public function getOrigin()
78 | {
79 | return $this->origin;
80 | }
81 |
82 | /**
83 | * @param Place $place
84 | * @return TravelInterface
85 | */
86 | public function setOrigin(Place $place)
87 | {
88 | $this->origin = $place;
89 | }
90 |
91 | /**
92 | * @return PassengerCollection
93 | */
94 | public function getPassengers()
95 | {
96 | return $this->passengers;
97 | }
98 |
99 | /**
100 | * @param PassengerCollection $passengers
101 | * @return TravelInterface
102 | */
103 | public function setPassengers(PassengerCollection $passengers)
104 | {
105 | $this->passengers = $passengers;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Metadata/Travel/TravelInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface TravelInterface
17 | {
18 | /**
19 | * @return Place
20 | */
21 | public function getDestination();
22 |
23 | /**
24 | * @param Place $place
25 | * @return TravelInterface
26 | */
27 | public function setDestination(Place $place);
28 |
29 | /**
30 | * @return Place
31 | */
32 | public function getOrigin();
33 |
34 | /**
35 | * @param Place $place
36 | * @return TravelInterface
37 | */
38 | public function setOrigin(Place $place);
39 |
40 | /**
41 | * @return PassengerCollection
42 | */
43 | public function getPassengers();
44 |
45 | /**
46 | * @param PassengerCollection $passengers
47 | * @return TravelInterface
48 | */
49 | public function setPassengers(PassengerCollection $passengers);
50 | }
51 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Statement/StatementInterface.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2016-01-12
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | interface StatementInterface
20 | {
21 |
22 | /**
23 | * Constructor
24 | * @param CheckoutInterface $checkout
25 | */
26 | public function __construct(CheckoutInterface $checkout);
27 |
28 | /**
29 | * @param RequestInterface $request
30 | * @return void
31 | */
32 | public function prepare(RequestInterface $request);
33 | }
34 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Statement/Xml/XmlConfig.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2016-01-12
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class XmlConfig implements XmlPartInterface
19 | {
20 | /**
21 | * @var CheckoutInterface
22 | */
23 | protected $checkout;
24 |
25 | /**
26 | * Constructor
27 | * @param CheckoutInterface $checkout
28 | */
29 | public function __construct(CheckoutInterface $checkout)
30 | {
31 | $this->checkout = $checkout;
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | public function getXmlString()
38 | {
39 | return
40 | $this->getExtraAmountXmlString() .
41 | $this->getRedirectURLXmlString() .
42 | $this->getNotificationURLXmlString() .
43 | $this->getMaxUsesXmlString() .
44 | $this->getMaxAgeXmlString();
45 | }
46 |
47 | /**
48 | * @param string $key
49 | * @param string $value
50 | * @return null|string
51 | */
52 | private function optionalValue($key, $value)
53 | {
54 | if (is_null($value)) {
55 | return null;
56 | }
57 | $str = '<%1$s>%2$s%1$s>';
58 | return sprintf($str, $key, $value);
59 | }
60 |
61 | /**
62 | * @return string XML
63 | */
64 | private function getExtraAmountXmlString()
65 | {
66 | $value = $this->checkout->getExtraAmount();
67 | return $this->optionalValue('extraAmount', $value);
68 | }
69 |
70 | /**
71 | * @return string XML
72 | */
73 | private function getRedirectURLXmlString()
74 | {
75 | $value = $this->checkout->getRedirectURL();
76 | return $this->optionalValue('redirectURL', $value);
77 | }
78 |
79 | /**
80 | * @return string XML
81 | */
82 | private function getNotificationURLXmlString()
83 | {
84 | $value = $this->checkout->getNotificationURL();
85 | return $this->optionalValue('notificationURL', $value);
86 | }
87 |
88 | /**
89 | * @return string XML
90 | */
91 | private function getMaxUsesXmlString()
92 | {
93 | $value = $this->checkout->getMaxUses();
94 | return $this->optionalValue('maxUses', $value);
95 | }
96 |
97 | /**
98 | * @return string XML
99 | */
100 | private function getMaxAgeXmlString()
101 | {
102 | $value = $this->checkout->getMaxAge();
103 | return $this->optionalValue('maxAge', $value);
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Statement/Xml/XmlMetadata.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2016-01-12
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class XmlMetadata implements XmlPartInterface
19 | {
20 | /**
21 | * @var MetadataCollection
22 | */
23 | protected $metadata;
24 |
25 | /**
26 | * Constructor
27 | * @param MetadataCollection $metadata
28 | */
29 | public function __construct($metadata = null)
30 | {
31 | if (!empty($metadata)) {
32 | if (!($metadata instanceof MetadataCollection)) {
33 | throw new \InvalidArgumentException('Invalid metadata');
34 | }
35 | $this->metadata = $metadata;
36 | }
37 | }
38 |
39 | /**
40 | * @return string
41 | */
42 | public function getXmlString()
43 | {
44 | if (is_null($this->metadata)) {
45 | return null;
46 | }
47 | $strCollection = [];
48 | foreach ($this->metadata as $tagable) {
49 | $strCollection[] = $tagable->toXmlTag();
50 | }
51 | $str = <<
53 | %s
54 |
55 | XML;
56 | return sprintf($str, implode('', $strCollection));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/Statement/Xml/XmlPartInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface XmlPartInterface
17 | {
18 | /**
19 | * @return string
20 | */
21 | public function getXmlString();
22 | }
23 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/TravelCheckout.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class TravelCheckout extends SimpleCheckout
17 | {
18 |
19 | use HasInfoTrait;
20 | }
21 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Checkout/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2016-01-12
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'currency' => 'Required|in:BRL',
27 | 'extraAmount' => 'Numeric',
28 | 'items' => 'Required',
29 | 'sender' => 'Required',
30 | 'shipping' => 'Required',
31 | 'notificationURL' => 'Url',
32 | 'redirectURL' => 'Url',
33 | 'reference' => 'String',
34 | 'maxAge' => 'Integer',
35 | 'maxUses' => 'Integer',
36 | 'metadata' => 'Array',
37 | ];
38 |
39 | /**
40 | * @var array
41 | */
42 | protected $messages;
43 |
44 | use ValidationRulesTrait;
45 | }
46 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Complements/DataHydratorTrait/DataHydratorConstructorTrait.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | trait DataHydratorConstructorTrait
17 | {
18 | /**
19 | * Hydrate Constructor
20 | * @param array $keys
21 | * @param array $args
22 | */
23 | protected function hydrateMagic(array $keys, array $args)
24 | {
25 | $argNum = count($args);
26 | $first = current($args);
27 | $assoc = is_array($first) && 1 === $argNum && !is_numeric(key($first));
28 | $data = [];
29 | if (!$assoc && count($args) === count($keys)) {
30 | $data = array_combine($keys, $args);
31 | } elseif (!$assoc) {
32 | foreach ($args as $keyNum => $value) {
33 | $key = $keys[$keyNum];
34 | $data[$key] = $value;
35 | }
36 | } else {
37 | $data = $first;
38 | }
39 | if (count($data)) {
40 | $this->hydrate($data);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Complements/DataHydratorTrait/DataHydratorProtectedTrait.php:
--------------------------------------------------------------------------------
1 |
13 | * @since 2015-12-10
14 | *
15 | * @copyright Laravel\PagSeguro
16 | */
17 | trait DataHydratorProtectedTrait
18 | {
19 |
20 | /**
21 | * Proxies Data Hydrate
22 | * @param array $data
23 | * @return object
24 | */
25 | protected function hydrate(array $data = [])
26 | {
27 | return $this->doHydrate($data);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Complements/DataHydratorTrait/DataHydratorTrait.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-01-08
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | trait DataHydratorTrait
17 | {
18 |
19 | /**
20 | * Proxies Data Hydrate
21 | * @param array $data
22 | * @return object
23 | */
24 | public function hydrate(array $data = [])
25 | {
26 | return $this->doHydrate($data);
27 | }
28 |
29 | /**
30 | * Proxies Data Hydrate
31 | * @param array $data
32 | * @return object
33 | */
34 | protected function doHydrate(array $data = [])
35 | {
36 | $rules = $this->getHidratableVars();
37 | $defaultData = array_fill_keys(array_keys($rules), null);
38 | $currentData = $this->toArray();
39 | $testData = array_merge(
40 | $defaultData,
41 | $currentData,
42 | array_intersect_key($data, $defaultData)
43 | );
44 | $this->bindHydrate($testData);
45 | return $this;
46 | }
47 |
48 | /**
49 | * Data Hydrate
50 | * @param array $data
51 | * @return void
52 | */
53 | protected function bindHydrate(array $data = [])
54 | {
55 | $itr = new \ArrayIterator($data);
56 | while ($itr->valid()) {
57 | $key = $itr->key();
58 | $value = $itr->current();
59 | $method = 'set' . ucfirst($key);
60 | if (method_exists($this, $method)) {
61 | $this->{$method}($value);
62 | } else {
63 | $this->{$key} = $value;
64 | }
65 | $itr->next();
66 | }
67 | }
68 |
69 | /**
70 | * Get Hidratable Vars
71 | * @return array
72 | */
73 | protected function getHidratableVars()
74 | {
75 | return get_object_vars($this);
76 | }
77 |
78 | /**
79 | * Cast Array
80 | * @return array
81 | */
82 | public function toArray()
83 | {
84 | $cast = [];
85 | $rulesKeys = array_keys($this->getHidratableVars());
86 | $it = new \ArrayIterator($rulesKeys);
87 | while ($it->valid()) {
88 | $key = $it->current();
89 | $method = 'get' . ucfirst($key);
90 | if (method_exists($this, $method)) {
91 | $value = $this->{$method}();
92 | } else {
93 | $value = $this->{$key};
94 | }
95 | $cast[$key] = $value;
96 | $it->next();
97 | }
98 | return $cast;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Complements/Filter/MoneyFilter.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class MoneyFilter
17 | {
18 |
19 | /**
20 | * @param float $value
21 | * @return string|float
22 | */
23 | public function filter($value)
24 | {
25 | if (empty($value)) {
26 | return null;
27 | }
28 | if (!is_numeric($value)) {
29 | throw new \InvalidArgumentException('Invalid numeric type');
30 | }
31 | return number_format($value, 2, '.', '');
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Complements/ValidateTrait.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-01-08
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | trait ValidateTrait
19 | {
20 |
21 | /**
22 | * @var \Illuminate\Validation\Validator
23 | */
24 | protected $validator;
25 |
26 | /**
27 | * Get Hidratable Vars
28 | * @return array
29 | */
30 | protected function getHidratableVars()
31 | {
32 | return $this->getValidationRules()->getRules();
33 | }
34 |
35 | /**
36 | * @return ValidationRulesInterface
37 | */
38 | public abstract function getValidationRules();
39 |
40 | /**
41 | * Test Valid Data
42 | * @return bool
43 | */
44 | public function isValid()
45 | {
46 | $vRules = $this->getValidationRules();
47 | $rules = $vRules->getRules();
48 | $messages = $vRules->getMessages();
49 | $currentData = $this->export();
50 | $this->validator = Validator::make($currentData, $rules, $messages);
51 | return $this->validator->passes();
52 | }
53 |
54 | /**
55 | * Get Validator
56 | * Return only after hydrate
57 | * @return null|\Illuminate\Validation\Validator
58 | */
59 | public function getValidator()
60 | {
61 | return $this->validator;
62 | }
63 |
64 | /**
65 | * Cast Array
66 | * @return array
67 | */
68 | public function export()
69 | {
70 | if (method_exists($this, 'toArray')) {
71 | return $this->toArray();
72 | }
73 | $data = [];
74 | foreach (get_object_vars($this) as $key) {
75 | $data[$key] = $this->__get($key);
76 | }
77 | return $data;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Complements/ValidationRulesInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-01-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface ValidationRulesInterface
17 | {
18 |
19 | /**
20 | * Get Rules Keys
21 | * @return array
22 | */
23 | public function getKeys();
24 |
25 | /**
26 | * Get Rules
27 | * @return array
28 | */
29 | public function getRules();
30 |
31 | /**
32 | * Get Messages
33 | * @return array
34 | */
35 | public function getMessages();
36 |
37 | /**
38 | * Set Messages
39 | * @param array $messages
40 | * @return array
41 | */
42 | public function setMessages(array $messages);
43 | }
44 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Complements/ValidationRulesTrait.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-01-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | trait ValidationRulesTrait
17 | {
18 |
19 | /**
20 | * Get Rules Keys
21 | * @return array
22 | */
23 | public function getKeys()
24 | {
25 | return array_keys($this->rules);
26 | }
27 |
28 | /**
29 | * Get Rules
30 | * @return array
31 | */
32 | public function getRules()
33 | {
34 | return $this->rules;
35 | }
36 |
37 | /**
38 | * Get Validate Messages
39 | * @return array
40 | */
41 | public function getMessages()
42 | {
43 | return $this->messages;
44 | }
45 |
46 | /**
47 | * Set Validate Messages
48 | * @param array $messages
49 | * @return object
50 | */
51 | public function setMessages(array $messages)
52 | {
53 | $this->messages = $messages;
54 | return $this;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Config/Config.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-10-28
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class Config
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected static $data;
26 |
27 | /**
28 | * @var PlatformInterface
29 | */
30 | protected static $platform;
31 |
32 | /**
33 | * @param string $key
34 | * @param mixed $default
35 | * @return mixed
36 | */
37 | public static function get($key, $default = null)
38 | {
39 | $platform = self::getPlatform();
40 | if (!preg_match('/[a-z-]/', $key)) {
41 | throw new \InvalidArgumentException('Invalid config key:' . $key);
42 | }
43 | $data = static::$data;
44 | if ($platform->hasPersonalConfig()) {
45 | $data = $platform->getConfigByKey('laravelpagseguro');
46 | }
47 | if (is_null($data)) {
48 | $data = include(__DIR__ . '/application-config.php');
49 | static::$data = $data;
50 | }
51 | return array_key_exists($key, $data) ? $data[$key] : $default;
52 | }
53 |
54 | /**
55 | * @param string $key
56 | * @param mixed $value
57 | * @return mixed
58 | */
59 | public static function set($key, $value)
60 | {
61 | $platform = self::getPlatform();
62 | $default = static::get($key);
63 | if ($default != $value) {
64 | static::$data[$key] = $value;
65 | if ($platform->hasPersonalConfig()) {
66 | $key = implode('.', (array) $key);
67 | \Config::set('laravelpagseguro.' . $key, $value);
68 | }
69 | }
70 | }
71 |
72 | /**
73 | * @return PlatformInterface
74 | */
75 | public static function getPlatform()
76 | {
77 | if (is_null(self::$platform)) {
78 | self::usePlatform(new Native());
79 | }
80 | return self::$platform;
81 | }
82 |
83 | /**
84 | * @param PlatformInterface $platformObject
85 | */
86 | public static function usePlatform(PlatformInterface $platformObject)
87 | {
88 | self::$platform = $platformObject;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Config/application-config.php:
--------------------------------------------------------------------------------
1 | false,
6 |
7 | /*
8 | * Coloque abaixo as informações do seu cadastro no PagSeguro
9 | */
10 | 'credentials' => [//INFORME AS CREDENCIAIS PADRÕES DE SUA LOJA, MAS PORDERÁ SER ALTERADA EM RUNTIME
11 | 'email' => null,
12 | 'token' => null,
13 | ],
14 |
15 | /*
16 | * Informe abaixo o nome / url das rotas de aplicação para notificações
17 | * e redirecionamento após pagamento
18 | * Parâmetro: "route-name" para nome de rota laravel ou "fixed" para url fixa (URL completa)
19 | * Ex. 01: "route-name" => "tela-de-obrigado" (Nome de Rota)
20 | * Ex. 02: "fixed" => "http://minhaloja.com.br/pagamento/tela-de-obrigado" (URL Fixa)
21 | *
22 | * PARA MAIS INFORMAÇÕES VIDE:
23 | * https://sandbox.pagseguro.uol.com.br/vendedor/configuracoes.html
24 | */
25 | 'routes' => [
26 | 'redirect' => [
27 | 'route-name' => 'pagseguro.redirect', // Criar uma rota com este nome
28 | ],
29 | 'notification' => [
30 | 'callback' => null, // Callable callback to Notification function (notificationInfo) : void {}
31 | 'credential' => 'default', // Callable resolve credential function (notificationCode) : Credentials {}
32 | 'route-name' => 'pagseguro.notification', // Criar uma rota com este nome
33 | ],
34 | ],
35 |
36 | /*
37 | * MOEDA QUE SERÁ UTILIZADA COMO MEIO DE PAGAMENTO
38 | * Somente BRL é aceito no momento (Real do Brasil)
39 | * */
40 | 'currency' => [
41 | 'type' => 'BRL'
42 | ],
43 |
44 | /**
45 | * Adaptador de Requisições
46 | */
47 | 'http' => [
48 | 'adapter' => [
49 | 'type' => 'curl',
50 | 'options' => [
51 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
52 | //CURLOPT_PROXY => 'http://user:pass@host:port', // PROXY OPTION
53 | ]
54 | ],
55 | ],
56 |
57 | /*
58 | * ATENÇÃO: Não altere as configurações abaixo
59 | * */
60 | 'host' => [
61 | 'production' => 'https://ws.pagseguro.uol.com.br',
62 | 'sandbox' => 'https://ws.sandbox.pagseguro.uol.com.br'
63 | ],
64 | 'url' => [
65 | 'checkout' => '/v2/checkout',
66 | 'transactions' => '/v3/transactions',
67 | 'transactions-notifications' => '/v3/transactions/notifications',
68 | 'transactions-history' => '/v2/transactions',
69 | 'transactions-abandoned' => '/v2/transactions/abandoned',
70 | 'pre-approvals' => '/pre-approvals/request'
71 | ],
72 | ];
73 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Credentials/Credentials.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-01-02
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class Credentials implements CredentialsInterface
17 | {
18 |
19 | const ERROR_INVALID_TOKEN = 'Invalid credential token';
20 | const ERROR_INVALID_EMAIL = 'Invalid credential email';
21 |
22 | /**
23 | * @var string
24 | */
25 | private $email;
26 |
27 | /**
28 | * @var string
29 | */
30 | private $token;
31 |
32 | /**
33 | * Constructor
34 | * @param string $token PagSeguro Token
35 | * @param string $email PagSeguro Account E-mail
36 | * @throws \InvalidArgumentException
37 | */
38 | public function __construct($token, $email)
39 | {
40 | if (!$this->tokenIsValid($token)) {
41 | throw new \InvalidArgumentException(self::ERROR_INVALID_TOKEN);
42 | }
43 | if (!$this->emailIsValid($email)) {
44 | throw new \InvalidArgumentException(self::ERROR_INVALID_EMAIL);
45 | }
46 | $this->token = $token;
47 | $this->email = $email;
48 | }
49 |
50 | /**
51 | * Is a Valid Credential
52 | * @return bool
53 | */
54 | public function isValid()
55 | {
56 | $validEmail = $this->emailIsValid($this->email);
57 | $validToken = $this->tokenIsValid($this->token);
58 | return $validEmail && $validToken;
59 | }
60 |
61 | /**
62 | * Valid e-mail test
63 | * @param string $email E-mail address
64 | * @return bool
65 | */
66 | protected function emailIsValid($email)
67 | {
68 | return !is_null($email) && filter_var($email, FILTER_VALIDATE_EMAIL);
69 | }
70 |
71 | /**
72 | * Valid token syntax test
73 | * @param string $token Token
74 | * @return bool
75 | */
76 | protected function tokenIsValid($token)
77 | {
78 | return !is_null($token) && is_string($token) && !empty($token);
79 | }
80 |
81 | /**
82 | * Get Token
83 | * @return string
84 | */
85 | public function getToken()
86 | {
87 | return $this->token;
88 | }
89 |
90 | /**
91 | * Return Account Email Address
92 | * @return string
93 | */
94 | public function getEmail()
95 | {
96 | return $this->email;
97 | }
98 |
99 | /**
100 | * Return array credential
101 | * @return string
102 | */
103 | public function toArray()
104 | {
105 | return ['email' => $this->email, 'token' => $this->token];
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Credentials/CredentialsInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since : 02/01/2015
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface CredentialsInterface
17 | {
18 |
19 | /**
20 | * Constructor
21 | * @param string $token PagSeguro Token
22 | * @param string $email PagSeguro Account E-mail
23 | * @throws \InvalidArgumentException
24 | */
25 | public function __construct($token, $email);
26 |
27 | /**
28 | * Is a Valid Credential
29 | * @return bool
30 | */
31 | public function isValid();
32 |
33 | /**
34 | * Get Token
35 | * @return string
36 | */
37 | public function getToken();
38 |
39 | /**
40 | * Return Account Email Address
41 | * @return string
42 | */
43 | public function getEmail();
44 | }
45 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Document/CNPJ/CNPJ.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 2018-01-12
17 | *
18 | * @copyright Laravel\PagSeguro
19 | */
20 | class CNPJ implements DocumentInterface
21 | {
22 |
23 | /**
24 | * Number
25 | * @var string
26 | */
27 | private $number;
28 |
29 | /**
30 | * Type
31 | * @var string
32 | */
33 | private $type = 'CNPJ';
34 |
35 | use DataHydratorTrait,
36 | ValidateTrait {
37 | ValidateTrait::getHidratableVars insteadof DataHydratorTrait;
38 | }
39 |
40 | /**
41 | * Constructor
42 | * @param array $data
43 | */
44 | public function __construct(array $data = [])
45 | {
46 | if (count($data)) {
47 | $this->hydrate($data);
48 | }
49 | }
50 |
51 | /**
52 | * Get Number
53 | * @return string
54 | */
55 | public function getNumber()
56 | {
57 | return $this->number;
58 | }
59 |
60 | /**
61 | * Get Type
62 | * @return string
63 | */
64 | public function getType()
65 | {
66 | return $this->type;
67 | }
68 |
69 | /**
70 | * Set Number
71 | * @param string $number
72 | * @return Cnpj
73 | */
74 | public function setNumber($number)
75 | {
76 | $filterNum = preg_replace('/[^0-9]/', '', $number);
77 | $padNum = str_pad($filterNum, 11, '0', STR_PAD_LEFT);
78 | $this->number = $padNum;
79 | return $this;
80 | }
81 |
82 | /**
83 | * Set Type
84 | * @param string $type
85 | * @return Cnpj
86 | */
87 | protected function setType($type)
88 | {
89 | if ($type !== 'CNPJ') { // Restrict to Hydrate
90 | throw new \InvalidArgumentException('Invalid CNPJ Type');
91 | }
92 | return $this;
93 | }
94 |
95 | /**
96 | * Get Validation Rules
97 | * @return ValidationRules
98 | */
99 | public function getValidationRules()
100 | {
101 | return new ValidationRules();
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Document/CNPJ/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2018-01-12
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'number' => 'Required|numeric|digits:14',
27 | ];
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $messages;
33 |
34 | use ValidationRulesTrait;
35 | }
36 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Document/CPF/CPF.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 2015-01-11
17 | *
18 | * @copyright Laravel\PagSeguro
19 | */
20 | class CPF implements DocumentInterface
21 | {
22 |
23 | /**
24 | * Number
25 | * @var string
26 | */
27 | private $number;
28 |
29 | /**
30 | * Type
31 | * @var string
32 | */
33 | private $type = 'CPF';
34 |
35 | use DataHydratorTrait,
36 | ValidateTrait {
37 | ValidateTrait::getHidratableVars insteadof DataHydratorTrait;
38 | }
39 |
40 | /**
41 | * Constructor
42 | * @param array $data
43 | */
44 | public function __construct(array $data = [])
45 | {
46 | if (count($data)) {
47 | $this->hydrate($data);
48 | }
49 | }
50 |
51 | /**
52 | * Get Number
53 | * @return string
54 | */
55 | public function getNumber()
56 | {
57 | return $this->number;
58 | }
59 |
60 | /**
61 | * Get Type
62 | * @return string
63 | */
64 | public function getType()
65 | {
66 | return $this->type;
67 | }
68 |
69 | /**
70 | * Set Number
71 | * @param string $number
72 | * @return Cpf
73 | */
74 | public function setNumber($number)
75 | {
76 | $filterNum = preg_replace('/[^0-9]/', '', $number);
77 | $padNum = str_pad($filterNum, 11, '0', STR_PAD_LEFT);
78 | $this->number = $padNum;
79 | return $this;
80 | }
81 |
82 | /**
83 | * Set Type
84 | * @param string $type
85 | * @return Cpf
86 | */
87 | protected function setType($type)
88 | {
89 | if ($type !== 'CPF') { // Restrict to Hydrate
90 | throw new \InvalidArgumentException('Invalid CPF Type');
91 | }
92 | return $this;
93 | }
94 |
95 | /**
96 | * Get Validation Rules
97 | * @return ValidationRules
98 | */
99 | public function getValidationRules()
100 | {
101 | return new ValidationRules();
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Document/CPF/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-01-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'number' => 'Required|numeric|digits:11',
27 | ];
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $messages;
33 |
34 | use ValidationRulesTrait;
35 | }
36 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Document/DocumentCollection.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-01-11
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class DocumentCollection extends \ArrayObject
20 | {
21 |
22 | /**
23 | * Factory ItemCollection (Cria coleção de itens)
24 | * @param array $data Items
25 | * @return DocumentCollection
26 | * @throws \InvalidArgumentException
27 | */
28 | public static function factory(array $data = [])
29 | {
30 | $collectionItems = [];
31 | $itr = new \ArrayIterator($data);
32 | while ($itr->valid()) {
33 | $item = $itr->current();
34 | if ($item instanceof DocumentInterface) {
35 | $collectionItems[] = $item;
36 | } elseif (is_array($item)) {
37 | $collectionItems[] = self::documentFactory($item);
38 | } else {
39 | $exptMsg = sprintf('Invalid document on key: %s', $itr->key());
40 | throw new \InvalidArgumentException($exptMsg);
41 | }
42 | $itr->next();
43 | }
44 | return new self($collectionItems);
45 | }
46 |
47 | /**
48 | * Factory Document
49 | * CPF and CNPJ are the unique suported documents
50 | * @param array $data
51 | * @return DocumentInterface
52 | * @throws \InvalidArgumentException
53 | */
54 | public static function documentFactory(array $data)
55 | {
56 | if (!array_key_exists('type', $data)
57 | || !array_key_exists('number', $data)
58 | || empty($data['type'])
59 | || empty($data['number'])
60 | ) {
61 | throw new \InvalidArgumentException('Invalid document data');
62 | }
63 |
64 | if($data['type'] == 'CPF'){
65 | self::unsetType($data);
66 | return new CPF($data);
67 | }elseif($data['type'] == 'CNPJ'){
68 | self::unsetType($data);
69 | return new CNPJ($data);
70 | }else{
71 | throw new \InvalidArgumentException('Invalid document type');
72 | }
73 | }
74 |
75 | /**
76 | * Unset the type
77 | * @param array $data
78 | * @return void
79 | */
80 | private static function unsetType(array $data)
81 | {
82 | unset($data['type']);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Document/DocumentInterface.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-01-11
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | interface DocumentInterface
19 | {
20 |
21 | /**
22 | * Get Number
23 | * @return string
24 | */
25 | public function getNumber();
26 |
27 | /**
28 | * Get Type
29 | * @return string
30 | */
31 | public function getType();
32 |
33 | /**
34 | * Set Number
35 | * @param string $number
36 | * @return Cpf
37 | */
38 | public function setNumber($number);
39 |
40 | /**
41 | * Proxies Data Hydrate
42 | * @param array $data
43 | * @return object
44 | */
45 | public function hydrate(array $data = []);
46 |
47 | /**
48 | * Test Valid Data
49 | * @return bool
50 | */
51 | public function isValid();
52 |
53 | /**
54 | * Get Validator
55 | * Return only after hydrate
56 | * @return null|\Illuminate\Validation\Validator
57 | */
58 | public function getValidator();
59 |
60 | /**
61 | * Cast Array
62 | * @return array
63 | */
64 | public function toArray();
65 | }
66 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Document/Passport/Passport.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 2015-01-11
17 | *
18 | * @copyright Laravel\PagSeguro
19 | */
20 | class Passport implements DocumentInterface
21 | {
22 |
23 | /**
24 | * Number
25 | * @var string
26 | */
27 | private $number;
28 |
29 | /**
30 | * Type
31 | * @var string
32 | */
33 | private $type = 'PASSPORT';
34 |
35 | use DataHydratorTrait,
36 | ValidateTrait {
37 | ValidateTrait::getHidratableVars insteadof DataHydratorTrait;
38 | }
39 |
40 | /**
41 | * Constructor
42 | * @param array $data
43 | */
44 | public function __construct(array $data = [])
45 | {
46 | if (count($data)) {
47 | $this->hydrate($data);
48 | }
49 | }
50 |
51 | /**
52 | * Get Number
53 | * @return string
54 | */
55 | public function getNumber()
56 | {
57 | return $this->number;
58 | }
59 |
60 | /**
61 | * Get Type
62 | * @return string
63 | */
64 | public function getType()
65 | {
66 | return $this->type;
67 | }
68 |
69 | /**
70 | * Set Number
71 | * @param string $number
72 | * @return Passport
73 | */
74 | public function setNumber($number)
75 | {
76 | $this->number = $number;
77 | return $this;
78 | }
79 |
80 | /**
81 | * Set Type
82 | * @param string $type
83 | * @return Passport
84 | */
85 | protected function setType($type)
86 | {
87 | if ($type !== 'PASSPORT') { // Restrict to Hydrate
88 | throw new \InvalidArgumentException('Invalid Passport Type');
89 | }
90 | return $this;
91 | }
92 |
93 | /**
94 | * Get Validation Rules
95 | * @return ValidationRules
96 | */
97 | public function getValidationRules()
98 | {
99 | return new ValidationRules();
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Document/Passport/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-01-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'number' => 'Required',
27 | ];
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $messages;
33 |
34 | use ValidationRulesTrait;
35 | }
36 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Facades/Checkout.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Checkout
14 | {
15 |
16 | /**
17 | * Create Address Instance
18 | * @param array $data
19 | * @return CheckoutInterface
20 | */
21 | public function createFromArray(array $data)
22 | {
23 | $resolver = new Resolver();
24 | if (!array_key_exists('redirectURL', $data)) {
25 | $data['redirectURL'] = $resolver->getRedirectURL();
26 | }
27 | if (!array_key_exists('notificationURL', $data)) {
28 | $data['notificationURL'] = $resolver->getNotificationURL();
29 | }
30 | $createData = array_filter($data);
31 | $facade = new CheckoutFacade();
32 | $checkout = $facade->createFromArray($createData);
33 | return $checkout;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Facades/Credentials.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Credentials
13 | {
14 |
15 | /**
16 | * Get Default Credentials
17 | * @param string $token
18 | * @param string $email
19 | * @return Credentials
20 | */
21 | public function create($token, $email)
22 | {
23 | return new PagSeguroCredentials($token, $email);
24 | }
25 |
26 | /**
27 | * Get Default Credentials
28 | * @return Credentials
29 | */
30 | public function get()
31 | {
32 | $data = Config::get('credentials');
33 | return $this->create($data['token'], $data['email']);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Facades/Item.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Item
13 | {
14 |
15 | /**
16 | * Create Item Instance
17 | * @param array $data
18 | * @return Item
19 | */
20 | public function create(array $data = [])
21 | {
22 | return new CartItem($data);
23 | }
24 |
25 | /**
26 | * Create Item Collection Instance
27 | * @param array $data
28 | * @return ItemCollection
29 | */
30 | public function createCollection(array $data = [])
31 | {
32 | return ItemCollection::factory($data);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Facades/PagSeguro.php:
--------------------------------------------------------------------------------
1 |
8 | */
9 | class PagSeguro
10 | {
11 |
12 | /**
13 | * @return Checkout
14 | */
15 | public function checkout()
16 | {
17 | return new Checkout();
18 | }
19 |
20 | /**
21 | * @return Plan
22 | */
23 | public function plan()
24 | {
25 | return new Plan();
26 | }
27 |
28 | /**
29 | * @return Credentials
30 | */
31 | public function credentials()
32 | {
33 | return new Credentials();
34 | }
35 |
36 | /**
37 | * @return Item
38 | */
39 | public function item()
40 | {
41 | return new Item();
42 | }
43 |
44 | /**
45 | * @return Transaction
46 | */
47 | public function transaction()
48 | {
49 | return new Transaction();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Facades/Plan.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 2019-08-28
17 | *
18 | * @copyright Laravel\PagSeguro
19 | */
20 | class Plan
21 | {
22 | /**
23 | * @param array $data
24 | * @return PlansInterface
25 | */
26 | public function createFromArray(array $data)
27 | {
28 | $this->checkArray($data);
29 |
30 | $dataFacade = new DataFacade();
31 | $PlansData = $dataFacade->ensureInstances($data);
32 |
33 | $plan = new Plans($PlansData);
34 |
35 | return $plan;
36 | }
37 |
38 | private function checkArray(array $data)
39 | {
40 | if(count($data) == 0)
41 | throw new \InvalidArgumentException('Parameter array plan size 0. Please check your array.');
42 | }
43 | }
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Facades/Transaction.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class Transaction
13 | {
14 |
15 | /**
16 | * @param string $code
17 | * @param CredentialsInterface $credentials
18 | * @param bool $autoCheck
19 | * @return PagSeguroTransaction
20 | */
21 | public function get($code, CredentialsInterface $credentials, $autoCheck = true)
22 | {
23 | $transaction = new PagSeguroTransaction($code, $credentials, $autoCheck);
24 | return $transaction;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Http/Request/Adapter/AdapterInterface.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-10-28
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | interface AdapterInterface
19 | {
20 | /**
21 | * @param RequestInterface $request
22 | * @return boolean Successful request
23 | */
24 | public function dispatch(RequestInterface $request);
25 |
26 | /**
27 | * @return \laravel\pagseguro\Http\Response\ResponseInterface Response
28 | */
29 | public function getResponse();
30 | }
31 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Http/Request/RequestInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-10-28
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface RequestInterface
17 | {
18 | /**
19 | * @return string GET|POST|PUT|DELETE ...
20 | */
21 | public function getMethod();
22 |
23 | /**
24 | * @return string Complete URL
25 | */
26 | public function getUrl();
27 |
28 | /**
29 | * @return array
30 | */
31 | public function getParams();
32 |
33 | /**
34 | * @return array
35 | */
36 | public function getData();
37 |
38 | /**
39 | * @return integer
40 | */
41 | public function getTimeout();
42 |
43 | /**
44 | * @return string
45 | */
46 | public function getCharset();
47 |
48 | /**
49 | * @return array Associative
50 | */
51 | public function getHeaders();
52 |
53 | /**
54 | * @param string $method
55 | * @return RequestInterface
56 | */
57 | public function setMethod($method);
58 |
59 | /**
60 | * @param string $url
61 | * @return RequestInterface
62 | */
63 | public function setUrl($url);
64 |
65 | /**
66 | * @param array|\JsonSerializable $params
67 | * @return RequestInterface
68 | */
69 | public function setParams($params);
70 |
71 | /**
72 | * @param string $data
73 | * @return RequestInterface
74 | */
75 | public function setData($data);
76 |
77 | /**
78 | * @param int $timeout
79 | * @return RequestInterface
80 | */
81 | public function setTimeout($timeout);
82 |
83 | /**
84 | * @param string $charset
85 | * @return RequestInterface
86 | */
87 | public function setCharset($charset);
88 |
89 | /**
90 | * @param array $headers
91 | * @return RequestInterface
92 | */
93 | public function setHeaders(array $headers);
94 | }
95 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Http/Response/Response.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-10-28
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class Response implements ResponseInterface
17 | {
18 | /**
19 | * @var string
20 | */
21 | protected $rawBody;
22 |
23 | /**
24 | * @var int
25 | */
26 | protected $httpStatus;
27 |
28 | /**
29 | * @var array
30 | */
31 | protected $errors = [];
32 |
33 | /**
34 | * @return string
35 | */
36 | public function getRawBody()
37 | {
38 | return $this->rawBody;
39 | }
40 |
41 | /**
42 | * @return int
43 | */
44 | public function getHttpStatus()
45 | {
46 | return $this->httpStatus;
47 | }
48 |
49 | /**
50 | * @return array
51 | */
52 | public function getErrors()
53 | {
54 | return $this->errors;
55 | }
56 |
57 | /**
58 | * @param string $rawBody
59 | * @return ResponseInterface
60 | */
61 | public function setRawBody($rawBody)
62 | {
63 | $this->rawBody = $rawBody;
64 | return $this;
65 | }
66 |
67 | /**
68 | * @param int $httpStatus
69 | * @return ResponseInterface
70 | */
71 | public function setHttpStatus($httpStatus)
72 | {
73 | $this->httpStatus = $httpStatus;
74 | return $this;
75 | }
76 |
77 | /**
78 | * @param array $errors
79 | * @return ResponseInterface
80 | */
81 | public function setErrors(array $errors)
82 | {
83 | $this->errors = $errors;
84 | return $this;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Http/Response/ResponseInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-10-28
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface ResponseInterface
17 | {
18 | /**
19 | * @return string Raw Body
20 | */
21 | public function getRawBody();
22 |
23 | /**
24 | * @return integer HTTP Status
25 | */
26 | public function getHttpStatus();
27 |
28 | /**
29 | * @param string $body Raw Body
30 | */
31 | public function setRawBody($body);
32 |
33 | /**
34 | * @param integer $status HTTP Status
35 | */
36 | public function setHttpStatus($status);
37 | }
38 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Information/InformationAbstract.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2016-01-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | abstract class InformationAbstract
20 | {
21 |
22 | use DataHydratorTrait, DataHydratorProtectedTrait {
23 | DataHydratorProtectedTrait::hydrate insteadof DataHydratorTrait;
24 | }
25 |
26 | /**
27 | * Constructor
28 | * @param array $data
29 | */
30 | public function __construct(array $data = [])
31 | {
32 | if (count($data)) {
33 | $this->hydrate($data);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Information/InformationAbstractFactory.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | abstract class InformationAbstractFactory
17 | {
18 |
19 | /**
20 | * @var array
21 | */
22 | protected $data;
23 |
24 | /**
25 | * Constructor
26 | * @param array $data
27 | */
28 | public function __construct(array $data)
29 | {
30 | $this->data = $data;
31 | }
32 |
33 | /**
34 | * @return Information
35 | */
36 | abstract public function getInformation();
37 |
38 | /**
39 | * Get DateTimeObject
40 | * @param string $stringDate
41 | * @return \DateTimeInterface
42 | */
43 | protected function getDateTimeObject($stringDate)
44 | {
45 | $time = \str_replace('.000', '', $stringDate);
46 | return \DateTime::createFromFormat(\DateTime::W3C, $time);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Item/ItemCollection.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-01-09
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class ItemCollection extends \ArrayObject
17 | {
18 |
19 | /**
20 | * Factory ItemCollection (Cria coleção de itens)
21 | * @param array $data Items
22 | * @return ItemCollection
23 | * @throws \InvalidArgumentException
24 | */
25 | public static function factory(array $data = [])
26 | {
27 | $collectionItems = [];
28 | $itr = new \ArrayIterator($data);
29 | while ($itr->valid()) {
30 | $item = $itr->current();
31 | if ($item instanceof ItemInterface) {
32 | $collectionItems[] = $item;
33 | } elseif (is_array($item)) {
34 | $collectionItems[] = new Item($item);
35 | } else {
36 | $exptMsg = sprintf('Invalid item on key: %s', $itr->key());
37 | throw new \InvalidArgumentException($exptMsg);
38 | }
39 | $itr->next();
40 | }
41 | return new self($collectionItems);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Item/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-01-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'id' => 'Required|max:100',
27 | 'description' => 'Required|max:100',
28 | 'quantity' => 'Required|integer|between:1,999',
29 | 'amount' => 'Required|numeric|between:0,9999999',
30 | 'weight' => 'Integer|max:30000',
31 | 'shippingCost' => 'Numeric|between:0,9999999',
32 | 'width' => 'Numeric',
33 | 'height' => 'Numeric',
34 | 'length' => 'Numeric',
35 | ];
36 |
37 | /**
38 | * @var array
39 | */
40 | protected $messages;
41 |
42 | use ValidationRulesTrait;
43 | }
44 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Notification/NotificationInterface.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-09-15
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | interface NotificationInterface
20 | {
21 |
22 | /**
23 | * Constructor
24 | * @param array|string $data Notification Required Data or String Code
25 | */
26 | public function __construct($data = []);
27 |
28 | /**
29 | * Get Notification Code
30 | * @return string
31 | */
32 | public function getNotificationCode();
33 |
34 | /**
35 | * Set Notification Code
36 | * @param string $code
37 | * @return Notification
38 | */
39 | public function setNotificationCode($code);
40 |
41 | /**
42 | * Get Notification Type
43 | * @return string
44 | */
45 | public function getNotificationType();
46 |
47 | /**
48 | * Set Notification Type
49 | * @param string $type
50 | * @return Notification
51 | */
52 | public function setNotificationType($type);
53 |
54 | /**
55 | * Check Information
56 | * @param CredentialsInterface $credentials
57 | * @return InformationFactory
58 | */
59 | public function check(CredentialsInterface $credentials);
60 |
61 | /**
62 | * Proxies Data Hydrate
63 | * @param array $data
64 | * @return object
65 | */
66 | public function hydrate(array $data = []);
67 | }
68 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Notification/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-09-15
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'notificationCode' => 'Required|size:39',
27 | 'notificationType' => 'Required|in:transaction',
28 | ];
29 |
30 | /**
31 | * @var array
32 | */
33 | protected $messages;
34 |
35 | use ValidationRulesTrait;
36 | }
37 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Parser/ParserInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface ParserInterface
17 | {
18 |
19 | /**
20 | * Constructor
21 | * @param string $rawData
22 | */
23 | public function __construct($rawData);
24 |
25 | /**
26 | * Array Parse
27 | */
28 | public function toArray();
29 | }
30 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Parser/Xml.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class Xml implements ParserInterface
17 | {
18 |
19 | /**
20 | * Raw Data
21 | * @var string
22 | */
23 | protected $rawData;
24 |
25 | /**
26 | * Parsed Data
27 | * @var array
28 | */
29 | protected $data;
30 |
31 | /**
32 | * Constructor
33 | * @param string $rawData
34 | */
35 | public function __construct($rawData)
36 | {
37 | if (!is_string($rawData)) {
38 | throw new \InvalidArgumentException('Invalid raw data');
39 | }
40 | $this->rawData = $rawData;
41 | }
42 |
43 | /**
44 | * Parse data
45 | * @throws \RuntimeException
46 | */
47 | protected function parse()
48 | {
49 | libxml_use_internal_errors(true);
50 | $xml = simplexml_load_string($this->rawData, '\SimpleXMLElement');
51 | if (count(libxml_get_errors())) {
52 | $errors = [];
53 | foreach (libxml_get_errors() as $error) {
54 | $errors[] = $error->message;
55 | }
56 | throw new \RuntimeException('Error: '. implode("\n", $errors));
57 | }
58 | if (!$xml) {
59 | throw new \RuntimeException('Invalid XML data');
60 | }
61 | $this->data = json_decode(json_encode((array) $xml), true);
62 | }
63 |
64 | /**
65 | * Array Parse
66 | * @return array
67 | */
68 | public function toArray()
69 | {
70 | if (is_null($this->data)) {
71 | $this->parse();
72 | }
73 | if (!is_array($this->data)) {
74 | throw new \RuntimeException('Error on parse XML data');
75 | }
76 | return $this->data;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/Billet/Billet.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-12-10
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class Billet extends MethodAbstract implements BilletInterface
19 | {
20 |
21 | /**
22 | * @var int
23 | */
24 | protected $type = self::TYPE_BILLET;
25 |
26 | /**
27 | * @var string
28 | */
29 | protected $typeName = 'Boleto';
30 |
31 | /**
32 | * @var array
33 | */
34 | protected $names = [
35 | self::BRADESCO => 'Bradesco',
36 | self::SANTANDER => 'Santander'
37 | ];
38 | }
39 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/Billet/BilletInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface BilletInterface
17 | {
18 | const BRADESCO = 201;
19 | const SANTANDER = 202;
20 | }
21 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/CreditCard/CreditCard.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-12-10
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class CreditCard extends MethodAbstract implements CreditCardInterface
19 | {
20 |
21 | /**
22 | * @var int
23 | */
24 | protected $type = self::TYPE_CREDIT_CARD;
25 |
26 | /**
27 | * @var string
28 | */
29 | protected $typeName = 'Cartão de Crédito';
30 |
31 | /**
32 | * @var array
33 | */
34 | protected $names = [
35 | self::VISA => 'VISA',
36 | self::MASTERCARD => 'MasterCard',
37 | self::AMERICAN_EXPRESS => 'American Express',
38 | self::DINERS => 'Diners',
39 | self::HIPERCARD => 'Hipercard',
40 | self::AURA => 'Aura',
41 | self::ELO => 'Elo',
42 | self::PLENOCARD => 'PLENOCard',
43 | self::PERSONALCARD => 'PersonalCard',
44 | self::JCB => 'JCB',
45 | self::DISCOVER => 'Discover',
46 | self::BRASILCARD => 'BrasilCard',
47 | self::FORTBRASIL => 'FORTBRASIL',
48 | self::CARDBAN => 'CARDBAN',
49 | self::VALECARD => 'VALECARD',
50 | self::CABAL => 'Cabal',
51 | self::MAIS => 'Mais',
52 | self::AVISTA => 'Avista',
53 | self::GRANDCARD => 'GRANDCARD',
54 | self::SOROCRED => 'Sorocred',
55 | ];
56 | }
57 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/CreditCard/CreditCardInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface CreditCardInterface
17 | {
18 | const VISA = 101;
19 | const MASTERCARD = 102;
20 | const AMERICAN_EXPRESS = 103;
21 | const DINERS = 104;
22 | const HIPERCARD = 105;
23 | const AURA = 106;
24 | const ELO = 107;
25 | const PLENOCARD = 108;
26 | const PERSONALCARD = 109;
27 | const JCB = 110;
28 | const DISCOVER = 111;
29 | const BRASILCARD = 112;
30 | const FORTBRASIL = 113;
31 | const CARDBAN = 114;
32 | const VALECARD = 115;
33 | const CABAL = 116;
34 | const MAIS = 117;
35 | const AVISTA = 118;
36 | const GRANDCARD = 119;
37 | const SOROCRED = 120;
38 | }
39 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/DepositAccount/DepositAccount.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-12-10
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class DepositAccount extends MethodAbstract implements DepositAccountInterface
19 | {
20 |
21 | /**
22 | * @var int
23 | */
24 | protected $type = self::TYPE_DEPOSIT_ACCOUNT;
25 |
26 | /**
27 | * @var string
28 | */
29 | protected $typeName = 'Depósito em conta';
30 |
31 | /**
32 | * @var array
33 | */
34 | protected $names = [
35 | self::BANCO_DO_BRASIL => 'Banco do Brasil',
36 | self::HSBC => 'HSBC'
37 | ];
38 | }
39 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/DepositAccount/DepositAccountInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface DepositAccountInterface
17 | {
18 | const BANCO_DO_BRASIL = 701;
19 | const HSBC = 702;
20 | }
21 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/Extras/Extras.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-12-10
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class Extras extends MethodAbstract implements ExtrasInterface
19 | {
20 |
21 | /**
22 | * @var int
23 | */
24 | protected $type;
25 |
26 | /**
27 | * @var array
28 | */
29 | protected $typeNames = [
30 | self::TYPE_OI_PAGGO => 'Oi Paggo',
31 | self::TYPE_PS_CREDIT => 'Saldo PagSeguro'
32 | ];
33 |
34 | /**
35 | * Test has code
36 | * @throws \InvalidArgumentException
37 | */
38 | protected function testCode()
39 | {
40 | if (!array_key_exists($this->type, $this->typeNames)) {
41 | throw new \InvalidArgumentException('Unknow type: ' . $this->type);
42 | }
43 | }
44 |
45 | /**
46 | * Get Name
47 | * @return string
48 | */
49 | public function getName()
50 | {
51 | return null;
52 | }
53 |
54 | /**
55 | * Get Type Name
56 | * @return string
57 | */
58 | public function getTypeName()
59 | {
60 | return $this->type ? $this->typeNames[$this->type] : null;
61 | }
62 |
63 | /**
64 | * Get Full Name
65 | * @return string
66 | */
67 | public function getFullName()
68 | {
69 | return $this->getTypeName();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/Extras/ExtrasInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface ExtrasInterface
17 | {
18 | const PS_CREDIT = 401;
19 | const OI_PAGGO = 501;
20 | }
21 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/MethodAbstract.php:
--------------------------------------------------------------------------------
1 |
16 | * @since 2015-12-10
17 | *
18 | * @copyright Laravel\PagSeguro
19 | */
20 | abstract class MethodAbstract implements MethodInterface
21 | {
22 |
23 | protected $names = [];
24 |
25 | protected $type;
26 |
27 | protected $typeName;
28 |
29 | protected $code;
30 |
31 | use DataHydratorTrait,
32 | DataHydratorProtectedTrait,
33 | DataHydratorConstructorTrait
34 | {
35 | DataHydratorProtectedTrait::hydrate insteadof DataHydratorTrait;
36 | }
37 |
38 | /**
39 | * @throws \InvalidArgumentException
40 | */
41 | public function __construct()
42 | {
43 | $this->hydrateMagic(['type', 'code', 'names'], func_get_args());
44 | if (!$this->type || !$this->code) {
45 | throw new \InvalidArgumentException('Type and Code are required');
46 | }
47 | $this->testCode();
48 | }
49 |
50 | /**
51 | * Test has code
52 | * @throws \InvalidArgumentException
53 | */
54 | protected function testCode()
55 | {
56 | if (!array_key_exists($this->code, $this->names)) {
57 | throw new \InvalidArgumentException('Unknow code: ' . $this->code);
58 | }
59 | }
60 |
61 | /**
62 | * Get Code
63 | * @return int
64 | */
65 | public function getCode()
66 | {
67 | return $this->code;
68 | }
69 |
70 | /**
71 | * Get Name
72 | * @return string
73 | */
74 | public function getName()
75 | {
76 | return $this->names[$this->code];
77 | }
78 |
79 | /**
80 | * Get Type
81 | * @return int
82 | */
83 | public function getType()
84 | {
85 | return $this->type;
86 | }
87 |
88 | /**
89 | * Get Type Name
90 | * @return string
91 | */
92 | public function getTypeName()
93 | {
94 | return $this->typeName;
95 | }
96 |
97 | /**
98 | * Get Full Name
99 | * @return string
100 | */
101 | public function getFullName()
102 | {
103 | return $this->getTypeName() . ' ' . $this->getName();
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/MethodFactory.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class MethodFactory extends MethodAbstract
17 | {
18 |
19 | /**
20 | * Class Map
21 | * @var array
22 | */
23 | protected static $classMap = [
24 | MethodInterface::TYPE_CREDIT_CARD => '\laravel\pagseguro\Payment\Method\CreditCard\CreditCard',
25 | MethodInterface::TYPE_BILLET => '\laravel\pagseguro\Payment\Method\Billet\Billet',
26 | MethodInterface::TYPE_TRANSFER => '\laravel\pagseguro\Payment\Method\Transfer\Transfer',
27 | MethodInterface::TYPE_PS_CREDIT => '\laravel\pagseguro\Payment\Method\Extras\Extras',
28 | MethodInterface::TYPE_OI_PAGGO => '\laravel\pagseguro\Payment\Method\Extras\Extras',
29 | MethodInterface::TYPE_DEPOSIT_ACCOUNT => '\laravel\pagseguro\Payment\Method\DepositAccount\DepositAccount',
30 | MethodInterface::TYPE_PIX => '\laravel\pagseguro\Payment\Method\Pix\Pix'
31 | ];
32 |
33 | /**
34 | * Factory Method
35 | * @param int $type
36 | * @param int $code
37 | * @return MethodInterface
38 | */
39 | public static function factory($type, $code)
40 | {
41 | if (!filter_var($type, FILTER_VALIDATE_INT)
42 | || !array_key_exists($type, self::$classMap)) {
43 | throw new \InvalidArgumentException('Invalid type');
44 | }
45 | if (!filter_var($code, FILTER_VALIDATE_INT)) {
46 | throw new \InvalidArgumentException('Invalid code');
47 | }
48 | $class = self::$classMap[$type];
49 | $paymentMethod = new $class($type, $code);
50 | return $paymentMethod;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/MethodInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface MethodInterface
17 | {
18 | const TYPE_CREDIT_CARD = 1;
19 | const TYPE_BILLET = 2;
20 | const TYPE_TRANSFER = 3;
21 | const TYPE_PS_CREDIT = 4;
22 | const TYPE_OI_PAGGO = 5;
23 | const TYPE_DEPOSIT_ACCOUNT = 6;
24 | const TYPE_PIX = 11;
25 |
26 | /**
27 | * Get Type Code
28 | * @return int
29 | */
30 | public function getType();
31 |
32 | /**
33 | * Get Type Name
34 | * @return string
35 | */
36 | public function getTypeName();
37 |
38 | /**
39 | * Get Method Code
40 | * @return int
41 | */
42 | public function getCode();
43 |
44 | /**
45 | * Get Method Name
46 | * @return string
47 | */
48 | public function getName();
49 |
50 | /**
51 | * Get Full Name
52 | * @return string
53 | */
54 | public function getFullName();
55 | }
56 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/Pix/Pix.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2023-02-04
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class Pix extends MethodAbstract implements PixInterface
19 | {
20 |
21 | /**
22 | * @var int
23 | */
24 | protected $type = self::TYPE_PIX;
25 |
26 | /**
27 | * @var string
28 | */
29 | protected $typeName = 'PIX';
30 |
31 | /**
32 | * @var array
33 | */
34 | protected $names = [
35 | self::PIX => 'Pix',
36 | ];
37 | }
38 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/Pix/PixInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2023-02-04
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface PixInterface
17 | {
18 | const PIX = 402;
19 | }
20 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/Transfer/Transfer.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-12-10
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class Transfer extends MethodAbstract implements TransferInterface
19 | {
20 |
21 | /**
22 | * @var int
23 | */
24 | protected $type = self::TYPE_TRANSFER;
25 |
26 | /**
27 | * @var string
28 | */
29 | protected $typeName = 'Transferência eletrônica';
30 |
31 | /**
32 | * @var array
33 | */
34 | protected $names = [
35 | self::BRADESCO => 'Bradesco',
36 | self::ITAU => 'Itaú',
37 | self::UNIBANCO => 'Unibanco',
38 | self::BANCO_DO_BRASIL => 'Bando do Brasil',
39 | self::BANCO_REAL => 'Banco Real',
40 | self::BANRISUL => 'Branrisul',
41 | self::HSBC => 'HSBC'
42 | ];
43 | }
44 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Payment/Method/Transfer/TransferInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-12-10
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface TransferInterface
17 | {
18 | const BRADESCO = 301;
19 | const ITAU = 302;
20 | const UNIBANCO = 303;
21 | const BANCO_DO_BRASIL = 304;
22 | const BANCO_REAL = 305;
23 | const BANRISUL = 306;
24 | const HSBC = 307;
25 | }
26 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Phone/PhoneInterface.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-01-11
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | interface PhoneInterface
19 | {
20 |
21 | /**
22 | * Get Area Code (DDD)
23 | * @return int
24 | */
25 | public function getAreaCode();
26 |
27 | /**
28 | * Set Area Code (DDD)
29 | * @param int $areaCode
30 | * @return PhoneInterface
31 | */
32 | public function setAreaCode($areaCode);
33 |
34 | /**
35 | * Get Country Code (DDI)
36 | * @return int
37 | */
38 | public function getCountryCode();
39 |
40 | /**
41 | * Set Country Code (DDI)
42 | * @param int $countryCode
43 | * @return PhoneInterface
44 | */
45 | public function setCountryCode($countryCode);
46 |
47 | /**
48 | * Get Number
49 | * @return string
50 | */
51 | public function getNumber();
52 |
53 | /**
54 | * Set Number
55 | * @param string $number
56 | * @return PhoneInterface
57 | */
58 | public function setNumber($number);
59 |
60 | /**
61 | * Proxies Data Hydrate
62 | * @param array $data
63 | * @return object
64 | */
65 | public function hydrate(array $data = []);
66 |
67 | /**
68 | * Test Valid Data
69 | * @return bool
70 | */
71 | public function isValid();
72 |
73 | /**
74 | * Get Validator
75 | * Return only after hydrate
76 | * @return null|\Illuminate\Validation\Validator
77 | */
78 | public function getValidator();
79 |
80 | /**
81 | * Cast Array
82 | * @return array
83 | */
84 | public function toArray();
85 | }
86 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Phone/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-01-11
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'areaCode' => 'Required|numeric|digits:2',
27 | 'countryCode' => 'Required|numeric|digits:2',
28 | 'number' => 'Required|digits_between:8,9',
29 | ];
30 |
31 | /**
32 | * @var array
33 | */
34 | protected $messages;
35 |
36 | use ValidationRulesTrait;
37 | }
38 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Plans/AbstractPlans.php:
--------------------------------------------------------------------------------
1 | hydrateMagic(
30 | [
31 | 'references', 'preApproval'
32 | ],
33 | $args
34 | );
35 | }
36 |
37 | /**
38 | * @return ValidationRulesInterface
39 | */
40 | public function getValidationRules()
41 | {
42 | return new ValidationRules();
43 | }
44 | }
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Plans/Facade/DataFacade.php:
--------------------------------------------------------------------------------
1 | ensurePreApproval($data['preApproval']);
14 | }
15 | return $data;
16 | }
17 |
18 | private function ensurePreApproval($preApproval)
19 | {
20 | if ($preApproval instanceof PreApprovalInterface) {
21 | return $preApproval;
22 | }
23 | if (!is_array($preApproval)) {
24 | throw new \InvalidArgumentException('Invalid sender data');
25 | }
26 | return new PreApproval($preApproval);
27 | }
28 | }
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Plans/Plans.php:
--------------------------------------------------------------------------------
1 | body;
24 | }
25 |
26 | public function getpreApproval()
27 | {
28 | return $this->preApproval;
29 | }
30 |
31 | public function setBody($body)
32 | {
33 | if (is_null($body)) {
34 | throw new \InvalidArgumentException('Invalid body');
35 | }
36 | $this->body = $body;
37 | return $this;
38 | }
39 |
40 | public function setpreApproval($preApproval)
41 | {
42 | if (is_null($preApproval)) {
43 | throw new \InvalidArgumentException('Invalid preApproval');
44 | }
45 | $this->preApproval = $preApproval;
46 | return $this;
47 | }
48 |
49 | public function send(CredentialsInterface $credentials)
50 | {
51 | $remote = new RemotePlans();
52 | $data = $remote->send($this, $credentials);
53 | $factory = new InformationFactory($data);
54 | return $factory->getInformation();
55 | }
56 | }
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Plans/PlansInterface.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2019-08-28
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class Expiration implements ExpirationInterface
20 | {
21 | /**
22 | * Value (Valor do tempo)
23 | * @var int
24 | */
25 | protected $value;
26 |
27 | /**
28 | * Unit (Unidade de tempo dia, mês ou ano)
29 | */
30 | protected $unit;
31 |
32 | use DataHydratorTrait, ValidateTrait {
33 | ValidateTrait::getHidratableVars insteadof DataHydratorTrait;
34 | }
35 |
36 | /**
37 | * Constructor
38 | * @param array $data
39 | */
40 | public function __construct(array $data = [])
41 | {
42 | if (count($data)) {
43 | $this->hydrate($data);
44 | }
45 | }
46 |
47 | /**
48 | * Get Name (Nome)
49 | * @return string
50 | */
51 | public function getValue()
52 | {
53 | return $this->value;
54 | }
55 |
56 | /**
57 | * @param string $name
58 | * @return $this|PreApprovalInterface
59 | */
60 | public function setValue($value)
61 | {
62 | $this->value= $value;
63 |
64 | return $this;
65 | }
66 |
67 | public function getUnit()
68 | {
69 | return $this->unit;
70 | }
71 |
72 | public function setUnit($unit)
73 | {
74 | $this->charge = $unit;
75 |
76 | return $this;
77 | }
78 |
79 | /**
80 | * Get Validation Rules
81 | * @return ValidationRules
82 | */
83 | public function getValidationRules()
84 | {
85 | return new ValidationRules();
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Plans/PreApproval/Expiration/ExpirationInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2019-12-13
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface ExpirationInterface
17 | {
18 |
19 | /**
20 | * Constructor
21 | * @param array $data
22 | */
23 | public function __construct(array $data = []);
24 |
25 | /**
26 | * Get Value (Valor)
27 | * @return int
28 | */
29 | public function getValue();
30 |
31 | /**
32 | * Set Value
33 | * @param int $value
34 | * @return ExpirationInterface
35 | */
36 | public function setValue($value);
37 |
38 | /**
39 | * Get Unit (Unidade de tempo)
40 | * @return string
41 | */
42 | public function getUnit();
43 |
44 | /**
45 | * Set Unit
46 | * @param int $unit
47 | * @return ExpirationInterface
48 | */
49 | public function setUnit($unit);
50 |
51 | /**
52 | * Proxies Data Hydrate
53 | * @param array $data
54 | * @return object
55 | */
56 | public function hydrate(array $data = []);
57 |
58 | /**
59 | * Test Valid Data
60 | * @return bool
61 | */
62 | public function isValid();
63 |
64 | /**
65 | * Get Validator
66 | * Return only after hydrate
67 | * @return null|\Illuminate\Validation\Validator
68 | */
69 | public function getValidator();
70 |
71 | /**
72 | * Cast Array
73 | * @return array
74 | */
75 | public function toArray();
76 | }
77 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Plans/PreApproval/Expiration/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2019-08-28
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 | /**
22 | * @var array
23 | */
24 | protected $rules = [
25 | 'value' => 'required|int|min:1|max:1000000',
26 | 'unit' => 'required|string',
27 | ];
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $messages;
33 |
34 | use ValidationRulesTrait;
35 | }
36 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Plans/PreApproval/PreApprovalInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2019-08-28
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface PreApprovalInterface
17 | {
18 |
19 | /**
20 | * Constructor
21 | * @param array $data
22 | */
23 | public function __construct(array $data = []);
24 |
25 | /**
26 | * Get Name (Nome)
27 | * @return string
28 | */
29 | public function getName();
30 |
31 | /**
32 | * Set Name
33 | * @param string $name
34 | * @return PreApprovalInterface
35 | */
36 | public function setName($name);
37 |
38 | public function getCharge();
39 |
40 | public function setCharge($charge);
41 |
42 | public function setPeriod($period);
43 |
44 | public function getPeriod();
45 |
46 | public function setAmountPerPayment($amountPerPayment);
47 |
48 | public function getAmountPerPayment();
49 |
50 | public function setTrialPeriodDuration($trialPeriodDuration);
51 |
52 | public function getTrialPeriodDuration();
53 |
54 | public function setMembershipFee($membershipFee);
55 |
56 | public function getMembershipFee();
57 |
58 | public function setDetails($details);
59 |
60 | public function getDetails();
61 |
62 | public function setExpiration($expiration);
63 |
64 | public function getExpiration();
65 |
66 | /**
67 | * Proxies Data Hydrate
68 | * @param array $data
69 | * @return object
70 | */
71 | public function hydrate(array $data = []);
72 |
73 | /**
74 | * Test Valid Data
75 | * @return bool
76 | */
77 | public function isValid();
78 |
79 | /**
80 | * Get Validator
81 | * Return only after hydrate
82 | * @return null|\Illuminate\Validation\Validator
83 | */
84 | public function getValidator();
85 |
86 | /**
87 | * Cast Array
88 | * @return array
89 | */
90 | public function toArray();
91 | }
92 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Plans/PreApproval/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2019-08-28
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 | /**
22 | * @var array
23 | */
24 | protected $rules = [
25 | 'name' => 'Required|min:2|max:50',
26 | 'charge' => 'Required',
27 | 'period' => 'Required',
28 | 'amountPerPayment' => '',
29 | 'membershipFee' => '',
30 | 'trialPeriodDuration' => '',
31 | 'details' => '',
32 | 'expiration' => '',
33 | ];
34 |
35 | /**
36 | * @var array
37 | */
38 | protected $messages;
39 |
40 | use ValidationRulesTrait;
41 | }
42 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Plans/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2016-01-12
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'body' => 'Required',
27 | 'preApproval' => 'Required',
28 | ];
29 |
30 | /**
31 | * @var array
32 | */
33 | protected $messages;
34 |
35 | use ValidationRulesTrait;
36 | }
37 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Platform/Laravel5.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2016-01-15
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | class Laravel5 implements PlatformInterface
19 | {
20 |
21 | /**
22 | * @return array
23 | */
24 | public function getUrlParameters()
25 | {
26 | return Request::all();
27 | }
28 |
29 | /**
30 | * @return boolean
31 | */
32 | public function hasPersonalConfig()
33 | {
34 | return true;
35 | }
36 |
37 | /**
38 | * @param string $key
39 | * @return array
40 | */
41 | public function getConfigByKey($key)
42 | {
43 | return \Config::get($key);
44 | }
45 |
46 | /**
47 | * @param string $key
48 | * @param mixed $value
49 | * @return void
50 | */
51 | public function setConfigByKey($key, $value)
52 | {
53 | \Config::set($key, $value);
54 | }
55 |
56 | /**
57 | * @return void
58 | */
59 | public function abort()
60 | {
61 | \App::abort(500);
62 | }
63 |
64 | /**
65 | * @return boolean
66 | */
67 | public function hasRouter()
68 | {
69 | return true;
70 | }
71 |
72 | /**
73 | * @param string $routeName
74 | * @return string
75 | */
76 | public function getUrlByRoute($routeName)
77 | {
78 | return \URL::route($routeName);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Platform/Laravel5/PagSeguro.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class PagSeguro extends Facade
12 | {
13 |
14 | /**
15 | * Get the registered name of the component.
16 | *
17 | * @return string
18 | */
19 | protected static function getFacadeAccessor()
20 | {
21 | return 'pagseguro';
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Platform/Laravel5/ServiceProvider.php:
--------------------------------------------------------------------------------
1 |
17 | * @since 2015-01-02
18 | *
19 | * @copyright Laravel\PagSeguro
20 | */
21 | class ServiceProvider extends SupportServiceProvider
22 | {
23 |
24 | /**
25 | * Indicates if loading of the provider is deferred.
26 | * @var bool
27 | */
28 | protected $defer = true;
29 |
30 | /**
31 | * Bootstrap the application events.
32 | * @return void
33 | */
34 | public function boot()
35 | {
36 | $this->publishes([__DIR__ . '/../../Config/application-config.php' => config_path('laravelpagseguro.php')]);
37 | }
38 |
39 | /**
40 | * Register the service provider.
41 | * @return void
42 | */
43 | public function register()
44 | {
45 | $this->app->bind('pagseguro', function () {
46 | $platform = new Laravel5();
47 | Config::usePlatform($platform);
48 | $facade = new PagSeguroFacade();
49 | return $facade;
50 | });
51 | }
52 |
53 | /**
54 | * Get the services provided by the provider.
55 | * @return array
56 | */
57 | public function provides()
58 | {
59 | return ['pagseguro'];
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Platform/Native.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-15
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | class Native implements PlatformInterface
17 | {
18 |
19 | /**
20 | * @return array
21 | */
22 | public function getUrlParameters()
23 | {
24 | return filter_input_array(INPUT_GET);
25 | }
26 |
27 | /**
28 | * @return boolean
29 | */
30 | public function hasPersonalConfig()
31 | {
32 | return false;
33 | }
34 |
35 | /**
36 | * @param string $key
37 | * @return array
38 | */
39 | public function getConfigByKey($key)
40 | {
41 | unset($key);
42 | return [];
43 | }
44 |
45 | /**
46 | * @param string $key
47 | * @param mixed $value
48 | * @return void
49 | */
50 | public function setConfigByKey($key, $value)
51 | {
52 | unset($key, $value);
53 | }
54 |
55 | /**
56 | * @return void
57 | */
58 | public function abort()
59 | {
60 | $protocol = filter_input(INPUT_SERVER, 'SERVER_PROTOCOL');
61 | header($protocol . ' 500 Internal Server Error', true, 500);
62 | }
63 |
64 | /**
65 | * @return boolean
66 | */
67 | public function hasRouter()
68 | {
69 | return false;
70 | }
71 |
72 | /**
73 | * @param string $routeName
74 | * @return string
75 | */
76 | public function getUrlByRoute($routeName)
77 | {
78 | unset($routeName);
79 | return null;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Platform/PlatformInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-15
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface PlatformInterface
17 | {
18 |
19 | /**
20 | * @return array
21 | */
22 | public function getUrlParameters();
23 |
24 | /**
25 | * @return boolean
26 | */
27 | public function hasPersonalConfig();
28 |
29 | /**
30 | * @param string $key
31 | * @return array
32 | */
33 | public function getConfigByKey($key);
34 |
35 | /**
36 | * @param string $key
37 | * @param mixed $value
38 | * @return void
39 | */
40 | public function setConfigByKey($key, $value);
41 |
42 | /**
43 | * @return void
44 | */
45 | public function abort();
46 |
47 | /**
48 | * @return boolean
49 | */
50 | public function hasRouter();
51 |
52 | /**
53 | * @param string $routeName
54 | * @return string
55 | */
56 | public function getUrlByRoute($routeName);
57 | }
58 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Receiver/Receiver.php:
--------------------------------------------------------------------------------
1 |
17 | * @since 2016-01-12
18 | *
19 | * @copyright Laravel\PagSeguro
20 | */
21 | class Receiver implements ReceiverInterface
22 | {
23 |
24 | /**
25 | * @var string
26 | */
27 | protected $email;
28 |
29 | use DataHydratorTrait, DataHydratorProtectedTrait, DataHydratorConstructorTrait, ValidateTrait {
30 | DataHydratorProtectedTrait::hydrate insteadof DataHydratorTrait;
31 | ValidateTrait::getHidratableVars insteadof DataHydratorTrait;
32 | }
33 |
34 | /**
35 | * Constructor
36 | * @param array|string $data Notification Required Data or String Code
37 | */
38 | public function __construct($data = [])
39 | {
40 | $args = func_get_args();
41 | $data = null;
42 | $this->hydrateMagic(['email'], $args);
43 | }
44 |
45 | /**
46 | * @return string
47 | */
48 | public function getEmail()
49 | {
50 | return $this->email;
51 | }
52 |
53 | /**
54 | * Get Validation Rules
55 | * @return ValidationRules
56 | */
57 | public function getValidationRules()
58 | {
59 | return new ValidationRules();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Receiver/ReceiverInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2016-01-12
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface ReceiverInterface
17 | {
18 | /**
19 | * Constructor
20 | * @param array $data Checkout data
21 | */
22 | public function __construct($data = []);
23 |
24 | /**
25 | * @return string
26 | */
27 | public function getEmail();
28 | }
29 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Receiver/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2016-01-12
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'email' => 'Required|Email|Max:60'
27 | ];
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $messages;
33 |
34 | use ValidationRulesTrait;
35 | }
36 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Remote/Checkout.php:
--------------------------------------------------------------------------------
1 |
18 | * @since 2015-12-10
19 | *
20 | * @copyright Laravel\PagSeguro
21 | */
22 | class Checkout extends ConsumerAbstract
23 | {
24 |
25 | /**
26 | * Send Checkout
27 | * @param CheckoutInterface $checkout
28 | * @param CredentialsInterface $credential
29 | * @return array|boolean Array with transaction info or FALSE on failure
30 | */
31 | public function send(CheckoutInterface $checkout, CredentialsInterface $credential)
32 | {
33 | $url = $this->getUrlTo('checkout');
34 | $request = $this->getRequest();
35 | $this->prepareStatement($checkout, $request);
36 | $credentialData = $this->getCredentialData($credential);
37 | $response = $request->post($url, $credentialData);
38 | if (!$response) {
39 | throw new \RuntimeException('Checkout send failure');
40 | }
41 | $body = $response->getRawBody();
42 | if ($response->getHttpStatus() !== 200) {
43 | $error = 'Error on send: ' . $response->getHttpStatus() . '-' . $body;
44 | throw new \RuntimeException($error);
45 | }
46 | $parser = new Xml($body);
47 | $data = $parser->toArray();
48 | if (array_key_exists('code', $data)) {
49 | $paymentUrl = str_replace('ws.', '', $url) . '/payment.html?code=';
50 | $data['link'] = $paymentUrl . $data['code'];
51 | }
52 | return $data;
53 | }
54 |
55 | /**
56 | * Prepare Request With Statement
57 | * @param CheckoutInterface $checkout
58 | * @param RequestInterface $request
59 | */
60 | protected function prepareStatement(CheckoutInterface $checkout, RequestInterface $request)
61 | {
62 | $stmt = new XmlStatement($checkout);
63 | $stmt->prepare($request);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Remote/ConsumerAbstract.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-12-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | abstract class ConsumerAbstract
20 | {
21 |
22 | /**
23 | * Request Object
24 | * @var Request
25 | */
26 | protected $request;
27 |
28 | /**
29 | * Return Request Object
30 | * @return Request
31 | */
32 | protected function getRequest()
33 | {
34 | $adapter = Manager::getHttpAdapter();
35 | $request = new Request($adapter);
36 | return $request;
37 | }
38 |
39 | /**
40 | * Get Credential Data to Request
41 | * @param CredentialsInterface $credential
42 | * @return array Credential Data
43 | */
44 | protected function getCredentialData(CredentialsInterface $credential)
45 | {
46 | return [
47 | 'email' => $credential->getEmail(),
48 | 'token' => $credential->getToken()
49 | ];
50 | }
51 |
52 | /**
53 | * Return URL from Config
54 | * @param string $code URL Code
55 | * @return string
56 | */
57 | protected function getUrlTo($code)
58 | {
59 | $resolver = new Url\Resolver();
60 | return $resolver->getByKey($code);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Remote/Manager.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-12-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class Manager
20 | {
21 |
22 | /**
23 | * @var AdapterInterface
24 | */
25 | private static $httpAdapter;
26 |
27 | /**
28 | * Set Http Adapter
29 | * @param AdapterInterface $adapter
30 | */
31 | public static function setHttpAdapter(AdapterInterface $adapter)
32 | {
33 | self::$httpAdapter = $adapter;
34 | }
35 |
36 | /**
37 | * Get Http Adapter
38 | * @return AdapterInterface
39 | */
40 | public static function getHttpAdapter()
41 | {
42 | $adapter = self::$httpAdapter;
43 | if (!$adapter) {
44 | $adapter = self::$httpAdapter = self::buildHttpAdapter();
45 | }
46 | return $adapter;
47 | }
48 |
49 | /**
50 | * Build Http Adapter by Application Config
51 | * @return AdapterInterface
52 | * @throws \RuntimeException
53 | */
54 | public static function buildHttpAdapter()
55 | {
56 | $http = Config::get('http');
57 | $adapterConfig = $http['adapter'];
58 | $adapter = null;
59 | if (is_array($adapterConfig)) {
60 | $adapter = self::adapterArrayFactory($adapterConfig);
61 | } elseif ($adapterConfig instanceof \Closure) {
62 | $adapter = $adapterConfig();
63 | }
64 | if (!($adapter instanceof AdapterInterface)) {
65 | throw new \RuntimeException('Invalid adapter object');
66 | }
67 | return $adapter;
68 | }
69 |
70 | /**
71 | * @param array $adapter
72 | * @return AdapterInterface
73 | */
74 | private static function adapterArrayFactory(array $adapter)
75 | {
76 | $type = reset($adapter);
77 | $options = end($adapter);
78 | if (!is_string($type) || !is_array($options)) {
79 | throw new \InvalidArgumentException('Invalid adapter config');
80 | }
81 | $namespace = '\\laravel\\pagseguro\\Http\\Request\\Adapter\\';
82 | $className = ucfirst($type) . 'Adapter';
83 | $class = $namespace . $className;
84 | if (!class_exists($class)) {
85 | throw new \InvalidArgumentException('Invalid adapter: ' . $type);
86 | }
87 | return new $class($options);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Remote/Notification.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-12-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class Notification extends ConsumerAbstract
20 | {
21 |
22 | /**
23 | * Get Transaction Status
24 | * @param string $code
25 | * @param CredentialsInterface $credential
26 | * @return array|boolean Array with transaction info or FALSE on failure
27 | */
28 | public function transaction($code, CredentialsInterface $credential)
29 | {
30 | $url = $this->getUrlTo('transactions-notifications');
31 | $completeUrl = "{$url}/{$code}";
32 | $request = $this->getRequest();
33 | $credentialData = $this->getCredentialData($credential);
34 | $response = $request->get($completeUrl, $credentialData);
35 | if (!$response) {
36 | throw new \RuntimeException('Notification check failure');
37 | }
38 | $body = $response->getRawBody();
39 | if ($response->getHttpStatus() !== 200) {
40 | $error = 'Error on getStatus: ' . $response->getHttpStatus() . '-' . strip_tags($body);
41 | throw new \RuntimeException($error);
42 | }
43 | $parser = new Xml($body);
44 | return $parser->toArray();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Remote/Plans.php:
--------------------------------------------------------------------------------
1 | getUrlTo('pre-approvals');
14 | $request = $this->getRequest();
15 | $this->prepareStatement($plans, $request);
16 | $credentialData = $this->getCredentialData($credential);
17 | $response = $request->post($url, $credentialData);
18 | if (!$response) {
19 | throw new \RuntimeException('Checkout send failure');
20 | }
21 | $body = $response->getRawBody();
22 |
23 | if ($response->getHttpStatus() !== 200) {
24 | $error = 'Error on send: ' . $response->getHttpStatus() . '-' . $body;
25 | throw new \RuntimeException($error);
26 | }
27 |
28 | $data = json_decode($body, true);
29 | if (array_key_exists('code', $data)) {
30 | $paymentUrl = str_replace(['ws.', '/pre-approvals', '/request'], '', $url) . '/v2/pre-approvals/request.html?code=';
31 | $data['link'] = $paymentUrl . $data['code'];
32 | }
33 |
34 | return $data;
35 | }
36 |
37 | protected function prepareStatement(PlansInterface $plans, RequestInterface $request)
38 | {
39 |
40 | $array = $this->change_key($plans->getpreApproval()->toArray(), 'name', 'preApprovalName');
41 | $array = $this->change_key($array, 'charge', 'preApprovalCharge');
42 | $array = $this->change_key($array, 'period', 'preApprovalPeriod');
43 | $array = $this->change_key($array, 'amountPerPayment', 'preApprovalAmountPerPayment');
44 | $array = $this->change_key($array, 'membershipFee', 'preApprovalMembershipFee');
45 | $array = $this->change_key($array, 'trialPeriodDuration', 'preApprovalTrialPeriodDuration');
46 | $array = $this->change_key($array, 'details', 'preApprovalDetails');
47 |
48 | $dataRequest = http_build_query(array_merge($plans->toArray()['body'], $array ));
49 |
50 | $charset = 'UTF-8';
51 | $request->setData($dataRequest)->setCharset($charset)
52 | ->setHeaders([
53 | 'Accept' => 'application/vnd.pagseguro.com.br.v3+json;charset=ISO-8859-1'
54 | ]);
55 | }
56 |
57 | private function change_key( $array, $old_key, $new_key ) {
58 | if( ! array_key_exists( $old_key, $array ) )
59 | return $array;
60 |
61 | $keys = array_keys( $array );
62 | $keys[ array_search( $old_key, $keys ) ] = $new_key;
63 |
64 | return array_combine( $keys, $array );
65 | }
66 | }
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Remote/Transaction.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-12-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class Transaction extends ConsumerAbstract
20 | {
21 |
22 | /**
23 | * Get Transaction Status
24 | * @param string $code
25 | * @param CredentialsInterface $credential
26 | * @return array|boolean Array with transaction info or FALSE on failure
27 | */
28 | public function getStatus($code, CredentialsInterface $credential)
29 | {
30 | $url = $this->getUrlTo('transactions');
31 | $completeUrl = "{$url}/{$code}";
32 | $request = $this->getRequest();
33 | $credentialData = $this->getCredentialData($credential);
34 | $response = $request->get($completeUrl, $credentialData);
35 | if (!$response) {
36 | throw new \RuntimeException('Transaction check failure');
37 | }
38 | $body = $response->getRawBody();
39 | if ($response->getHttpStatus() !== 200) {
40 | $error = 'Error on getStatus: ' . $response->getHttpStatus() . '-' . $body;
41 | throw new \RuntimeException($error);
42 | }
43 | $parser = new Xml($body);
44 | return $parser->toArray();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Sender/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-01-11
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'email' => 'Required|Email',
27 | 'name' => 'Required|min:2|max:50',
28 | 'documents' => 'Required',
29 | 'phone' => 'Required',
30 | 'bornDate' => 'Date',
31 | ];
32 |
33 | /**
34 | * @var array
35 | */
36 | protected $messages;
37 |
38 | use ValidationRulesTrait;
39 | }
40 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Shipping/ShippingInterface.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2015-12-10
15 | *
16 | * @copyright Laravel\PagSeguro
17 | */
18 | interface ShippingInterface
19 | {
20 |
21 | const TYPE_PAC = 1;
22 | const TYPE_SEDEX = 2;
23 | const TYPE_UNKNOW = 3;
24 |
25 | /**
26 | * Constructor
27 | * @param array $data
28 | */
29 | public function __construct(array $data = []);
30 |
31 |
32 | /**
33 | * Get Address
34 | * @return AddressInterface
35 | */
36 | public function getAddress();
37 |
38 | /**
39 | * Get Cost
40 | * @return float
41 | */
42 | public function getCost();
43 |
44 | /**
45 | * Get Type
46 | * @return int
47 | */
48 | public function getType();
49 |
50 | /**
51 | * Set Address
52 | * @param AddressInterface $address
53 | * @return ShippingInterface
54 | */
55 | public function setAddress(AddressInterface $address);
56 |
57 | /**
58 | * Set Cost
59 | * @param float $cost
60 | * @return ShippingInterface
61 | */
62 | public function setCost($cost);
63 |
64 | /**
65 | * Set Type
66 | * @param int $type
67 | * @return ShippingInterface
68 | */
69 | public function setType($type);
70 |
71 | /**
72 | * Proxies Data Hydrate
73 | * @param array $data
74 | * @return object
75 | */
76 | public function hydrate(array $data = []);
77 |
78 | /**
79 | * Test Valid Data
80 | * @return bool
81 | */
82 | public function isValid();
83 |
84 | /**
85 | * Get Validator
86 | * Return only after hydrate
87 | * @return null|\Illuminate\Validation\Validator
88 | */
89 | public function getValidator();
90 |
91 | /**
92 | * Cast Array
93 | * @return array
94 | */
95 | public function toArray();
96 | }
97 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Shipping/ValidationRules.php:
--------------------------------------------------------------------------------
1 |
15 | * @since 2015-12-10
16 | *
17 | * @copyright Laravel\PagSeguro
18 | */
19 | class ValidationRules implements ValidationRulesInterface
20 | {
21 |
22 | /**
23 | * @var array
24 | */
25 | protected $rules = [
26 | 'address' => 'Required',
27 | 'cost' => 'Required|numeric|between:0,9999999',
28 | 'type' => 'Required|integer|between:1,3',
29 | ];
30 |
31 | /**
32 | * @var array
33 | */
34 | protected $messages;
35 |
36 | use ValidationRulesTrait;
37 | }
38 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Transaction/Status/StatusInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-09-15
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface StatusInterface
17 | {
18 |
19 | const INITIALIZED = 0;
20 | const AWAITING_PAYMENT = 1;
21 | const REVIEW = 2;
22 | const PAID = 3;
23 | const AVAIBLE = 4;
24 | const DISPUTE = 5;
25 | const RETURNED = 6;
26 | const CANCELED = 7;
27 | const SELLER_CHARGEBACK = 8;
28 | const CONTESTATION = 9;
29 |
30 | /**
31 | * @return int
32 | */
33 | public function getCode();
34 |
35 | /**
36 | * @return string
37 | */
38 | public function getName();
39 |
40 | /**
41 | * Se Pode liberar o produto/ serviço para o cliente
42 | * You can release the product / service to the customer
43 | */
44 | public function canDispatch();
45 |
46 | /**
47 | * Se o dinheiro já esta disponível
48 | * If the money is already available
49 | */
50 | public function isAvaible();
51 |
52 | /**
53 | * Se a transação foi cancelada
54 | * If the transaction is canceled
55 | */
56 | public function canceled();
57 |
58 | /**
59 | * Se a transação foi encerrada
60 | * If the transaction is finished
61 | */
62 | public function finished();
63 | }
64 |
--------------------------------------------------------------------------------
/src/laravel/pagseguro/Transaction/TransactionInterface.php:
--------------------------------------------------------------------------------
1 |
12 | * @since 2015-09-15
13 | *
14 | * @copyright Laravel\PagSeguro
15 | */
16 | interface TransactionInterface
17 | {
18 | /**
19 | * Get Code
20 | * @return string
21 | */
22 | public function getCode();
23 |
24 | /**
25 | * Check transaction status
26 | * @return bool
27 | */
28 | public function check();
29 |
30 | /**
31 | * Get Transaction Info
32 | * @return Information\Information
33 | */
34 | public function getInformation();
35 | }
36 |
--------------------------------------------------------------------------------
/tests/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaeldouglas/laravel-pagseguro/4ab3ce8d03b6bc77a520c35409a04ed3e049d430/tests/.gitkeep
--------------------------------------------------------------------------------
/tests/unit/Address/AddressTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class AddressTest extends TestCase
13 | {
14 |
15 | public function testEmptyAddress()
16 | {
17 | $address = new Address();
18 | $this->assertEquals([
19 | 'postalCode' => null,
20 | 'street' => null,
21 | 'number' => null,
22 | 'complement' => null,
23 | 'district' => null,
24 | 'city' => null,
25 | 'state' => null,
26 | 'country' => null,
27 | ], $address->toArray());
28 | }
29 |
30 | public function testFullAddress()
31 | {
32 | $data = [
33 | 'postalCode' => '06410000',
34 | 'street' => 'Rua da prata',
35 | 'number' => '55',
36 | 'complement' => '',
37 | 'district' => 'Jardim dos Camargos',
38 | 'city' => 'Barueri',
39 | 'state' => 'SP',
40 | 'country' => 'Brasil',
41 | ];
42 | $address = new Address($data);
43 | $this->assertEquals($data, $address->toArray());
44 | $this->assertEquals($data['postalCode'], $address->getPostalCode());
45 | $this->assertEquals($data['street'], $address->getStreet());
46 | $this->assertEquals($data['number'], $address->getNumber());
47 | $this->assertEquals($data['complement'], $address->getComplement());
48 | $this->assertEquals($data['district'], $address->getDistrict());
49 | $this->assertEquals($data['city'], $address->getCity());
50 | $this->assertEquals($data['state'], $address->getState());
51 | $this->assertEquals($data['country'], $address->getCountry());
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/tests/unit/Address/BaseValidationRules.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class BaseValidationRules extends \laravel\pagseguro\Tests\Unit\ValidationRules
12 | {
13 |
14 | /**
15 | * @param string $key
16 | * @return mixed
17 | */
18 | protected function getRule($key)
19 | {
20 | if (!$this->rules) {
21 | $validationRules = new ValidationRules();
22 | $this->rules = $validationRules->getRules();
23 | }
24 | return $this->rules[$key];
25 | }
26 |
27 | /**
28 | * @param string $strBase
29 | * @param int $size
30 | * @param bool $required
31 | * @return array
32 | */
33 | protected function getWithStrBaseWithRequired($strBase, $size = 10, $required = true)
34 | {
35 | $strBase = str_repeat($strBase, $size);
36 | return [
37 | $required ? $this->emptyRequired() : $this->emptyUnrequired(),
38 | [$strBase, true],
39 | [$strBase . 'A', false],
40 | ];
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/unit/Address/PrimaryInfoTest.php:
--------------------------------------------------------------------------------
1 |
8 | */
9 | class PrimaryInfoTest extends BaseValidationRules
10 | {
11 |
12 | /**
13 | * Postal Code Data Provider
14 | * @return array
15 | */
16 | public function postalCodeProvider()
17 | {
18 | return [
19 | $this->emptyRequired(),
20 | ['asdasd', false],
21 | ['0640512', false],
22 | ['06405122', true],
23 | ['064051228', false],
24 | ];
25 | }
26 |
27 | /**
28 | * @dataProvider postalCodeProvider
29 | * @param mixed $value
30 | * @param boolean $expected
31 | * @return array
32 | */
33 | public function testPostalCode($value, $expected)
34 | {
35 | $rule = $this->getRule('postalCode');
36 | $validatorMake = $this->validatorMake($rule, $value);
37 | $this->assertEquals($expected, $validatorMake->passes());
38 | }
39 |
40 | /**
41 | * Street Data Provider
42 | * @return array
43 | */
44 | public function streetProvider()
45 | {
46 | return $this->getWithStrBaseWithRequired('NOME RUA', 10);
47 | }
48 |
49 | /**
50 | * @dataProvider streetProvider
51 | * @param mixed $value
52 | * @param boolean $expected
53 | * @return array
54 | */
55 | public function testStreet($value, $expected)
56 | {
57 | $rule = $this->getRule('street');
58 | $validatorMake = $this->validatorMake($rule, $value);
59 | $this->assertEquals($expected, $validatorMake->passes());
60 | }
61 |
62 | /**
63 | * Complement Data Provider
64 | * @return array
65 | */
66 | public function complementProvider()
67 | {
68 | $data = $this->getWithStrBaseWithRequired('COMP', 10, false);
69 | $data[] = ['Number 43', true];
70 | return $data;
71 | }
72 |
73 | /**
74 | * @dataProvider complementProvider
75 | * @param mixed $value
76 | * @param boolean $expected
77 | * @return array
78 | */
79 | public function testComplement($value, $expected)
80 | {
81 | $rule = $this->getRule('complement');
82 | $validatorMake = $this->validatorMake($rule, $value);
83 | $this->assertEquals($expected, $validatorMake->passes());
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/tests/unit/Checkout/CheckoutBase.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class CheckoutBase extends TestCase
14 | {
15 | /**
16 | * @var SimpleCheckout
17 | */
18 | protected $checkout;
19 |
20 | /**
21 | * SetUp
22 | */
23 | public function setUp()
24 | {
25 | $facade = new Checkout();
26 | $this->checkout = $facade->createFromArray([
27 | 'items' => $this->getItems(),
28 | 'sender' => $this->getSender(),
29 | 'shipping' => $this->getShipping(),
30 | 'redirectURL' => 'http://www.meusite.com.br',
31 | 'notificationURL' => 'http://www.meusite.com.br/notification'
32 | ]);
33 | }
34 |
35 | /**
36 | * Get Items to Test
37 | */
38 | public function getItems()
39 | {
40 | return [
41 | [
42 | 'id' => '18',
43 | 'description' => 'Laravel PS',
44 | 'quantity' => '40',
45 | 'amount' => '784.6',
46 | 'weight' => '45',
47 | 'shippingCost' => '666',
48 | 'width' => '665',
49 | 'height' => '445',
50 | 'length' => '669',
51 | ],
52 | ];
53 | }
54 |
55 | /**
56 | * Get Sender to Test
57 | */
58 | public function getSender()
59 | {
60 | return [
61 | 'email' => 'isaquesb@gmail.com',
62 | 'name' => 'Isaque de Souza Barbosa',
63 | 'documents' => [
64 | [
65 | 'number' => '80808080822',
66 | 'type' => 'CPF'
67 | ]
68 | ],
69 | 'phone' => [
70 | 'number' => '985445522',
71 | 'areaCode' => '11',
72 | ],
73 | 'bornDate' => '1988-03-25',
74 | ];
75 | }
76 |
77 | /**
78 | * Get Shipping to Test
79 | */
80 | public function getShipping()
81 | {
82 | return [
83 | 'address' => [
84 | 'postalCode' => '06410030',
85 | 'street' => 'Rua da Selva',
86 | 'number' => '12',
87 | 'district' => 'Jardim dos Camargos',
88 | 'city' => 'Barueri',
89 | 'state' => 'SP',
90 | 'country' => 'BRA',
91 | ],
92 | 'type' => 2,
93 | 'cost' => 30.4,
94 | ];
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/tests/unit/Document/CNPJ/CNPJTest.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class CNPJTest extends \PHPUnit\Framework\TestCase
12 | {
13 |
14 | public function testEmptyCNPJ()
15 | {
16 | $cnpj = new CNPJ();
17 | $this->assertEquals([
18 | 'number' => null,
19 | ], $cnpj->toArray());
20 | }
21 |
22 | public function testCnpj()
23 | {
24 | $data = [
25 | 'number' => '51815418000198',
26 | ];
27 | $cnpj = new CNPJ($data);
28 | $this->assertEquals($data, $cnpj->toArray());
29 | $this->assertEquals($data['number'], $cnpj->getNumber());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/unit/Document/CNPJ/ValidationRulesTest.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class ValidationRulesTest extends \laravel\pagseguro\Tests\Unit\ValidationRules
12 | {
13 |
14 | /**
15 | * @param string $key
16 | * @return mixed
17 | */
18 | protected function getRule($key)
19 | {
20 | if (!$this->rules) {
21 | $o = new ValidationRules();
22 | $this->rules = $o->getRules();
23 | }
24 | return $this->rules[$key];
25 | }
26 |
27 | /**
28 | * Email Data Provider
29 | * @return array
30 | */
31 | public function numberProvider()
32 | {
33 | return [
34 | ['', false],
35 | ['987654321', false],
36 | ['9876543210', false],
37 | ['87654321', false],
38 | ['8765432', false],
39 | ['phone123456789', false],
40 | ['51815418000198', true],
41 | ['109876543210', false],
42 | ];
43 | }
44 |
45 | /**
46 | * @dataProvider numberProvider
47 | * @param mixed $value
48 | * @param boolean $expected
49 | * @return array
50 | */
51 | public function testNumber($value, $expected)
52 | {
53 | $rule = $this->getRule('number');
54 | $v = $this->validatorMake($rule, $value);
55 | $this->assertEquals($expected, $v->passes());
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/unit/Document/CPF/CPFTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class CPFTest extends TestCase
13 | {
14 |
15 | public function testEmptyCPF()
16 | {
17 | $cpf = new CPF();
18 | $this->assertEquals([
19 | 'number' => null,
20 | ], $cpf->toArray());
21 | }
22 |
23 | public function testCpf()
24 | {
25 | $data = [
26 | 'number' => '10987654321',
27 | ];
28 | $cpf = new CPF($data);
29 | $this->assertEquals($data, $cpf->toArray());
30 | $this->assertEquals($data['number'], $cpf->getNumber());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/unit/Document/CPF/ValidationRulesTest.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class ValidationRulesTest extends \laravel\pagseguro\Tests\Unit\ValidationRules
12 | {
13 |
14 | /**
15 | * @param string $key
16 | * @return mixed
17 | */
18 | protected function getRule($key)
19 | {
20 | if (!$this->rules) {
21 | $o = new ValidationRules();
22 | $this->rules = $o->getRules();
23 | }
24 | return $this->rules[$key];
25 | }
26 |
27 | /**
28 | * Email Data Provider
29 | * @return array
30 | */
31 | public function numberProvider()
32 | {
33 | return [
34 | ['', false],
35 | ['987654321', false],
36 | ['9876543210', false],
37 | ['87654321', false],
38 | ['8765432', false],
39 | ['phone123456789', false],
40 | ['10987654321', true],
41 | ['109876543210', false],
42 | ];
43 | }
44 |
45 | /**
46 | * @dataProvider numberProvider
47 | * @param mixed $value
48 | * @param boolean $expected
49 | * @return array
50 | */
51 | public function testNumber($value, $expected)
52 | {
53 | $rule = $this->getRule('number');
54 | $v = $this->validatorMake($rule, $value);
55 | $this->assertEquals($expected, $v->passes());
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/unit/Item/ItemCollectionTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class ItemCollectionTest extends TestCase
14 | {
15 |
16 | /**
17 | * Test With Integer
18 | * @expectedException \InvalidArgumentException Invalid
19 | */
20 | public function testWithInteger()
21 | {
22 | ItemCollection::factory([1]);
23 | }
24 |
25 | /**
26 | * Test With String
27 | * @expectedException \InvalidArgumentException Invalid
28 | */
29 | public function testWithString()
30 | {
31 | ItemCollection::factory(['Meu Item']);
32 | }
33 |
34 | /**
35 | * Test With Object
36 | * @expectedException \InvalidArgumentException Invalid
37 | */
38 | public function testWithObject()
39 | {
40 | $item = new \stdClass();
41 | ItemCollection::factory([$item]);
42 | }
43 |
44 | /**
45 | * Test With Array
46 | */
47 | public function testWithArray()
48 | {
49 | $item = [];
50 | $itemCollection = ItemCollection::factory([$item]);
51 | $this->assertInstanceOf('\laravel\pagseguro\Item\ItemCollection', $itemCollection);
52 | $this->assertCount(1, $itemCollection);
53 | $this->assertEquals(new Item($item), $itemCollection->offsetGet(0));
54 | }
55 |
56 | /**
57 | * Test With Item
58 | */
59 | public function testWithItem()
60 | {
61 | $item = new Item([
62 | 'id' => '1',
63 | 'description' => 'Laravel PS',
64 | 'quantity' => '777',
65 | 'amount' => '888',
66 | 'weight' => '999',
67 | 'shippingCost' => '666',
68 | 'width' => '555',
69 | 'height' => '444',
70 | 'length' => '333',
71 | ]);
72 | $collection = ItemCollection::factory([$item]);
73 | $this->assertInstanceOf('\laravel\pagseguro\Item\ItemCollection', $collection);
74 | $this->assertCount(1, $collection);
75 | $this->assertEquals($item, $collection->offsetGet(0));
76 | }
77 |
78 | /**
79 | * Test With Empty Data
80 | */
81 | public function testWithEmpty()
82 | {
83 | $collection = ItemCollection::factory();
84 | $this->assertInstanceOf('\laravel\pagseguro\Item\ItemCollection', $collection);
85 | $this->assertCount(0, $collection);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/tests/unit/Item/ItemTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class ItemTest extends TestCase
13 | {
14 |
15 | public function testEmptyItem()
16 | {
17 | $item = new Item();
18 | $this->assertEquals([
19 | 'id' => null,
20 | 'description' => null,
21 | 'quantity' => null,
22 | 'amount' => null,
23 | 'weight' => null,
24 | 'shippingCost' => null,
25 | 'width' => null,
26 | 'height' => null,
27 | 'length' => null,
28 | ], $item->toArray());
29 | }
30 |
31 | public function testFullItem()
32 | {
33 | $data = [
34 | 'description' => 'Laravel PS',
35 | 'quantity' => '777',
36 | 'weight' => '999',
37 | 'shippingCost' => '666',
38 | 'width' => 555,
39 | 'height' => '444',
40 | 'length' => '333',
41 | 'amount' => '888',
42 | 'id' => 1,
43 | ];
44 | $item = new Item($data);
45 | $this->assertEquals($data, $item->toArray());
46 | $this->assertEquals($data['id'], $item->getId());
47 | $this->assertEquals($data['description'], $item->getDescription());
48 | $this->assertEquals($data['quantity'], $item->getQuantity());
49 | $this->assertEquals($data['amount'], $item->getAmount());
50 | $this->assertEquals($data['weight'], $item->getWeight());
51 | $this->assertEquals($data['shippingCost'], $item->getShippingCost());
52 | $this->assertEquals($data['width'], $item->getWidth());
53 | $this->assertEquals($data['height'], $item->getHeight());
54 | $this->assertEquals($data['length'], $item->getLength());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/tests/unit/Notification/NotificationTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class NotificationTest extends TestCase
13 | {
14 |
15 | public function testEmptyNotification()
16 | {
17 | $o = new Notification();
18 | $this->assertEquals([
19 | 'notificationCode' => null,
20 | 'notificationType' => 'transaction',
21 | ], $o->toArray());
22 | }
23 |
24 | public function testWithStringCode()
25 | {
26 | $o = new Notification('012345678901234567890123456789012345678');
27 | $this->assertEquals('012345678901234567890123456789012345678', $o->getNotificationCode());
28 | $this->assertEquals('transaction', $o->getNotificationType());
29 | }
30 |
31 | public function testWithStringCodeAndStringType()
32 | {
33 | $o = new Notification('012345678901234567890123456789012345678', 'transaction');
34 | $this->assertEquals('012345678901234567890123456789012345678', $o->getNotificationCode());
35 | $this->assertEquals('transaction', $o->getNotificationType());
36 | }
37 |
38 | public function testWithArrayCodeOnly()
39 | {
40 | $notification = new Notification(['notificationCode' => '012345678901234567890123456789012345678']);
41 | $this->assertEquals('012345678901234567890123456789012345678', $notification->getNotificationCode());
42 | $this->assertEquals('transaction', $notification->getNotificationType());
43 | }
44 |
45 | public function testWithArrayParams()
46 | {
47 | $data = [
48 | 'notificationCode' => '012345678901234567890123456789012345678',
49 | 'notificationType' => 'transaction',
50 | ];
51 | $notification = new Notification($data);
52 | $this->assertEquals($data, $notification->toArray());
53 | $this->assertEquals($data['notificationCode'], $notification->getNotificationCode());
54 | $this->assertEquals($data['notificationType'], $notification->getNotificationType());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/tests/unit/Notification/ValidationRulesTest.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class ValidationRulesTest extends \laravel\pagseguro\Tests\Unit\ValidationRules
12 | {
13 |
14 | /**
15 | * @param string $key
16 | * @return mixed
17 | */
18 | protected function getRule($key)
19 | {
20 | if(!$this->rules) {
21 | $validationRules = new ValidationRules();
22 | $this->rules = $validationRules->getRules();
23 | }
24 | return $this->rules[$key];
25 | }
26 |
27 | /**
28 | * Code Data Provider
29 | * @return array
30 | */
31 | public function codeProvider()
32 | {
33 | $data = [
34 | ['012345678901234567890123456789012345678', true],
35 | ['0123ABC7890123456789012345678901234567D', true],
36 | ['0123456789012345678901234567890123456789', false],
37 | ['01234567890123456789012345678901234567', false],
38 | ];
39 | $data[] = $this->emptyRequired();
40 | return $data;
41 | }
42 |
43 | /**
44 | * @dataProvider codeProvider
45 | * @param mixed $value
46 | * @param boolean $expected
47 | * @return array
48 | */
49 | public function testCode($value, $expected)
50 | {
51 | $rule = $this->getRule('notificationCode');
52 | $validatorMake = $this->validatorMake($rule, $value);
53 | $this->assertEquals($expected, $validatorMake->passes());
54 | }
55 |
56 | /**
57 | * Type Data Provider
58 | * @return array
59 | */
60 | public function typeProvider()
61 | {
62 | return [
63 | ['', false],
64 | ['transaction', true],
65 | ['notification', false],
66 | ['request', false],
67 | [1, false],
68 | ];
69 | }
70 |
71 | /**
72 | * @dataProvider typeProvider
73 | * @param mixed $value
74 | * @param boolean $expected
75 | * @return array
76 | */
77 | public function testType($value, $expected)
78 | {
79 | $rule = $this->getRule('notificationType');
80 | $validatorMake = $this->validatorMake($rule, $value);
81 | $this->assertEquals($expected, $validatorMake->passes());
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/tests/unit/Parser/XmlTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class XmlTest extends TestCase
13 | {
14 |
15 | protected function getXmlForParseTest()
16 | {
17 | $str = <<
19 |
20 | 0580
21 |
22 | 101
23 |
24 |
25 | -
26 | 0002
27 | Notebook
28 |
29 | -
30 | 0003
31 | Transação
32 |
33 |
34 |
35 | XML;
36 | return $str;
37 | }
38 |
39 | public function testParse()
40 | {
41 | $str = $this->getXmlForParseTest();
42 | $xml = new Xml($str);
43 | $this->assertEquals([
44 | 'id' => '0580',
45 | 'method' => [
46 | 'code' => '101'
47 | ],
48 | 'items' => [
49 | 'item' => [
50 | [
51 | 'id' => '0002',
52 | 'description' => 'Notebook'
53 | ],
54 | [
55 | 'id' => '0003',
56 | 'description' => 'Transação'
57 | ],
58 | ]
59 | ],
60 | ], $xml->toArray());
61 | }
62 |
63 | protected function getOneItemTest()
64 | {
65 | $str = <<
67 |
68 |
69 | -
70 | 0002
71 | Notebook
72 |
73 |
74 |
75 | XML;
76 | return $str;
77 | }
78 |
79 | public function testOneItemParse()
80 | {
81 | $str = $this->getOneItemTest();
82 | $xml = new Xml($str);
83 | $this->assertEquals([
84 | 'items' => [
85 | 'item' => [
86 | 'id' => '0002',
87 | 'description' => 'Notebook'
88 | ]
89 | ],
90 | ], $xml->toArray());
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/tests/unit/Phone/PhoneTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class PhoneTest extends TestCase
13 | {
14 |
15 | public function testStdPhone()
16 | {
17 | $phone = new Phone();
18 | $this->assertEquals([
19 | 'areaCode' => null,
20 | 'countryCode' => '55',
21 | 'number' => null,
22 | ], $phone->toArray());
23 | }
24 |
25 | public function testArrayFactory()
26 | {
27 | $data = [
28 | 'areaCode' => '11',
29 | 'countryCode' => '54',
30 | 'number' => '980848055'
31 | ];
32 | $phone = new Phone($data);
33 | $this->assertEquals($data, $phone->toArray());
34 | $this->assertEquals($data['areaCode'], $phone->getAreaCode());
35 | $this->assertEquals($data['countryCode'], $phone->getCountryCode());
36 | $this->assertEquals($data['number'], $phone->getNumber());
37 | }
38 |
39 | public function testStringFactory()
40 | {
41 | $phone = Phone::factory('5411980848055');
42 | $this->assertEquals('11', $phone->getAreaCode());
43 | $this->assertEquals('54', $phone->getCountryCode());
44 | $this->assertEquals('980848055', $phone->getNumber());
45 | }
46 |
47 | public function testStringFactoryWithoutDdi()
48 | {
49 | $phone = Phone::factory('11980848055');
50 | $this->assertEquals('11', $phone->getAreaCode());
51 | $this->assertEquals('55', $phone->getCountryCode());
52 | $this->assertEquals('980848055', $phone->getNumber());
53 | }
54 |
55 | /**
56 | * @expectedException \InvalidArgumentException
57 | */
58 | public function testStringFactoryWithoutDdiAndDdd()
59 | {
60 | Phone::factory('980848055');
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/tests/unit/Phone/ValidationRulesTest.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class ValidationRulesTest extends \laravel\pagseguro\Tests\Unit\ValidationRules
12 | {
13 |
14 | /**
15 | * @param string $key
16 | * @return mixed
17 | */
18 | protected function getRule($key)
19 | {
20 | if (!$this->rules) {
21 | $validationRules = new ValidationRules();
22 | $this->rules = $validationRules->getRules();
23 | }
24 | return $this->rules[$key];
25 | }
26 |
27 | /**
28 | * Area Code Data Provider
29 | * @return array
30 | */
31 | public function areaCodeProvider()
32 | {
33 | return [
34 | ['', false],
35 | ['32', true],
36 | [44, true],
37 | [11, true],
38 | [110, false],
39 | [1, false],
40 | ['9', false],
41 | ];
42 | }
43 |
44 | /**
45 | * Phone Data Provider
46 | * @return array
47 | */
48 | public function phoneProvider()
49 | {
50 | return [
51 | ['', false],
52 | ['987654321', true],
53 | ['9876543210', false],
54 | [87654321, true],
55 | ['8765432', false],
56 | ['phone123456789', false],
57 | ];
58 | }
59 |
60 | /**
61 | * @dataProvider areaCodeProvider
62 | * @param mixed $value
63 | * @param boolean $expected
64 | * @return array
65 | */
66 | public function testAreaCode($value, $expected)
67 | {
68 | $rule = $this->getRule('areaCode');
69 | $validatorMake = $this->validatorMake($rule, $value);
70 | $this->assertEquals($expected, $validatorMake->passes());
71 | }
72 |
73 | /**
74 | * @dataProvider phoneProvider
75 | * @param mixed $value
76 | * @param boolean $expected
77 | * @return array
78 | */
79 | public function testPhone($value, $expected)
80 | {
81 | $rule = $this->getRule('number');
82 | $validatorMake = $this->validatorMake($rule, $value);
83 | $this->assertEquals($expected, $validatorMake->passes());
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/tests/unit/Sender/SenderTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class SenderTest extends TestCase
14 | {
15 |
16 | public function testEmptySender()
17 | {
18 | $sender = new Sender();
19 | $this->assertEquals([
20 | 'email' => null,
21 | 'name' => null,
22 | 'documents' => null,
23 | 'phone' => null,
24 | 'bornDate' => null,
25 | ], $sender->toArray());
26 |
27 | }
28 |
29 | public function testSenderWithoutPhones()
30 | {
31 | $class = '\\laravel\\pagseguro\\Phone\\Phone';
32 | $data = [
33 | 'email' => 'isaquesb@gmail.com',
34 | 'name' => 'Isaque de Souza',
35 | 'documents' => null,
36 | 'phone' => [],
37 | 'bornDate' => '1988-03-21',
38 | ];
39 | $sender = new Sender($data);
40 | $this->assertInstanceOf($class, $sender->getPhone());
41 | }
42 |
43 | public function testSenderWithoutPhonesKey()
44 | {
45 | $class = '\\laravel\\pagseguro\\Phone\\Phone';
46 | $data = [
47 | 'email' => 'isaquesb@gmail.com',
48 | 'name' => 'Isaque de Souza',
49 | 'documents' => null,
50 | 'bornDate' => '1988-03-21',
51 | ];
52 | $sender = new Sender($data);
53 | $this->assertInstanceOf($class, $sender->getPhone());
54 | }
55 |
56 | public function testSenderWithoutDocuments()
57 | {
58 | $phone = new Phone([]);
59 | $data = [
60 | 'email' => 'isaquesb@gmail.com',
61 | 'name' => 'Isaque de Souza',
62 | 'documents' => null,
63 | 'phone' => [],
64 | 'bornDate' => '1988-03-21',
65 | ];
66 | $sender = new Sender($data);
67 |
68 | $this->assertEquals($data['email'], $sender->getEmail());
69 | $this->assertEquals($data['name'], $sender->getName());
70 | $this->assertEquals($data['documents'], $sender->getDocuments());
71 | $this->assertEquals($data['bornDate'], $sender->getBornDate());
72 |
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/tests/unit/Shipping/ShippingTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class ShippingTest extends TestCase
14 | {
15 |
16 | public function testEmptySender()
17 | {
18 | $shipping = new Shipping();
19 | $this->assertEquals([
20 | 'address' => null,
21 | 'type' => null,
22 | 'cost' => null,
23 | ], $shipping->toArray());
24 | }
25 |
26 | public function testSenderWithoutPhonesAndDocuments()
27 | {
28 | $data = [
29 | 'address' => new Address([
30 | 'postalCode' => '06410000',
31 | 'street' => 'Rua da prata',
32 | 'number' => '55',
33 | 'complement' => '',
34 | 'district' => 'Jardim dos Camargos',
35 | 'city' => 'Barueri',
36 | 'state' => 'SP',
37 | 'country' => 'Brasil',
38 | ]),
39 | 'type' => 1,
40 | 'cost' => 25.78,
41 | ];
42 | $shipping = new Shipping($data);
43 | $this->assertEquals($data, $shipping->toArray());
44 | $this->assertEquals($data['address'], $shipping->getAddress());
45 | $this->assertEquals($data['type'], $shipping->getType());
46 | $this->assertEquals($data['cost'], $shipping->getCost());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tests/unit/Shipping/ValidationRulesTest.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class ValidationRulesTest extends \laravel\pagseguro\Tests\Unit\ValidationRules
12 | {
13 |
14 | /**
15 | * @param string $key
16 | * @return mixed
17 | */
18 | protected function getRule($key)
19 | {
20 | if (!$this->rules) {
21 | $validationRules = new ValidationRules();
22 | $this->rules = $validationRules->getRules();
23 | }
24 | return $this->rules[$key];
25 | }
26 |
27 | /**
28 | * Type Data Provider
29 | * @return array
30 | */
31 | public function typeProvider()
32 | {
33 | return [
34 | ['', false],
35 | ['12', false],
36 | ['BBT', false],
37 | [1010, false],
38 | [-1, false],
39 | [0, false],
40 | [1, true],
41 | [2, true],
42 | [3, true],
43 | ];
44 | }
45 |
46 | /**
47 | * @dataProvider numericRequiredUnsignedProvider
48 | * @param mixed $value
49 | * @param boolean $expected
50 | * @return array
51 | */
52 | public function testCost($value, $expected)
53 | {
54 | $rule = $this->getRule('cost');
55 | $validatorMake = $this->validatorMake($rule, $value);
56 | $this->assertEquals($expected, $validatorMake->passes());
57 | }
58 |
59 | /**
60 | * @dataProvider typeProvider
61 | * @param mixed $value
62 | * @param boolean $expected
63 | * @return array
64 | */
65 | public function testType($value, $expected)
66 | {
67 | $rule = $this->getRule('type');
68 | $validatorMake = $this->validatorMake($rule, $value);
69 | $this->assertEquals($expected, $validatorMake->passes());
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/tests/unit/Transaction/Information/simple-response.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2011-02-10T16:13:41.000-03:00
4 | 9E884542-81B3-4419-9A75-BCC6FB495EF1
5 | REF1234
6 | 1
7 | 3
8 | 2011-02-15T17:39:14.000-03:00
9 |
10 | 1
11 | 101
12 |
13 | 49900.00
14 | 0.00
15 | 1.10
16 | 49909.00
17 | 5.00
18 | 1
19 | 2
20 |
21 | -
22 | 0001
23 | Notebook Prata
24 | 1
25 | 24300.00
26 |
27 | -
28 | 0002
29 | Notebook Rosa
30 | 1
31 | 25600.00
32 |
33 |
34 |
35 | José Comprador
36 | comprador@uol.com.br
37 |
38 | 11
39 | 56273440
40 |
41 |
42 |
43 | CPF
44 | 40404040411
45 |
46 |
47 |
48 |
49 |
50 | Av. Brig. Faria Lima
51 | 1384
52 | 5o andar
53 | Jardim Paulistano
54 | 01452002
55 | Sao Paulo
56 | SP
57 | BRA
58 |
59 | 1
60 | 21.69
61 |
62 |
--------------------------------------------------------------------------------
/tests/unit/Transaction/StatusTest.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class StatusTest extends TestCase
13 | {
14 |
15 | /**
16 | * @expectedException \InvalidArgumentException Invalid
17 | */
18 | public function createProvider()
19 | {
20 | return [
21 | [0, 0, 'Iniciada'],
22 | [1, 1, 'Aguardando pagamento'],
23 | [2, 2, 'Em análise'],
24 | [3, 3, 'Paga'],
25 | [4, 4, 'Disponível'],
26 | [5, 5, 'Em disputa'],
27 | [6, 6, 'Devolvida'],
28 | [7, 7, 'Cancelada'],
29 | [8, 8, 'Chargeback'],
30 | [9, 9, 'Contestada']
31 | ];
32 | }
33 |
34 | /**
35 | * @dataProvider createProvider
36 | * @param mixed $value
37 | * @param int $expectedCode
38 | * @param string $expectedLabel
39 | * @return array
40 | */
41 | public function testCodeAndName($value, $expectedCode, $expectedLabel)
42 | {
43 | $status = new Status($value);
44 | $this->assertEquals($expectedCode, $status->getCode());
45 | $this->assertEquals($expectedLabel, $status->getName());
46 | }
47 |
48 | /**
49 | * @expectedException \InvalidArgumentException
50 | */
51 | public function testInvalid()
52 | {
53 | new Status('Cancelada');
54 | }
55 |
56 | public function testInitilized()
57 | {
58 | $status = new Status(Status::INITIALIZED);
59 | $this->assertFalse($status->finished());
60 | }
61 |
62 | public function testAwaiting()
63 | {
64 | $status = new Status(Status::AWAITING_PAYMENT);
65 | $this->assertFalse($status->canDispatch());
66 | }
67 |
68 | public function testReview()
69 | {
70 | $status = new Status(Status::REVIEW);
71 | $this->assertFalse($status->finished());
72 | $this->assertFalse($status->canceled());
73 | }
74 |
75 | public function testPaid()
76 | {
77 | $status = new Status(Status::PAID);
78 | $this->assertFalse($status->finished());
79 | $this->assertFalse($status->canceled());
80 | $this->assertTrue($status->canDispatch());
81 | }
82 |
83 | public function testCanceled()
84 | {
85 | $status = new Status(Status::CANCELED);
86 | $this->assertTrue($status->finished());
87 | $this->assertTrue($status->canceled());
88 | $this->assertFalse($status->canDispatch());
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/tests/unit/Transaction/TransactionTest.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class TransactionTest extends TestCase
14 | {
15 |
16 | /**
17 | * @expectedException \InvalidArgumentException Invalid
18 | */
19 | public function testWithNumericTransactionCode()
20 | {
21 | $credential = new Credentials('ASD', 'isaquesb@gmail.com');
22 | new Transaction(123456, $credential, false);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/unit/bootstrap.php:
--------------------------------------------------------------------------------
1 |