/**
  * test whether metadata is created with given values
  */
 public function testCreate()
 {
     $customer = new Customer(['name' => 'Gorbadoc Oldbuck', 'cpf' => '04267484171', 'phone_number' => '5144916523', 'email' => '*****@*****.**', 'birth' => '1977-01-15']);
     $billingAddress = new Address(['street' => 'Av. JK', 'number' => 909, 'neighborhood' => 'Bauxita', 'zipcode' => '35400000', 'city' => 'Ouro Preto', 'state' => 'MG']);
     $model = new CreditCard(['installments' => 1, 'billing_address' => $billingAddress, 'payment_token' => '6426f3abd8688639c6772963669bbb8e0eb3c319', 'customer' => $customer]);
     $this->assertTrue($model->validate());
 }
 /**
  * pay a charge
  *
  * @param CreditCard|Billet $paymentType
  * @return bool
  */
 public function payCharge($paymentType)
 {
     if (empty($this->customer)) {
         throw new BadMethodCallException("You need to set the customer.");
     }
     if (empty($this->chargeId)) {
         throw new BadMethodCallException("Ops. Did you charge? It is missing the charge id");
     }
     $params = ['id' => $this->chargeId];
     $body = ['payment' => []];
     $model = null;
     if ($paymentType instanceof Billet) {
         $model = new Billet($paymentType);
         $model->customer = $this->customer;
         if (!$model->validate()) {
             $this->errors = $model->errors;
             return false;
         }
         $body['payment'] = ['banking_billet' => $model->toArray()];
     } elseif ($paymentType instanceof CreditCard) {
         $model = new CreditCard($paymentType);
         $model->customer = $this->customer;
         if (!$model->validate()) {
             $this->errors = $model->errors;
             return false;
         }
         $data = $model->toArray();
         if (empty($data['discount'])) {
             unset($data['discount']);
         }
         $body['payment'] = ['credit_card' => $data];
     } else {
         throw new \InvalidArgumentException("The param should be an instance of Billet or CreditCard.");
     }
     $data = $this->getApi()->payCharge($params, $body);
     if (!empty($data['code']) && $data['code'] == 200) {
         $this->refresh();
     }
     return $data;
 }