/** * Get a Chargify client instance * * @param string $mockResponseFile Filename containing mocked response * @param string $env (test|dev) * * @return Chargify */ public static function getInstance($mockResponseFile = null, $env = 'test') { $config = array(); switch ($env) { case 'test': $config = (require dirname(__DIR__) . '/configs/ClientConfig.Test.php'); break; case 'dev': $config = (require dirname(__DIR__) . '/configs/ClientConfig.Dev.php'); break; } $chargify = new Chargify($config); if (!empty($mockResponseFile)) { $mock = new MockHandler([Psr7\parse_response(MockResponse::read($mockResponseFile))]); $handler = HandlerStack::create($mock); // $logger = new Logger('Logger'); // $logger->pushHandler(new StreamHandler(dirname(__DIR__) . '/artifacts/logs/guzzle.log', Logger::DEBUG)); // // $middleware = new LoggerMiddleware($logger); // $template = MessageFormatter::DEBUG; // $middleware->setFormatter(new MessageFormatter($template)); // // $handler->push($middleware); $chargify->getHttpClient()->getConfig('handler')->setHandler($handler); } return $chargify; }
public function testReadByChargifyId() { $chargify = new Chargify(array('hostname' => 'fgdfsgdfsgfds', 'api_key' => 'hgfdhdfghd', 'shared_key' => 'hgfdhgfdhg')); // set a mock response on the client $mock = new Mock([MockResponse::read('customer.readByChargifyId.success')]); $chargify->getHttpClient()->getEmitter()->attach($mock); $customer = $chargify->customer()->readByChargifyId(8003316); $this->assertFalse($customer->isError(), '$customer has an error'); }
/** * @todo assert http response code */ public function testNoShippingCreatesError() { $chargify = new Chargify(array('hostname' => 'sdfdsf', 'api_key' => 'fsdfdsf', 'shared_key' => 'fsdfdsf')); // set a mock response on the client $mock = new Mock([MockResponse::read('subscription.error.no_shipping')]); $chargify->getHttpClient()->getEmitter()->attach($mock); $subscription = $chargify->subscription()->setProductId(123)->setCustomerAttributes(array('first_name' => 'Darryl', 'last_name' => 'Strawberry', 'email' => '*****@*****.**', 'organization' => 'Mets'))->setPaymentProfileAttributes(array('first_name' => 'Darryl2', 'last_name' => 'Strawberry2', 'full_number' => '1', 'expiration_month' => '03', 'expiration_year' => '16', 'cvv' => '123', 'billing_address' => '600 N', 'billing_city' => 'Chicago', 'billing_state' => 'IL', 'billing_zip' => '60610', 'billing_country' => 'US'))->create(); // $subscription object should be in an error state $this->assertTrue($subscription->isError()); // get errors from $subscription $errors = $subscription->getErrors(); // check for $this->assertContains('Shipping Address: cannot be blank.', $errors); }
public function testHelperInstances() { $chargify = new Chargify(array('hostname' => 'fdsfs', 'api_key' => 'fdsfds', 'shared_key' => 'fdsfds')); $adjustment = $chargify->adjustment(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Adjustment', $adjustment); $charge = $chargify->charge(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Charge', $charge); $component = $chargify->component(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Component', $component); $coupon = $chargify->coupon(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Coupon', $coupon); $customer = $chargify->customer(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Customer', $customer); $event = $chargify->event(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Event', $event); $product = $chargify->product(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Product', $product); $refund = $chargify->refund(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Refund', $refund); $statement = $chargify->statement(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Statement', $statement); $stats = $chargify->stats(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Stats', $stats); $subscription = $chargify->subscription(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Subscription', $subscription); $transaction = $chargify->transaction(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Transaction', $transaction); $webhook = $chargify->webhook(); $this->assertInstanceOf('Crucial\\Service\\Chargify\\Webhook', $webhook); }