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');
        }
    }
예제 #2
0
$id = $card->getId();
use PayPal\Api\CreditCard;
use PayPal\Api\Patch;
// ### Patch Object
// You could update a credit card by sending patch requests. Each path object would have a specific detail in the object to be updated.
$pathOperation = new Patch();
$pathOperation->setOp("replace")->setPath('/expire_month')->setValue("12");
// ### Another Patch Object
// You could set more than one patch while updating a credit card.
$pathOperation2 = new Patch();
$pathOperation2->setOp('add')->setPath('/billing_address')->setValue(json_decode('{
            "line1": "111 First Street",
            "city": "Saratoga",
            "country_code": "US",
            "state": "CA",
            "postal_code": "95070"
        }'));
$pathRequest = new \PayPal\Api\PatchRequest();
$pathRequest->addPatch($pathOperation)->addPatch($pathOperation2);
/// ### Update Credit Card
// (See bootstrap.php for more on `ApiContext`)
try {
    $card = $card->update($pathRequest, $apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Updated Credit Card", "Credit Card", $card->getId(), $pathRequest, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Updated Credit Card", "Credit Card", $card->getId(), $pathRequest, $card);
return $card;
                    "details": {
                        "subtotal": "17.50",
                        "shipping": "6.20",
                        "tax":"1.30"
                    }
                }'));
$patchAdd = new \PayPal\Api\Patch();
$patchAdd->setOp('add')->setPath('/transactions/0/item_list/shipping_address')->setValue(json_decode('{
                    "recipient_name": "Gruneberg, Anna",
                    "line1": "52 N Main St",
                    "city": "San Jose",
                    "state": "CA",
                    "postal_code": "95112",
                    "country_code": "US"
                }'));
$patchRequest = new \PayPal\Api\PatchRequest();
$patchRequest->setPatches(array($patchReplace, $patchAdd));
// ### Update payment
// Update payment object by calling the
// static `update` method
// on the Payment class by passing a valid
// Payment ID
// (See bootstrap.php for more on `ApiContext`)
try {
    $result = $createdPayment->update($patchRequest, $apiContext);
} catch (Exception $ex) {
    ResultPrinter::printError("Update Payment", "PatchRequest", null, $patchRequest, $ex);
    exit(1);
}
ResultPrinter::printResult("Update Payment", "PatchRequest", $payment->getId(), $patchRequest, null);
// ### Getting Updated Payment Object
//      [
//         {
//             "op":"replace",
//            "path":"/url",
//            "value":"https://requestb.in/10ujt3c1"
//         },
//         {
//             "op":"replace",
//            "path":"/event_types",
//            "value":[
//               {
//                   "name":"PAYMENT.SALE.REFUNDED"
//               }
//            ]
//         }
//      ]
$patch = new \PayPal\Api\Patch();
$patch->setOp("replace")->setPath("/url")->setValue("https://requestb.in/10ujt3c1?uniqid=" . uniqid());
$patch2 = new \PayPal\Api\Patch();
$patch2->setOp("replace")->setPath("/event_types")->setValue(json_decode('[{"name":"PAYMENT.SALE.REFUNDED"}]'));
$patchRequest = new \PayPal\Api\PatchRequest();
$patchRequest->addPatch($patch)->addPatch($patch2);
// ### Get Webhook
try {
    $output = $webhook->update($patchRequest, $apiContext);
} catch (Exception $ex) {
    ResultPrinter::printError("Updated a Webhook", "Webhook", null, $patchRequest, $ex);
    exit(1);
}
ResultPrinter::printResult("Updated a Webhook", "Webhook", $output->getId(), $patchRequest, $output);
return $output;