|
3 | 3 | namespace Omnipay\Braintree; |
4 | 4 |
|
5 | 5 | use Omnipay\Tests\GatewayTestCase; |
6 | | -use Omnipay\Common\CreditCard; |
7 | 6 |
|
8 | 7 | class GatewayTest extends GatewayTestCase |
9 | 8 | { |
@@ -124,4 +123,70 @@ public function testClientToken() |
124 | 123 | $request = $this->gateway->clientToken(array()); |
125 | 124 | $this->assertInstanceOf('Omnipay\Braintree\Message\ClientTokenRequest', $request); |
126 | 125 | } |
| 126 | + |
| 127 | + public function testCreateSubscription() |
| 128 | + { |
| 129 | + $request = $this->gateway->createSubscription(array()); |
| 130 | + $this->assertInstanceOf('Omnipay\Braintree\Message\CreateSubscriptionRequest', $request); |
| 131 | + } |
| 132 | + |
| 133 | + public function testCancelSubscription() |
| 134 | + { |
| 135 | + $request = $this->gateway->cancelSubscription('1'); |
| 136 | + $this->assertInstanceOf('Omnipay\Braintree\Message\CancelSubscriptionRequest', $request); |
| 137 | + } |
| 138 | + |
| 139 | + public function testParseNotification() |
| 140 | + { |
| 141 | + if(\Braintree_Version::MAJOR >= 3) { |
| 142 | + $xml = '<notification></notification>'; |
| 143 | + $payload = base64_encode($xml); |
| 144 | + $signature = \Braintree_Digest::hexDigestSha1(\Braintree_Configuration::privateKey(), $payload); |
| 145 | + $gatewayMock = $this->buildGatewayMock($payload); |
| 146 | + $gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest(), $gatewayMock); |
| 147 | + $params = array( |
| 148 | + 'bt_signature' => $payload.'|'.$signature, |
| 149 | + 'bt_payload' => $payload |
| 150 | + ); |
| 151 | + $request = $gateway->parseNotification($params); |
| 152 | + $this->assertInstanceOf('\Braintree_WebhookNotification', $request); |
| 153 | + } else { |
| 154 | + $xml = '<notification><subject></subject></notification>'; |
| 155 | + $payload = base64_encode($xml); |
| 156 | + $signature = \Braintree_Digest::hexDigestSha1(\Braintree_Configuration::privateKey(), $payload); |
| 157 | + $gatewayMock = $this->buildGatewayMock($payload); |
| 158 | + $gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest(), $gatewayMock); |
| 159 | + $params = array( |
| 160 | + 'bt_signature' => $payload.'|'.$signature, |
| 161 | + 'bt_payload' => $payload |
| 162 | + ); |
| 163 | + $request = $gateway->parseNotification($params); |
| 164 | + $this->assertInstanceOf('\Braintree_WebhookNotification', $request); |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * @param $payload |
| 170 | + * |
| 171 | + * @return \Braintree_Gateway |
| 172 | + */ |
| 173 | + protected function buildGatewayMock($payload) |
| 174 | + { |
| 175 | + $configuration = $this->getMockBuilder('\Braintree_Configuration') |
| 176 | + ->disableOriginalConstructor() |
| 177 | + ->setMethods(array( |
| 178 | + 'assertHasAccessTokenOrKeys' |
| 179 | + )) |
| 180 | + ->getMock(); |
| 181 | + $configuration->expects($this->any()) |
| 182 | + ->method('assertHasAccessTokenOrKeys') |
| 183 | + ->will($this->returnValue(null)); |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | + $configuration->setPublicKey($payload); |
| 188 | + |
| 189 | + \Braintree_Configuration::$global = $configuration; |
| 190 | + return \Braintree_Configuration::gateway(); |
| 191 | + } |
127 | 192 | } |
0 commit comments