/** * 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; }
/** * 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']); $model = new Billet(['expire_at' => '2018-12-12', 'customer' => $customer, 'instructions' => ['Pay only with money', 'Do not pay with gold']]); $this->assertTrue($model->validate()); }