1 | <?php |
||
15 | abstract class MoipTestCase extends TestCase |
||
16 | { |
||
17 | /** |
||
18 | * Variables representing the test modes. On MOCK mode no http request will be made. |
||
19 | * In SANDBOX mode HTTP requests will be made to the Moip::SANDBOX_ENDPOINT, the authentication information |
||
20 | * is retrieved from the MOIP_TOKEN and MOIP_KEY environment variables. |
||
21 | */ |
||
22 | const MOCK = 'mock'; |
||
23 | const SANDBOX = 'sandbox'; |
||
24 | |||
25 | /** |
||
26 | * Intance of \Moip\Moip. |
||
27 | * |
||
28 | * @var \Moip\Moip |
||
29 | **/ |
||
30 | protected $moip; |
||
31 | |||
32 | /** |
||
33 | * @var string current format for dates. |
||
34 | */ |
||
35 | protected $date_format = 'Y-m-d'; |
||
36 | |||
37 | /** |
||
38 | * @var string date used for testing. |
||
39 | */ |
||
40 | protected $date_string = '1989-06-01'; |
||
41 | |||
42 | //todo: add the ability to use the play(https://github.com/rodrigosaito/mockwebserver-player) files from the jada sdk |
||
43 | //the two responses below were based on the moip Java sdk's test files (https://github.com/moip/moip-sdk-java/) |
||
44 | /** |
||
45 | * @var string response from the client moip API. |
||
46 | */ |
||
47 | protected $body_client = '{"id":"CUS-CFMKXQBZNJQQ","ownId":"meu_id_sandbox","fullname":"Jose Silva","email":"[email protected]","phone":{"countryCode":"55","areaCode":"11","number":"66778899"},"birthDate":"1989-06-01","taxDocument":{"type":"CPF","number":"22222222222"},"shippingAddress":{"street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","state":"SP","country":"BRA","zipCode":"01234000"},"fundingInstruments":[],"createdAt":"2016-02-18T19:55:00.000-02","_links":{"self":{"href":"https://sandbox.moip.com.br/v2/customers/CUS-CFMKXQBZNJQQ"}}}'; |
||
48 | |||
49 | /** |
||
50 | * @var string response from the order moip API. |
||
51 | */ |
||
52 | protected $body_order = '{"id":"ORD-HG479ZEIB7LV","ownId":"meu_id_pedido","status":"CREATED","createdAt":"2016-02-19T12:24:55.849-02","updatedAt":"2016-02-19T12:24:55.849-02","amount":{"total":102470,"fees":0,"refunds":0,"liquid":0,"otherReceivers":0,"currency":"BRL","subtotals":{"shipping":1490,"addition":0,"discount":1000,"items":101980}},"items":[{"price":100000,"detail":"Mais info...","quantity":1,"product":"Nome do produto"},{"price":990,"detail":"Abacaxi de terra de areia","quantity":2,"product":"abacaxi"}],"customer":{"id":"CUS-7U5K9KWG8DBZ","ownId":"meu_id_saasdadadsnasdasddboxssssssssss","fullname":"Jose Silva","createdAt":"2016-02-18T20:03:28.000-02","birthDate":"1989-06-01T00:00:00.000-03","email":"[email protected]","phone":{"countryCode":"55","areaCode":"11","number":"66778899"},"taxDocument":{"type":"CPF","number":"22222222222"},"shippingAddress":{"zipCode":"01234000","street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","district":"Itaim","state":"SP","country":"BRA"},"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/customers/CUS-7U5K9KWG8DBZ"}}},"payments":[],"refunds":[],"entries":[],"events":[{"type":"ORDER.CREATED","createdAt":"2016-02-19T12:24:55.849-02","description":""}],"receivers":[{"moipAccount":{"id":"MPA-7ED9D2D0BC81","login":"[email protected]","fullname":"Carmen Elisabete de Menezes ME"},"type":"PRIMARY","amount":{"total":102470,"fees":0,"refunds":0}}],"shippingAddress":{"zipCode":"01234000","street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","district":"Itaim","state":"SP","country":"BRA"},"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-HG479ZEIB7LV"},"checkout":{"payOnlineBankDebitItau":{"redirectHref":"https://checkout-sandbox.moip.com.br/debit/itau/ORD-HG479ZEIB7LV"},"payCreditCard":{"redirectHref":"https://checkout-sandbox.moip.com.br/creditcard/ORD-HG479ZEIB7LV"},"payBoleto":{"redirectHref":"https://checkout-sandbox.moip.com.br/boleto/ORD-HG479ZEIB7LV"}}}}'; |
||
53 | |||
54 | /** |
||
55 | * @var string response from moip API. |
||
56 | */ |
||
57 | protected $body_cc_pay_pci = '{"id":"PAY-L6J2NKS9OGYU","status":"IN_ANALYSIS","delayCapture":false,"amount":{"total":102470,"fees":5695,"refunds":0,"liquid":96775,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"creditCard":{"id":"CRC-2TJ13YB4Y1WU","brand":"MASTERCARD","first6":"555566","last4":"8884","holder":{"birthdate":"1989-06-01","birthDate":"1989-06-01","taxDocument":{"type":"CPF","number":"22222222222"},"fullname":"Jose Silva"}},"method":"CREDIT_CARD"},"fees":[{"type":"TRANSACTION","amount":5695}],"events":[{"type":"PAYMENT.IN_ANALYSIS","createdAt":"2016-02-19T18:18:54.535-02"},{"type":"PAYMENT.CREATED","createdAt":"2016-02-19T18:18:51.946-02"}],"_links":{"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-8UDL4K9VRJTB","title":"ORD-8UDL4K9VRJTB"},"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-L6J2NKS9OGYU"}},"createdAt":"2016-02-19T18:18:51.944-02","updatedAt":"2016-02-19T18:18:54.535-02"}'; |
||
58 | |||
59 | /** |
||
60 | * @var string holds the last generated customer ownId. In mock mode it'll be always the default, but it changes on sandbox mode. |
||
61 | */ |
||
62 | protected $last_cus_id = 'meu_id_customer'; |
||
63 | |||
64 | /** |
||
65 | * @var string same as `$last_cus_id` but for orders. |
||
66 | * |
||
67 | * @see $last_cus_id |
||
68 | */ |
||
69 | protected $last_ord_id = 'meu_id_pedido'; |
||
70 | |||
71 | protected $sandbox_mock = self::MOCK; |
||
72 | |||
73 | /** |
||
74 | * Sets up the fixture, for example, open a network connection. |
||
75 | * This method is called before a test is executed. |
||
76 | */ |
||
77 | public function setUp() |
||
92 | |||
93 | /** |
||
94 | * If in MOCK mode returns a mocked Requests_Sessesion if in SANDBOX mode, creates a new session. |
||
95 | * |
||
96 | * @param string $body what the request will return |
||
97 | * @param int $status_code what http code the request will return |
||
98 | */ |
||
99 | public function mockHttpSession($body, $status_code = 200) |
||
113 | |||
114 | /** |
||
115 | * Creates a customer. |
||
116 | * |
||
117 | * @return Customer |
||
118 | */ |
||
119 | public function createCustomer() |
||
138 | |||
139 | /** |
||
140 | * Creates an order. |
||
141 | * |
||
142 | * @return Orders |
||
143 | */ |
||
144 | public function createOrder() |
||
161 | |||
162 | /** |
||
163 | * Tears down the fixture, for example, close a network connection. |
||
164 | * This method is called after a test is executed. |
||
165 | */ |
||
166 | public function tearDown() |
||
170 | } |
||
171 |