/**
  * Execute a payment or an authorization that was previously approved by the client.
  *
  * @param PayPalRestApiClient\Model\AccessToken $accessToken
  * @param PayPalRestApiClient\Model\Payment $payment payment previously created with the "PaymentService::create" method
  * @param string $payerId not null, parameter "payerId" that is passed in the success url when using paypal payment method
  *
  * @return PayPalRestApiClient\Model\Payment
  */
 public function execute(AccessToken $accessToken, Payment $payment, $payerId)
 {
     $request = $this->client->createRequest('POST', $payment->getExecuteUrl(), array('Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => $accessToken->getTokenType() . ' ' . $accessToken->getAccessToken(), 'Content-Type' => 'application/json'), '{"payer_id":"' . $payerId . '"}', array('debug' => $this->debug));
     $response = $this->send($request, 200, "Payment error:");
     $data = json_decode($response->getBody(), true);
     if ('authorize' === $data['intent']) {
         $authorizationBuilder = new PaymentAuthorizationBuilder();
         $authorization = $authorizationBuilder->build($data);
         return $authorization;
     }
     $paymentBuilder = new PaymentBuilder();
     $payment = $paymentBuilder->build($data);
     return $payment;
 }
 public function testGetLinksUrl()
 {
     $payment = new Payment("PAY-6T42818722685883WKPPAT6I", "2014-08-03T10:07:53Z", 'created', 'sale', new Payer('paypal'), array(), array(new Link('https://api.sandbox.paypal.com/v1/payments/payment/PAY-6T42818722685883WKPPAT6I', 'self', 'GET'), new Link('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-9VK533621R3302713', 'approval_url', 'REDIRECT'), new Link('https://api.sandbox.paypal.com/v1/payments/payment/PAY-6T42818722685883WKPPAT6I/execute', 'execute', 'POST')), "2014-08-03T10:07:53Z");
     $this->assertEquals('https://api.sandbox.paypal.com/v1/payments/payment/PAY-6T42818722685883WKPPAT6I/execute', $payment->getExecuteUrl());
     $this->assertEquals('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-9VK533621R3302713', $payment->getApprovalUrl());
 }