PayPal\Api\Payment::setId PHP Method

setId() public method

Identifier of the payment resource created.
public setId ( string $id )
$id string
    public function setId($id)
    {
        $this->id = $id;
        return $this;
    }

Usage Example

Example #1
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();
     }
 }
All Usage Examples Of PayPal\Api\Payment::setId