Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 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);
 }