Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * Build an instance of PayPalRestApiClient\Model\Payment given an array
  *
  * @param array $data The array should contains the following keys:
  * id, create_time, state, intent, payer, transactions, links
  * The "id" key value should not be empty.
  *
  * @return PayPalRestApiClient\Model\Payment
  *
  * @throws PayPalRestApiClient\Exception\BuilderException If not all keys are set
  *
  * @see https://developer.paypal.com/docs/api/#payment-object
  */
 public function build(array $data)
 {
     $this->validateArrayKeys(array('id', 'create_time', 'state', 'intent', 'payer', 'transactions', 'links'), $data);
     if (empty($data['id'])) {
         throw new BuilderException('id is mandatory and should not be empty');
     }
     $links = array();
     foreach ($data['links'] as $link) {
         $links[] = $this->linkBuilder->build($link);
     }
     $payment = new Payment($data['id'], $data['create_time'], $data['state'], $data['intent'], $this->payerBuilder->build($data['payer']), $this->transactionsBuilder->build($data['transactions']), $links, isset($data['update_time']) ? $data['update_time'] : null);
     $payment->setPaypalData($data);
     return $payment;
 }
Пример #3
0
 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());
 }