|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace GlobalPayments\Api\Tests\Integration\Gateways\PorticoConnector; |
| 4 | + |
| 5 | +use GlobalPayments\Api\Entities\Address; |
| 6 | +use GlobalPayments\Api\Entities\Enums\AccountType; |
| 7 | +use GlobalPayments\Api\Entities\Enums\CheckType; |
| 8 | +use GlobalPayments\Api\Entities\Enums\EntryMethod; |
| 9 | +use GlobalPayments\Api\Entities\Enums\SecCode; |
| 10 | +use GlobalPayments\Api\PaymentMethods\ECheck; |
| 11 | +use GlobalPayments\Api\ServicesConfig; |
| 12 | +use GlobalPayments\Api\ServicesContainer; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +class AchTest extends TestCase |
| 16 | +{ |
| 17 | + protected $eCheck; |
| 18 | + protected $SUPTeCheck; |
| 19 | + protected $address; |
| 20 | + private $enableCryptoUrl = true; |
| 21 | + |
| 22 | + public function setup() |
| 23 | + { |
| 24 | + $this->eCheck = new ECheck(); |
| 25 | + $this->eCheck->accountNumber = '1357902468'; |
| 26 | + $this->eCheck->routingNumber = '122000030'; |
| 27 | + $this->eCheck->checkType = CheckType::PERSONAL; |
| 28 | + $this->eCheck->secCode = SecCode::PPD; |
| 29 | + $this->eCheck->accountType = AccountType::CHECKING; |
| 30 | + $this->eCheck->entryMode = EntryMethod::MANUAL; |
| 31 | + $this->eCheck->checkHolderName = 'John Doe'; |
| 32 | + $this->eCheck->driversLicenseNumber = '09876543210'; |
| 33 | + $this->eCheck->driversLicenseState = 'TX'; |
| 34 | + $this->eCheck->phoneNumber = '8003214567'; |
| 35 | + $this->eCheck->birthYear = '1997'; |
| 36 | + $this->eCheck->ssnLast4 = '4321'; |
| 37 | + |
| 38 | + $this->SUPTeCheck = new ECheck(); |
| 39 | + $this->SUPTeCheck->token = $this->getACHToken(); |
| 40 | + $this->SUPTeCheck->checkType = CheckType::PERSONAL; |
| 41 | + $this->SUPTeCheck->secCode = SecCode::PPD; |
| 42 | + $this->SUPTeCheck->accountType = AccountType::CHECKING; |
| 43 | + $this->SUPTeCheck->checkHolderName = 'John Doe'; |
| 44 | + |
| 45 | + $this->address = new Address(); |
| 46 | + $this->address->streetAddress1 = '123 Main St.'; |
| 47 | + $this->address->city = 'Downtown'; |
| 48 | + $this->address->state = 'NJ'; |
| 49 | + $this->address->postalCode = '12345'; |
| 50 | + |
| 51 | + ServicesContainer::configure($this->getConfig()); |
| 52 | + } |
| 53 | + |
| 54 | + public function testCheckSale() |
| 55 | + { |
| 56 | + $response = $this->eCheck->charge(11) |
| 57 | + ->withCurrency('USD') |
| 58 | + ->withAddress($this->address) |
| 59 | + ->execute(); |
| 60 | + $this->assertNotNull($response); |
| 61 | + $this->assertEquals('00', $response->responseCode); |
| 62 | + } |
| 63 | + |
| 64 | + public function testSUPTCheckSale() |
| 65 | + { |
| 66 | + $response = $this->SUPTeCheck->charge('11.01') |
| 67 | + ->withCurrency('USD') |
| 68 | + ->withAddress($this->address) |
| 69 | + ->execute(); |
| 70 | + $this->assertNotNull($response); |
| 71 | + $this->assertEquals('00', $response->responseCode); |
| 72 | + } |
| 73 | + |
| 74 | + protected function getConfig() |
| 75 | + { |
| 76 | + $config = new ServicesConfig(); |
| 77 | + $config->secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; |
| 78 | + $config->serviceUrl = ($this->enableCryptoUrl) ? |
| 79 | + 'https://cert.api2-c.heartlandportico.com/': |
| 80 | + 'https://cert.api2.heartlandportico.com'; |
| 81 | + return $config; |
| 82 | + } |
| 83 | + |
| 84 | + protected function getACHToken() |
| 85 | + { |
| 86 | + $payload = array( |
| 87 | + 'object' => 'token', |
| 88 | + 'token_type' => 'supt', |
| 89 | + 'ach' => array( |
| 90 | + 'account_number' => '1357902468', |
| 91 | + 'routing_number' => '122000030', |
| 92 | + ), |
| 93 | + ); |
| 94 | + $url = 'https://cert.api2-c.heartlandportico.com/Hps.Exchange.PosGateway.Hpf.v1/api/token?api_key=pkapi_cert_jKc1FtuyAydZhZfbB3'; |
| 95 | + $options = array( |
| 96 | + 'http' => array( |
| 97 | + 'header' => "Content-Type: application/json\r\n", |
| 98 | + 'method' => 'POST', |
| 99 | + 'content' => json_encode($payload), |
| 100 | + ), |
| 101 | + ); |
| 102 | + $context = stream_context_create($options); |
| 103 | + $response = json_decode(file_get_contents($url, false, $context)); |
| 104 | + if (!$response || isset($response->error)) { |
| 105 | + $this->fail('no single-use token obtained'); |
| 106 | + } |
| 107 | + return $response->token_value; |
| 108 | + } |
| 109 | +} |
0 commit comments