execute() public method

Executes, or completes, a PayPal payment that the payer has approved. You can optionally update selective payment information when you execute a payment.
public execute ( PaymentExecution $paymentExecution, ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : Payment
$paymentExecution PaymentExecution
$apiContext PayPal\Rest\ApiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
$restCall PayPalRestCall is the Rest Call Service that is used to make rest calls
return Payment
Esempio n. 1
0
 /**
  * @throws \InvalidArgumentException
  *
  * @return Payment
  */
 private function payment() : Payment
 {
     if ($this->payment === null) {
         $this->payment = $this->return->payment();
         $this->payment->execute($this->execution(), $this->context);
     }
     return $this->payment;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     /** @var $request Capture */
     RequestNotSupportedException::assertSupports($this, $request);
     $details = ArrayObject::ensureArrayObject($request->getModel());
     $payment = new Payment();
     $payer = new Payer();
     $payer->payment_method = "paypal";
     $amount = new Amount();
     $amount->currency = $details['PAYMENTREQUEST_CURRENCYCODE'];
     $amount->total = $details['PAYMENTREQUEST_AMT'];
     $transaction = new Transaction();
     $transaction->amount = $amount;
     $transaction->description = $details['PAYMENTREQUEST_DESCRIPTION'];
     $redirectUrls = new RedirectUrls();
     $redirectUrls->return_url = $details['RETURN_URL'];
     $redirectUrls->cancel_url = $details['CANCEL_URL'];
     $payment->intent = "sale";
     $payment->payer = $payer;
     $payment->redirect_urls = $redirectUrls;
     $payment->transactions = [$transaction];
     if (false == isset($details['response']) && false == isset($details['response']['state']) && isset($payment->payer->payment_method) && 'paypal' == $payment->payer->payment_method) {
         $paymentResponse = $payment->create($this->api);
         $details['response'] = $paymentResponse->toArray();
         foreach ($paymentResponse->links as $link) {
             if ($link->rel == 'approval_url') {
                 throw new HttpRedirect($link->href);
             }
         }
     }
     if (false == isset($details['response']) && false == isset($details['response']['state']) && isset($payment->payer->payment_method) && 'credit_card' == $payment->payer->payment_method) {
         $paymentResponse = $payment->create($this->api);
         $details['response'] = $paymentResponse->toArray();
     }
     $this->gateway->execute(new Sync($details));
     if (true == isset($details['response']) && true == isset($details['response']['state']) && true == isset($details['response']['id']) && isset($payment->payer->payment_method) && 'paypal' == $payment->payer->payment_method && true == isset($details['PayerID'])) {
         $payment->setId($details['response']['id']);
         $execution = new PaymentExecution();
         $execution->setPayerId($details['PayerID']);
         //Execute the payment
         $paymentResponse = $payment->execute($execution, $this->api);
         $details['response'] = $paymentResponse->toArray();
     }
 }
Esempio n. 3
0
 /**
  * @dataProvider mockProvider
  * @param Payment $obj
  */
 public function testExecute($obj, $mockApiContext)
 {
     $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(self::getJson()));
     $paymentExecution = PaymentExecutionTest::getObject();
     $result = $obj->execute($paymentExecution, $mockApiContext, $mockPPRestCall);
     $this->assertNotNull($result);
 }