/** @depends it_can_create_a_creditor */ function test_it_can_get_a_single_creditor(Creditor $old) { $new = $this->api->getCreditor($old->getId()); $this->assertInstanceOf('GoCardless\\Pro\\Models\\Creditor', $new); $this->assertEquals($old->toArray(), $new->toArray()); return $new; }
public function toArray() { $account = array_filter(get_object_vars($this)); if ($this->creditor instanceof Creditor) { unset($account['creditor']); $account['links'] = ['creditor' => $this->creditor->getId()]; } return $account; }
/** * @return array */ public function toArray() { $mandate = array_filter(get_object_vars($this)); if ($this->customer_bank_account instanceof CustomerBankAccount) { unset($mandate['customer_bank_account']); $mandate['links']['customer_bank_account'] = $this->customer_bank_account->getId(); } if ($this->creditor instanceof Creditor) { unset($mandate['creditor']); $mandate['links']['creditor'] = $this->creditor->getId(); } return $mandate; }
/** * Returns the entity as an array (as the API expects) * * @return array */ public function toArray() { $redirectFlow = array_filter(get_object_vars($this)); if ($this->creditor instanceof Creditor) { unset($redirectFlow['creditor']); $redirectFlow['links']['creditor'] = $this->creditor->getId(); } if ($this->mandate instanceof Mandate) { unset($redirectFlow['mandate']); $redirectFlow['links']['mandate'] = $this->mandate->getId(); } return $redirectFlow; }
/** @test */ function it_can_be_converted_an_array_for_the_api() { $redirectFlow = (new RedirectFlow(Creditor::fromArray(['id' => 'CR111']), Mandate::fromArray(['id' => 'MD111'])))->useSepaCore(); $this->assertEquals(['scheme' => 'sepa_core', 'links' => ['creditor' => 'CR111', 'mandate' => 'MD111']], $redirectFlow->toArray()); }
/** * @see https://developer.gocardless.com/pro/#creditors-get-a-single-creditor * * @param $id * * @return Creditor */ public function getCreditor($id) { $response = $this->get(self::CREDITORS, [], $id); return Creditor::fromArray($response); }
/** @test */ function it_can_be_converted_an_array_for_the_api() { $mandate = (new Mandate(CustomerBankAccount::fromArray(['id' => 'BA111']), Creditor::fromArray(['id' => 'CR111'])))->useSepaCore(); $this->assertEquals(['scheme' => 'sepa_core', 'links' => ['customer_bank_account' => 'BA111', 'creditor' => 'CR111']], $mandate->toArray()); }
require __DIR__ . '/vendor/autoload.php'; use GuzzleHttp\Client; use GoCardless\Pro\Api; use GoCardless\Pro\Models\Customer; use GoCardless\Pro\Models\CustomerBankAccount; use GoCardless\Pro\Models\Creditor; use GoCardless\Pro\Models\Mandate; use GoCardless\Pro\Models\Payment; /** * When you sign up for GoCardless pro you will be given an API key by default. * Navigate to the organisation area and scroll to the API section. Grab those keys! * * @link https://manage-sandbox.gocardless.com/organisation * @link https://developer.gocardless.com/pro/#overview-backwards-compatibility */ $api = new Api(new Client(), 'ACCESS_TOKEN', '2015-04-29'); /** On with the show */ $customer = (new Customer())->setFullName('David', 'Cameron')->setAddress('10 Downing Street', 'London', 'SW1A 2AA', 'GB'); $customer = $api->createCustomer($customer); $account = (new CustomerBankAccount())->withAccountDetails('Mr D Cameron', '55997711', '200000', 'GB', $customer); $account = $api->createCustomerBankAccount($account); // You also get a creditor ID automatically when you sign up. $mandate = new Mandate($account, Creditor::withId('CR123')); $mandate = $api->createMandate($mandate); /** * Now lets take some money! */ $payment = (new Payment())->collect(5000, 'GBP')->on('2015-02-16')->using($mandate); $payment = $api->createPayment($payment); $payment->isPendingSubmission(); // true
/** * @return Creditor */ public function get_full_creditor() { return Creditor::fromArray($this->full_creditor_details()); }
/** @test */ function it_can_access_the_required_attributes() { $creditor = new Creditor(); $creditor->setName('The Wine Club'); $this->assertEquals('The Wine Club', $creditor->getName()); }