/** @test */ function it_has_shortcut_methods() { $refund = new Refund(); $payment = Payment::fromArray(['id' => 'PM123']); $refund->of($payment)->returning(100)->totalling(150); $this->assertSame(100, $refund->getAmount()); $this->assertSame(150, $refund->getTotalAmountConfirmation()); $this->assertAttributeSame($payment, 'payment', $refund); }
/** * @return array */ public function toArray() { $refund = array_filter(get_object_vars($this)); if ($this->payment instanceof Payment) { unset($refund['payment']); $refund['links']['payment'] = $this->payment->getId(); } return $refund; }
/** @test */ function it_can_be_created_from_an_api_response() { $payment = Payment::fromArray(['id' => 'PM123', 'created_at' => '2014-05-08T17:01:06.000Z', 'charge_date' => '2014-05-15', 'amount' => '100', 'currency' => 'GBP', 'description' => null, 'status' => 'pending_submission', 'reference' => 'WINEBOX001', 'metadata' => ['order_dispatch_date' => '2014-05-22'], 'amount_refunded' => '0', 'links' => ['mandate' => 'MD123', 'creditor' => 'CR123']]); $this->assertEquals('PM123', $payment->getId()); $this->assertEquals('2014-05-08T17:01:06.000Z', $payment->getCreatedAt()); $this->assertEquals('2014-05-15', $payment->getChargeDate()); $this->assertSame(100, $payment->getAmount()); $this->assertSame('GBP', $payment->getCurrency()); $this->assertNull($payment->getDescription()); $this->assertEquals('pending_submission', $payment->getStatus()); $this->assertEquals('WINEBOX001', $payment->getReference()); $this->assertSame(0, $payment->getAmountRefunded()); }
/** * @see https://developer.gocardless.com/pro/#payments-retry-a-payment * * @param $id * * @return Payment */ public function retryPayment($id) { $response = $this->post(self::PAYMENTS, [], $id . '/actions/retry'); return Payment::fromArray($response); }
/** @depends test_it_can_create_a_payment */ function test_it_can_get_a_single_payment(Payment $old) { $new = $this->api->getPayment($old->getId()); $this->assertEquals($old->toArray(), $new->toArray()); return $new; }