Ejemplo n.º 1
0
 /**
  * @return array
  */
 public function toArray()
 {
     $payment = array_filter(get_object_vars($this));
     if ($this->mandate instanceof Mandate) {
         unset($payment['mandate']);
         $payment['links']['mandate'] = $this->mandate->getId();
     }
     return $payment;
 }
Ejemplo n.º 2
0
 /** @test */
 function it_can_be_created_from_an_api_response()
 {
     $mandate = Mandate::fromArray(['id' => 'MD123', 'created_at' => '2014-05-08T17:01:06.000Z', 'reference' => 'REF-123', 'status' => 'pending_submission', 'scheme' => 'bacs', 'next_possible_charge_date' => '2014-11-10', 'metadata' => ['contract' => 'ABCD1234'], 'links' => ['customer_bank_account' => 'BA123', 'creditor' => 'CR123']]);
     $this->assertEquals('MD123', $mandate->getId());
     $this->assertEquals('2014-05-08T17:01:06.000Z', $mandate->getCreatedAt());
     $this->assertEquals('REF-123', $mandate->getReference());
     $this->assertEquals('pending_submission', $mandate->getStatus());
     $this->assertEquals('bacs', $mandate->getScheme());
     $this->assertEquals('2014-11-10', $mandate->getNextPossibleChargeDate());
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /** @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());
 }
Ejemplo n.º 5
0
 /**
  * @see https://developer.gocardless.com/pro/#mandates-reinstate-a-mandate
  *
  * @param $id
  *
  * @return Mandate
  */
 public function reinstateMandate($id)
 {
     $response = $this->post(self::MANDATES, [], $id . '/actions/reinstate');
     return Mandate::fromArray($response);
 }
Ejemplo n.º 6
0
 /** @depends test_it_can_create_a_mandate */
 function test_it_can_get_a_single_mandate(Mandate $old)
 {
     $new = $this->api->getMandate($old->getId());
     $this->assertEquals($old->toArray(), $new->toArray());
 }
Ejemplo n.º 7
0
 /** @test */
 function it_can_be_converted_an_array_for_the_api()
 {
     $payment = new Payment();
     $payment->setAmount(300)->setCurrency('GBP')->setChargeDate('2014-05-19')->setDescription('My simple description')->setMandate(Mandate::fromArray(['id' => 'MD123']));
     $this->assertEquals(['amount' => '300', 'currency' => 'GBP', 'charge_date' => '2014-05-19', 'description' => 'My simple description', 'links' => ['mandate' => 'MD123']], $payment->toArray());
 }
Ejemplo n.º 8
0
 /** @test */
 function it_populates_using_fromarray()
 {
     $mandate = \GoCardless\Pro\Models\Mandate::fromArray(['metadata' => ['foo' => 'bar']]);
     $this->assertEquals(['foo' => 'bar'], $mandate->getMetadata());
 }