/var/www/hkosl.com/imusiccircle/paypal/ReviewOrder.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
    error_reporting
(E_ALL);
    
ini_set('display_errors'0);

    use 
PayPal\CoreComponentTypes\BasicAmountType;
    use 
PayPal\EBLBaseComponents\AddressType;
    use 
PayPal\EBLBaseComponents\BillingAgreementDetailsType;
    use 
PayPal\EBLBaseComponents\PaymentDetailsItemType;
    use 
PayPal\EBLBaseComponents\PaymentDetailsType;
    use 
PayPal\EBLBaseComponents\SetExpressCheckoutRequestDetailsType;
    use 
PayPal\PayPalAPI\SetExpressCheckoutReq;
    use 
PayPal\PayPalAPI\SetExpressCheckoutRequestType;
    use 
PayPal\Service\PayPalAPIInterfaceServiceService;
    require_once(
'PPBootStrap.php');

    require_once 
'../webadmin/configure.php';

    
//set payment config
    
$_REQUEST["order_id"] = 1;
    
$order_id = (int)$_REQUEST["order_id"];

    if(empty(
$order_id)){
        exit(
"Cannot find order id.");
    }

    
$shipping_amt 0;
    
$noShipping 1;
    
/*
     * The SetExpressCheckout API operation initiates an Express Checkout transaction
     * This sample code uses Merchant PHP SDK to make API call
     */


    //$url       = dirname('http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']);
    
$url       = ('http://' $_SERVER['HTTP_HOST']."/".EXTRA_URL);

    
$returnUrl "$url/ReviewOrder.php";
    
$cancelUrl "$url/webadmin/order_form.php?id=".$order_id;
    
$notifyURL "$url/paypal_notify.php";

    
$currencyCode "HKD";
    
// total shipping amount
    
$shippingTotal $shipping_amt;

    
// details about payment
    
$paymentDetails = new PaymentDetailsType();
    
$itemTotalValue 0;
    
$taxTotalValue  0;
    
/*
     * iterate trhough each item and add to item details
     */

    /*for ($i = 0; $i < count($_REQUEST['itemAmount']); $i++) {
        $itemAmount = new BasicAmountType($currencyCode, $_REQUEST['itemAmount'][$i]);
        $itemTotalValue += $_REQUEST['itemAmount'][$i] * $_REQUEST['itemQuantity'][$i];
        $itemDetails           = new PaymentDetailsItemType();
        $itemDetails->Name     = $_REQUEST['itemName'][$i];
        $itemDetails->Amount   = $itemAmount;
        $itemDetails->Quantity = $_REQUEST['itemQuantity'][$i];

        $paymentDetails->PaymentDetailsItem[$i] = $itemDetails;
    }*/

    
$itemTotalValue += 1;
    
$itemDetails           = new PaymentDetailsItemType();
    
$itemDetails->Name     "test1";
    
$itemDetails->Amount   1;
    
$itemDetails->Quantity 1;
    
$paymentDetails->PaymentDetailsItem[$i] = $itemDetails;

    
//end of payment config

    /*
     * The total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value. If not, this value should be the current subtotal of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. If the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment, set this field to 0.
     */
    
$orderTotalValue $shippingTotal->value $itemTotalValue $taxTotalValue;

    
//Payment details
    
$paymentDetails->ItemTotal     $itemTotalValue;
    
$paymentDetails->TaxTotal      $taxTotalValue;
    
$paymentDetails->OrderTotal    $orderTotalValue;

    
/*
     * How you want to obtain payment. When implementing parallel payments, this field is required and must be set to Order. When implementing digital goods, this field is required and must be set to Sale. If the transaction does not include a one-time purchase, this field is ignored. It is one of the following values:

        Sale � This is a final sale for which you are requesting payment (default).

        Authorization � This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.

        Order � This payment is an order authorization subject to settlement with PayPal Authorization and Capture.

     */
    
$paymentDetails->PaymentAction "Sale";
    
$paymentDetails->ShippingTotal  $shippingTotal;

    
/*
     *  Your URL for receiving Instant Payment Notification (IPN) about this transaction. If you do not specify this value in the request, the notification URL from your Merchant Profile is used, if one exists.
     */
    
if (!empty($notifyURL)) {
        
$paymentDetails->NotifyURL $notifyURL;
    }

    
$setECReqDetails                    = new SetExpressCheckoutRequestDetailsType();
    
$setECReqDetails->PaymentDetails[0] = $paymentDetails;
    
/*
     * (Required) URL to which the buyer is returned if the buyer does not approve the use of PayPal to pay you. For digital goods, you must add JavaScript to this page to close the in-context experience.
     */
    
$setECReqDetails->CancelURL $cancelUrl;
    
/*
     * (Required) URL to which the buyer's browser is returned after choosing to pay with PayPal. For digital goods, you must add JavaScript to this page to close the in-context experience.
     */
    
$setECReqDetails->ReturnURL $returnUrl;

    
/*
     * Determines where or not PayPal displays shipping address fields on the PayPal pages. For digital goods, this field is required, and you must set it to 1. It is one of the following values:

        0 � PayPal displays the shipping address on the PayPal pages.

        1 � PayPal does not display shipping address fields whatsoever.

        2 � If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.

     */
    
$setECReqDetails->NoShipping $noShipping;
    
/*
     *  (Optional) Determines whether or not the PayPal pages should display the shipping address set by you in this SetExpressCheckout request, not the shipping address on file with PayPal for this buyer. Displaying the PayPal street address on file does not allow the buyer to edit that address. It is one of the following values:

        0 � The PayPal pages should not display the shipping address.

        1 � The PayPal pages should display the shipping address.

     */
    
$setECReqDetails->AddressOverride $_REQUEST['addressOverride'];

    
/*
     * Indicates whether or not you require the buyer's shipping address on file with PayPal be a confirmed address. For digital goods, this field is required, and you must set it to 0. It is one of the following values:

        0 � You do not require the buyer's shipping address be a confirmed address.

        1 � You require the buyer's shipping address be a confirmed address.

     */
    
$setECReqDetails->ReqConfirmShipping 0;

    
// Advanced options
    //$setECReqDetails->AllowNote = $_REQUEST['allowNote'];

    
$setECReqType                                   = new SetExpressCheckoutRequestType();
    
$setECReqType->SetExpressCheckoutRequestDetails $setECReqDetails;
    
$setECReq                                       = new SetExpressCheckoutReq();
    
$setECReq->SetExpressCheckoutRequest            $setECReqType;

    
/*
     *      ## Creating service wrapper object
    Creating service wrapper object to make API call and loading
    Configuration::getAcctAndConfig() returns array that contains credential and config parameters
    */
    
$paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());

    try {
        
/* wrap API method calls on the service object with a try catch */
        
$setECResponse $paypalService->SetExpressCheckout($setECReq);
    } catch (
Exception $ex) {
        include_once(
"Error.php");
        exit;
    }

    if (isset(
$setECResponse)) {
        echo 
"<table>";
        echo 
"<tr><td>Ack :</td><td><div id='Ack'>$setECResponse->Ack</div> </td></tr>";
        echo 
"<tr><td>Token :</td><td><div id='Token'>$setECResponse->Token</div> </td></tr>";
        echo 
"</table>";
        echo 
'<pre>';
        
print_r($setECResponse);
        echo 
'</pre>';
        if (
$setECResponse->Ack == 'Success') {
            
$token $setECResponse->Token;
            
// Redirect to paypal.com here
            
$payPalURL 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' $token;
            echo 
" <a href=$payPalURL><b>* Redirect to PayPal to login </b></a><br>";
        }
    }
    require_once 
'Response.php';