setId() public méthode

Identifier of the payment resource created.
public setId ( string $id )
$id string
Exemple #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();
     }
 }
    function receipt_page($order_id)
    {
        $order = new WC_Order($order_id);
        WC()->session->ppp_order_id = $order_id;
        $PaymentData = AngellEYE_Gateway_Paypal::calculate($order, true);
        $payment = new Payment();
        $payment->setId(WC()->session->paymentId);
        $patchReplace = new \PayPal\Api\Patch();
        $patchReplace->setOp('replace')->setPath('/transactions/0/amount')->setValue(json_decode('{
                    "total": "' . number_format($order->get_total(), 2, '.', '') . '",
                    "currency": "' . get_woocommerce_currency() . '",
                    "details": {
                        "subtotal": "' . $PaymentData['itemamt'] . '",
                        "shipping": "' . $PaymentData['shippingamt'] . '",
                        "tax":"' . $PaymentData['taxamt'] . '"
                    }
                }'));
        $patchRequest = new \PayPal\Api\PatchRequest();
        if ($order->needs_shipping_address() && !empty($order->shipping_country)) {
            //add shipping info
            $patchAdd = new \PayPal\Api\Patch();
            $patchAdd->setOp('add')->setPath('/transactions/0/item_list/shipping_address')->setValue(json_decode('{
                    "recipient_name": "' . $order->shipping_first_name . ' ' . $order->shipping_last_name . '",
                    "line1": "' . $order->shipping_address_1 . '",
                    "city": "' . $order->shipping_city . '",
                    "state": "' . $order->shipping_state . '",
                    "postal_code": "' . $order->shipping_postcode . '",
                    "country_code": "' . $order->shipping_country . '"
                }'));
            $patchRequest->setPatches(array($patchAdd, $patchReplace));
        } else {
            $patchRequest->setPatches(array($patchReplace));
        }
        try {
            $result = $payment->update($patchRequest, $this->getAuth());
            $this->add_log(print_r($payment, true));
            if ($result == true) {
            }
            ?>
        <script src="https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js"type="text/javascript"></script>
        <script>
            jQuery(document).ready(function(){
                jQuery.blockUI({
                    message: "<?php 
            echo esc_js(__('Thank you for your order. We are now redirecting you to PayPal to make payment.', 'paypal-for-woocommerce'));
            ?>
",
                    baseZ: 99999,
                    overlayCSS:
                    {
                        background: "#fff",
                        opacity: 0.6
                    },
                    css: {
                        padding:        "20px",
                        zindex:         "9999999",
                        textAlign:      "center",
                        color:          "#555",
                        border:         "3px solid #aaa",
                        backgroundColor:"#fff",
                        cursor:         "wait",
                        lineHeight:		"24px"
                    }
                });
                PAYPAL.apps.PPP.doCheckout();
            });
        </script>
    <?php 
        } catch (PayPal\Exception\PayPalConnectionException $ex) {
            wc_add_notice(__("Error processing checkout. Please try again. ", 'woocommerce'), 'error');
            $this->add_log($ex->getData());
        } catch (Exception $ex) {
            $this->add_log($ex->getMessage());
            // Prints the Error Code
            wc_add_notice(__("Error processing checkout. Please try again.", 'woocommerce'), 'error');
        }
    }