This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Moip\Tests; |
||
| 4 | |||
| 5 | use Moip\Auth\OAuth; |
||
| 6 | use Moip\Moip; |
||
| 7 | use Moip\Resource\Customer; |
||
| 8 | use Moip\Resource\Holder; |
||
| 9 | use Moip\Resource\Orders; |
||
| 10 | use PHPUnit\Framework\TestCase as BaseTestCase; |
||
| 11 | use Requests_Response; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * class TestCase. |
||
| 15 | */ |
||
| 16 | abstract class TestCase extends BaseTestCase |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Variables representing the test modes. On MOCK mode no http request will be made. |
||
| 20 | * In SANDBOX mode HTTP requests will be made to the Moip::SANDBOX_ENDPOINT, the authentication information |
||
| 21 | * is retrieved from the MOIP_TOKEN and MOIP_KEY environment variables. |
||
| 22 | */ |
||
| 23 | const MOCK = 'mock'; |
||
| 24 | const SANDBOX = 'sandbox'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Intance of \Moip\Moip. |
||
| 28 | * |
||
| 29 | * @var \Moip\Moip |
||
| 30 | * */ |
||
| 31 | protected $moip; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string current format for dates. |
||
| 35 | */ |
||
| 36 | protected $date_format = 'Y-m-d'; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string date used for testing. |
||
| 40 | */ |
||
| 41 | protected $date_string = '1989-06-01'; |
||
| 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; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string response from the order moip API. |
||
| 51 | */ |
||
| 52 | protected $body_order; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string response from moip API. |
||
| 56 | */ |
||
| 57 | protected $body_cc_pay_pci; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string response from moip API. |
||
| 61 | */ |
||
| 62 | protected $body_cc_pay_pci_store; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var string response from moip API. |
||
| 66 | */ |
||
| 67 | protected $body_cc_pay_pci_escrow; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string response from moip API. |
||
| 71 | */ |
||
| 72 | protected $body_release_escrow; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string response from moip API. |
||
| 76 | */ |
||
| 77 | protected $body_billet_pay; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string response from moip API. |
||
| 81 | */ |
||
| 82 | protected $body_refund_full_bankaccount; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string response from moip API. |
||
| 86 | */ |
||
| 87 | protected $body_refund_partial_bankaccount; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string response from moip API. |
||
| 91 | */ |
||
| 92 | protected $body_notification_preference; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string response from moip API. |
||
| 96 | */ |
||
| 97 | protected $body_moip_account_create; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string response from moip API. |
||
| 101 | */ |
||
| 102 | protected $body_moip_account_get; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var string response from moip API. |
||
| 106 | */ |
||
| 107 | protected $body_order_list; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var string response from moip API. |
||
| 111 | */ |
||
| 112 | protected $body_notification_list; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var string response from moip API. |
||
| 116 | */ |
||
| 117 | protected $body_transfers_create; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var string response from moip API. |
||
| 121 | */ |
||
| 122 | protected $body_transfers_list; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var string response from moip API. |
||
| 126 | */ |
||
| 127 | protected $body_transfers_revert; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @var string response from moip API. |
||
| 131 | */ |
||
| 132 | protected $body_bank_account_create; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @var string response from moip API. |
||
| 136 | */ |
||
| 137 | protected $body_bank_account_list; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @var string response from moip API. |
||
| 141 | */ |
||
| 142 | protected $body_bank_account_update; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @var string response from moip API. |
||
| 146 | */ |
||
| 147 | protected $body_balances; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @var string holds the last generated customer ownId. In mock mode it'll be always the default, but it changes on sandbox mode. |
||
| 151 | */ |
||
| 152 | protected $last_cus_id = 'meu_id_customer'; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @var string same as `$last_cus_id` but for orders. |
||
| 156 | * |
||
| 157 | * @see $last_cus_id |
||
| 158 | */ |
||
| 159 | protected $last_ord_id = 'meu_id_pedido'; |
||
| 160 | protected $sandbox_mock = self::MOCK; |
||
| 161 | |||
| 162 | public function __construct() |
||
| 163 | { |
||
| 164 | parent::__construct(); |
||
| 165 | |||
| 166 | $this->body_client = $this->readJsonFile('jsons/customer/create'); |
||
| 167 | |||
| 168 | $this->body_order = $this->readJsonFile('jsons/order/create'); |
||
| 169 | |||
| 170 | $this->body_cc_pay_pci = $this->readJsonFile('jsons/payment/create_cc_pci'); |
||
| 171 | |||
| 172 | $this->body_cc_pay_pci_store = $this->readJsonFile('jsons/payment/create_cc_pci_store'); |
||
| 173 | |||
| 174 | $this->body_cc_pay_pci_escrow = $this->readJsonFile('jsons/payment/create_cc_pci_escrow'); |
||
| 175 | |||
| 176 | $this->body_release_escrow = $this->readJsonFile('jsons/escrow/release'); |
||
| 177 | |||
| 178 | $this->body_billet_pay = $this->readJsonFile('jsons/payment/create_billet'); |
||
| 179 | |||
| 180 | $this->body_billet_multipay = $this->readJsonFile('jsons/multipayment/create_billet'); |
||
| 181 | |||
| 182 | $this->body_refund_full_bankaccount = $this->readJsonFile('jsons/refund/full_bankaccount'); |
||
| 183 | |||
| 184 | $this->body_cc_multipay = $this->readJsonFile('jsons/multipayment/create_cc'); |
||
| 185 | |||
| 186 | $this->body_notification_preference = $this->readJsonFile('jsons/notification/create'); |
||
| 187 | |||
| 188 | $this->body_moip_account_create = $this->readJsonFile('jsons/account/create'); |
||
| 189 | |||
| 190 | $this->body_moip_account_get = $this->readJsonFile('jsons/account/get'); |
||
| 191 | |||
| 192 | $this->body_order_list = $this->readJsonFile('jsons/order/get_list'); |
||
| 193 | |||
| 194 | $this->body_add_credit_card = $this->readJsonFile('jsons/customer/add_credit_card'); |
||
| 195 | |||
| 196 | $this->body_list_webhook_no_filter = $this->readJsonFile('jsons/webhooks/get_no_filter'); |
||
| 197 | |||
| 198 | $this->body_list_webhook_pagination = $this->readJsonFile('jsons/webhooks/get_pagination'); |
||
| 199 | |||
| 200 | $this->body_list_webhook_all_filters = $this->readJsonFile('jsons/webhooks/get_all_filters'); |
||
| 201 | |||
| 202 | $this->body_notification_list = $this->readJsonFile('jsons/notification/list'); |
||
| 203 | |||
| 204 | $this->body_multiorder = $this->readJsonFile('jsons/multiorder/create'); |
||
| 205 | |||
| 206 | $this->body_cc_delay_capture = $this->readJsonFile('jsons/payment/create_cc_delay_capture'); |
||
| 207 | |||
| 208 | $this->body_capture_pay = $this->readJsonFile('jsons/payment/capture'); |
||
| 209 | |||
| 210 | $this->body_capture_multipay = $this->readJsonFile('jsons/multipayment/capture'); |
||
| 211 | |||
| 212 | $this->body_cancel_pay = $this->readJsonFile('jsons/payment/cancel_pre_authorized'); |
||
| 213 | |||
| 214 | $this->body_cancel_multipay = $this->readJsonFile('jsons/multipayment/cancel_pre_authorized'); |
||
| 215 | |||
| 216 | $this->body_get_pay = $this->readJsonFile('jsons/payment/get'); |
||
| 217 | |||
| 218 | $this->body_get_multipay = $this->readJsonFile('jsons/multipayment/get'); |
||
| 219 | |||
| 220 | $this->body_keys = $this->readJsonFile('jsons/keys/get'); |
||
| 221 | |||
| 222 | $this->body_transfers_create = $this->readJsonFile('jsons/transfers/create'); |
||
| 223 | |||
| 224 | $this->body_transfers_list = $this->readJsonFile('jsons/transfers/list'); |
||
| 225 | |||
| 226 | $this->body_transfers_revert = $this->readJsonFile('jsons/transfers/revert'); |
||
| 227 | |||
| 228 | $this->body_keys = $this->readJsonFile('jsons/keys/get'); |
||
| 229 | |||
| 230 | $this->body_order_refund_full_bankaccount = $this->readJsonFile('jsons/refund/order_full_bankaccount'); |
||
| 231 | |||
| 232 | $this->body_payment_refund_full_bankaccount = $this->readJsonFile('jsons/refund/payment_full_bankaccount'); |
||
| 233 | |||
| 234 | $this->body_order_refund_partial_bankaccount = $this->readJsonFile('jsons/refund/order_partial_bankaccount'); |
||
| 235 | |||
| 236 | $this->body_payment_refund_partial_bankaccount = $this->readJsonFile('jsons/refund/payment_partial_bankaccount'); |
||
| 237 | |||
| 238 | $this->body_order_refund_full_cc = $this->readJsonFile('jsons/refund/order_full_cc'); |
||
| 239 | |||
| 240 | $this->body_payment_refund_full_cc = $this->readJsonFile('jsons/refund/payment_full_cc'); |
||
| 241 | |||
| 242 | $this->body_order_refund_partial_cc = $this->readJsonFile('jsons/refund/order_partial_cc'); |
||
| 243 | |||
| 244 | $this->body_payment_refund_partial_cc = $this->readJsonFile('jsons/refund/payment_partial_cc'); |
||
| 245 | |||
| 246 | $this->body_bank_account_create = $this->readJsonFile('jsons/bank_account/create'); |
||
| 247 | |||
| 248 | $this->body_bank_account_list = $this->readJsonFile('jsons/bank_account/list'); |
||
| 249 | |||
| 250 | $this->body_bank_account_update = $this->readJsonFile('jsons/bank_account/update'); |
||
| 251 | |||
| 252 | $this->body_balances = $this->readJsonFile('jsons/balances/get'); |
||
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Sets up the fixture, for example, open a network connection. |
||
| 257 | * This method is called before a test is executed. |
||
| 258 | */ |
||
| 259 | public function setUp() |
||
| 260 | { |
||
| 261 | // check if we can run the request on sandbox |
||
| 262 | $moip_access_token = getenv('MOIP_ACCESS_TOKEN'); |
||
| 263 | |||
| 264 | if ($moip_access_token) { |
||
| 265 | $this->sandbox_mock = self::SANDBOX; |
||
| 266 | $auth = new OAuth($moip_access_token); |
||
| 267 | } else { |
||
| 268 | $this->sandbox_mock = self::MOCK; |
||
| 269 | $auth = $this->getMockBuilder('\Moip\Contracts\Authentication')->getMock(); |
||
| 270 | } |
||
| 271 | $this->moip = new Moip($auth, Moip::ENDPOINT_SANDBOX); |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Method to read JSON from a file. |
||
| 276 | * |
||
| 277 | * @param string $filename location of file |
||
| 278 | */ |
||
| 279 | public function readJsonFile($filename) |
||
| 280 | { |
||
| 281 | return file_get_contents($filename.'.json', FILE_USE_INCLUDE_PATH); |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * If in MOCK mode returns a mocked Requests_Sessesion if in SANDBOX mode, creates a new session. |
||
| 286 | * |
||
| 287 | * @param string $body what the request will return |
||
| 288 | * @param int $status_code what http code the request will return |
||
| 289 | */ |
||
| 290 | public function mockHttpSession($body, $status_code = 200) |
||
| 291 | { |
||
| 292 | if ($this->sandbox_mock == self::SANDBOX) { |
||
| 293 | $this->moip->createNewSession(); |
||
| 294 | |||
| 295 | return; |
||
| 296 | } |
||
| 297 | $resp = new Requests_Response(); |
||
| 298 | $resp->body = $body; |
||
| 299 | $resp->status_code = $status_code; |
||
| 300 | $sess = $this->getMockBuilder('\Requests_Session')->getMock(); |
||
| 301 | $sess->expects($this->once())->method('request')->willReturn($resp); |
||
| 302 | $this->moip->setSession($sess); |
||
| 303 | } |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Creates a customer. |
||
| 307 | * |
||
| 308 | * @return Customer |
||
| 309 | */ |
||
| 310 | public function createCustomer() |
||
| 311 | { |
||
| 312 | if ($this->sandbox_mock == self::SANDBOX) { |
||
| 313 | $this->last_cus_id = uniqid('CUS-'); |
||
| 314 | } else { |
||
| 315 | $this->last_cus_id = 'meu_id_sandbox'; |
||
| 316 | } |
||
| 317 | |||
| 318 | $customer = $this->moip->customers()->setOwnId($this->last_cus_id) |
||
| 319 | ->setBirthDate(\DateTime::createFromFormat($this->date_format, $this->date_string)) |
||
| 320 | ->setFullname('Jose Silva') |
||
| 321 | ->setEmail('[email protected]') |
||
| 322 | ->setTaxDocument('22222222222', 'CPF') |
||
| 323 | ->setPhone(11, 66778899, 55) |
||
| 324 | ->addAddress(Customer::ADDRESS_SHIPPING, 'Avenida Faria Lima', '2927', 'Itaim', 'Sao Paulo', 'SP', '01234000', '8'); |
||
| 325 | |||
| 326 | return $customer; |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Creates a holder. |
||
| 331 | * |
||
| 332 | * @return Holder |
||
| 333 | */ |
||
| 334 | public function createHolder() |
||
| 335 | { |
||
| 336 | $holder = $this->moip->holders()->setFullname('Jose Silva') |
||
| 337 | ->setBirthDate(\DateTime::createFromFormat($this->date_format, $this->date_string)) |
||
|
0 ignored issues
–
show
Security
Bug
introduced
by
Loading history...
|
|||
| 338 | ->setTaxDocument('22222222222', 'CPF') |
||
| 339 | ->setPhone(11, 66778899, 55) |
||
| 340 | ->setAddress(Holder::ADDRESS_BILLING, 'Avenida Faria Lima', '2927', 'Itaim', 'Sao Paulo', 'SP', '01234000', '8'); |
||
| 341 | |||
| 342 | return $holder; |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Creates a account. |
||
| 347 | * |
||
| 348 | * @return Account |
||
| 349 | */ |
||
| 350 | public function createAccount() |
||
| 351 | { |
||
| 352 | $moip = new Moip(new OAuth('1tldio91gi74r34zv30d4saz8yuuws5'), Moip::ENDPOINT_SANDBOX); |
||
| 353 | |||
| 354 | $uniqEmail = 'fulano'.uniqid('MPA-').'@detal123.com.br'; |
||
| 355 | |||
| 356 | $account = $moip->accounts() |
||
| 357 | ->setEmail($uniqEmail) |
||
| 358 | ->setName('Fulano') |
||
| 359 | ->setLastName('de Tal') |
||
| 360 | ->setBirthDate('1987-11-27') |
||
| 361 | ->setTaxDocument('22222222222') |
||
| 362 | ->setPhone(11, 988888888) |
||
| 363 | ->addAddress('Av. Ibirapuera', '2035', 'Moema', 'Sao Paulo', 'SP', '04078010') |
||
| 364 | ->setIdentityDocument('411111115', 'SSP', '2000-05-06') |
||
| 365 | ->create(); |
||
| 366 | |||
| 367 | return $account; |
||
| 368 | } |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Creates an order. |
||
| 372 | * |
||
| 373 | * @return Orders |
||
| 374 | */ |
||
| 375 | public function createOrder() |
||
| 376 | { |
||
| 377 | View Code Duplication | if ($this->sandbox_mock == self::SANDBOX) { |
|
| 378 | $this->last_ord_id = uniqid('ORD-'); |
||
| 379 | } else { |
||
| 380 | $this->last_ord_id = 'meu_id_pedido'; |
||
| 381 | } |
||
| 382 | |||
| 383 | $order = $this->moip->orders()->setCustomer($this->createCustomer()) |
||
| 384 | ->addItem('Nome do produto', 1, 'Mais info...', 100000, 'SHOES') |
||
| 385 | ->addItem('abacaxi', 2, 'Abacaxi de terra de areia', 990, 'OTHER_CATEGORIES') |
||
| 386 | ->setDiscount(1000) |
||
| 387 | ->setShippingAmount(1490) |
||
| 388 | ->setOwnId($this->last_ord_id); |
||
| 389 | |||
| 390 | return $order; |
||
| 391 | } |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Creates a multiorder. |
||
| 395 | * |
||
| 396 | * @return Multiorders |
||
| 397 | */ |
||
| 398 | public function createMultiorder() |
||
| 399 | { |
||
| 400 | View Code Duplication | if ($this->sandbox_mock == self::SANDBOX) { |
|
| 401 | $this->last_ord_id = uniqid('MOR-'); |
||
| 402 | } else { |
||
| 403 | $this->last_ord_id = 'meu_id_pedido'; |
||
| 404 | } |
||
| 405 | |||
| 406 | $order = $this->moip->orders()->setOwnId(uniqid()) |
||
| 407 | ->addItem('bicicleta 1', 1, 'sku1', 10000) |
||
| 408 | ->addItem('bicicleta 2', 1, 'sku2', 11000) |
||
| 409 | ->addItem('bicicleta 3', 1, 'sku3', 12000) |
||
| 410 | ->addItem('bicicleta 4', 1, 'sku4', 13000) |
||
| 411 | ->setShippingAmount(3000) |
||
| 412 | ->setAddition(1000) |
||
| 413 | ->setDiscount(5000) |
||
| 414 | ->setCustomer($this->createCustomer()) |
||
| 415 | ->addReceiver('MPA-VB5OGTVPCI52', 'PRIMARY', null); |
||
| 416 | |||
| 417 | $order2 = $this->moip->orders()->setOwnId(uniqid()) |
||
| 418 | ->addItem('bicicleta 1', 1, 'sku1', 10000) |
||
| 419 | ->addItem('bicicleta 2', 1, 'sku2', 11000) |
||
| 420 | ->addItem('bicicleta 3', 1, 'sku3', 12000) |
||
| 421 | ->setShippingAmount(3000) |
||
| 422 | ->setAddition(1000) |
||
| 423 | ->setDiscount(5000) |
||
| 424 | ->setCustomer($this->createCustomer()) |
||
| 425 | ->addReceiver('MPA-IFYRB1HBL73Z', 'PRIMARY', null); |
||
| 426 | |||
| 427 | $multiorder = $this->moip->multiorders() |
||
| 428 | ->setOwnId(uniqid()) |
||
| 429 | ->addOrder($order) |
||
| 430 | ->addOrder($order2); |
||
| 431 | |||
| 432 | return $multiorder; |
||
| 433 | } |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Tears down the fixture, for example, close a network connection. |
||
| 437 | * This method is called after a test is executed. |
||
| 438 | */ |
||
| 439 | public function tearDown() |
||
| 440 | { |
||
| 441 | $this->moip = null; |
||
| 442 | } |
||
| 443 | } |
||
| 444 |