public function testGetAuthorization() { $authorization = new Authorization('55660361T84491906', '2014-08-06T17:09:29Z', '2014-08-06T17:09:29Z', new Amount('EUR', '12.00'), 'authorized', 'PAY-82D19789V6611622NKPSQISI', '2014-09-06T17:09:29Z', array(new Link('https://api.sandbox.paypal.com/v1/payments/authorization/55660361T84491906', 'self', 'GET'), new Link('https://api.sandbox.paypal.com/v1/payments/authorization/55660361T84491906/capture', 'capture', 'POST'), new Link('https://api.sandbox.paypal.com/v1/payments/authorization/55660361T84491906/void', 'void', 'POST'), new Link('https://api.sandbox.paypal.com/v1/payments/payment/PAY-82D19789V6611622NKPSQISI', 'parent_payment', 'GET'))); $obj = new PaypalPaymentAuthorization('PAY-ID', "2014-08-08T17:11:00Z", "approved", "authorize", new Payer('paypal'), array(new Transaction(new Amount('EUR', '12.00'), 'my transaction', array(), array(array('authorization' => $authorization)))), array(new Link('https://api.sandbox.paypal.com/v1/payments/payment/PAY-82D19789V6611622NKPSQISI', 'self', 'GET')), "2014-08-08T17:11:00Z"); $this->assertInstanceOf('PayPalRestApiClient\\Model\\Authorization', $obj->getAuthorization()); $this->assertEquals($authorization, $obj->getAuthorization()); return $obj; }
/** * Build an instance of PayPalRestApiClient\Model\PaymentAuthorization given an array * * @param array $data The array should contains the following keys: * id, create_time, update_time, state, intent, payer, transactions, links. * The "id" key value should not be empty. * * @return PayPalRestApiClient\Model\PaypalPaymentAuthorization|PayPalRestApiClient\Model\CreditCardPaymentAuthorization * * @throws PayPalRestApiClient\Exception\BuilderException If not all keys are set or when "id" is empty * * @see https://developer.paypal.com/docs/integration/direct/capture-payment/#authorize-the-payment */ public function build(array $data) { $this->validateArrayKeys(array('id', 'create_time', 'update_time', 'state', 'intent', 'payer', 'transactions', 'links'), $data); if (empty($data['id'])) { throw new BuilderException('id is mandatory and should not be empty'); } $payer = $this->payerBuilder->build($data['payer']); $transactions = $this->transactionsBuilder->build($data['transactions']); $links = array(); foreach ($data['links'] as $link) { $links[] = $this->linkBuilder->build($link); } if ($data['payer']['payment_method'] === 'paypal') { $authorization = new PaypalPaymentAuthorization($data['id'], $data['create_time'], $data['state'], $data['intent'], $payer, $transactions, $links, $data['update_time']); $authorization->setPaypalData($data); return $authorization; } $authorization = new CreditCardPaymentAuthorization($data['id'], $data['create_time'], $data['state'], $data['intent'], $payer, $transactions, $links, $data['update_time']); $authorization->setPaypalData($data); return $authorization; }