/**
  * 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;
 }
 public function testGetLinksUrl()
 {
     $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 CreditCardPaymentAuthorization('PAY-ID', "2014-08-08T17:11:00Z", "approved", "authorize", new Payer('credit_card', array(array('credit_card' => array('number' => '4417119669820331', 'type' => 'visa', 'expire_month' => 11, 'expire_year' => 2018, 'cvv2' => '874', 'first_name' => 'Betsy', 'last_name' => 'Buyer', 'billing_address' => array('line1' => '111 First Street', 'city' => 'Saratoga', 'state' => 'CA', 'postal_code' => '95070', 'country_code' => 'US'))))), 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->assertEquals('https://api.sandbox.paypal.com/v1/payments/authorization/55660361T84491906/capture', $obj->getCaptureUrl());
 }