api = new PayPalAPIInterfaceServiceService($options['api']); unset($options['api']); Qs_Options::setOptions($this, $options); } public function getExpressCheckoutUrl() { if (null === $this->expressCheckoutUrl) { throw new UnexpectedValueException('Express Checkout Url is not defined'); } return $this->expressCheckoutUrl; } public function setExpressCheckoutUrl($expressCheckoutUrl) { $this->expressCheckoutUrl = $expressCheckoutUrl; return $this; } /** * @param array $request * @return SetExpressCheckoutResponseType * @throws \Exception */ public function setExpressCheckout(array $request) { /** @var SetExpressCheckoutReq $secRequest */ $secRequest = (new ObjectPropertyHydrator()) ->addStrategy('SetExpressCheckoutRequest', new Hydrator\SetExpressCheckoutRequestStrategy()) ->hydrate(['SetExpressCheckoutRequest' => $request], new SetExpressCheckoutReq()); $response = $this->api->SetExpressCheckout($secRequest); $this->throwOnInvalidResponse($response); return $response; } public function doExpressCheckoutPayment(array $request) { /** @var DoExpressCheckoutPaymentReq $decpRequest */ $decpRequest = (new ObjectPropertyHydrator()) ->addStrategy('DoExpressCheckoutPaymentRequest', new Hydrator\DoExpressCheckoutPaymentRequestStrategy()) ->hydrate(['DoExpressCheckoutPaymentRequest' => $request], new DoExpressCheckoutPaymentReq()); $response = $this->api->DoExpressCheckoutPayment($decpRequest); $this->throwOnInvalidResponse($response); return $response; } public function getExpressCheckoutDetails($token) { $request = new GetExpressCheckoutDetailsReq(); $request->GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token); $response = $this->api->GetExpressCheckoutDetails($request); $this->throwOnInvalidResponse($response); return $response; } private function throwOnInvalidResponse(AbstractResponseType $response) { if ($response->Ack === self::ACK_SUCCESS) { return $this; } $errors = []; /** @var \PayPal\EBLBaseComponents\ErrorType $error */ foreach ((array) $response->Errors as $error) { $errors[] = 'PayPal Error #' . $error->ErrorCode . ': ' . $error->LongMessage; } $message = implode(', ', $errors) ?: 'Unexpected Payment Error'; throw new Exception($message); } }