|
18 | 18 | class Start
|
19 | 19 | {
|
20 | 20 |
|
21 |
| - public function startExpress() |
| 21 | + public function startPayment() |
22 | 22 | {
|
23 | 23 | $methodName_ = 'SetExpressCheckout';
|
24 | 24 | $nvpStr_ = Yii::$service->payment->paypal->getStandardTokenNvpStr();
|
25 | 25 | //echo $nvpStr_;exit;
|
26 | 26 | // 通过接口,得到token信息
|
27 |
| - $SetExpressCheckoutReturn = Yii::$service->payment->paypal->PPHttpPost5($methodName_, $nvpStr_); |
28 |
| - //var_dump($SetExpressCheckoutReturn); |
29 |
| - if (strtolower($SetExpressCheckoutReturn['ACK']) == 'success') { |
30 |
| - $token = $SetExpressCheckoutReturn['TOKEN']; |
| 27 | + $checkoutReturn = Yii::$service->payment->paypal->PPHttpPost5($methodName_, $nvpStr_); |
| 28 | + //var_dump($checkoutReturn);exit; |
| 29 | + if (strtolower($checkoutReturn['ACK']) == 'success') { |
| 30 | + $token = $checkoutReturn['TOKEN']; |
31 | 31 | $increment_id = Yii::$service->order->getSessionIncrementId();
|
32 | 32 | # 将token写入到订单中
|
33 | 33 | Yii::$service->order->updateTokenByIncrementId($increment_id,$token);
|
34 |
| - $redirectUrl = Yii::$service->payment->paypal->getSetStandardCheckoutUrl($token); |
| 34 | + $redirectUrl = Yii::$service->payment->paypal->getStandardCheckoutUrl($token); |
35 | 35 | Yii::$service->url->redirect($redirectUrl);
|
36 | 36 | return;
|
37 |
| - } elseif (strtolower($SetExpressCheckoutReturn['ACK']) == 'failure') { |
38 |
| - echo $SetExpressCheckoutReturn['L_LONGMESSAGE0']; |
| 37 | + } elseif (strtolower($checkoutReturn['ACK']) == 'failure') { |
| 38 | + echo $checkoutReturn['L_LONGMESSAGE0']; |
39 | 39 | } else {
|
40 |
| - var_dump($SetExpressCheckoutReturn); |
| 40 | + var_dump($checkoutReturn); |
41 | 41 | }
|
42 | 42 | }
|
43 |
| - |
44 |
| - /* |
45 |
| - public function getLastData() |
46 |
| - { |
47 |
| - $loaderImg = Yii::$service->image->getImgUrl('images/loader.gif', 'appfront'); |
48 |
| - $paypalLogoImg = Yii::$service->image->getImgUrl('custom/logo.png', 'appfront'); |
49 |
| -
|
50 |
| - $increment_id = Yii::$service->order->getSessionIncrementId(); |
51 |
| - if ($increment_id) { |
52 |
| - $order = Yii::$service->order->getInfoByIncrementId($increment_id); |
53 |
| - if ($order) { |
54 |
| - //var_dump($order);exit; |
55 |
| - Yii::$service->payment->setPaymentMethod($order['payment_method']); |
56 |
| - $success_redirect_url = Yii::$service->payment->getStandardSuccessRedirectUrl(); |
57 |
| - $cancel_url = Yii::$service->payment->getStandardCancelUrl(); |
58 |
| - $ipn_url = Yii::$service->payment->getStandardIpnUrl(); |
59 |
| - $store_name = Yii::$service->store->currentStore; |
60 |
| -
|
61 |
| - $payment_action = 'sale'; |
62 |
| - $cmd = '_cart'; |
63 |
| - $upload = 1; |
64 |
| - $tax = 0.00; |
65 |
| - $tax_cart = 0.00; |
66 |
| -
|
67 |
| - $payment_url = Yii::$service->payment->getStandardPaymentUrl(); |
68 |
| - $account = Yii::$service->payment->getStandardAccount(); |
69 |
| -
|
70 |
| - return [ |
71 |
| - 'loader_img' => $loaderImg, |
72 |
| - 'paypal_logo_img' => $paypalLogoImg, |
73 |
| - 'order' => $order, |
74 |
| - 'success_redirect_url' => $success_redirect_url, |
75 |
| - 'cancel_url' => $cancel_url, |
76 |
| - 'ipn_url' => $ipn_url, |
77 |
| - 'store_name' => $store_name, |
78 |
| - 'payment_action' => $payment_action, |
79 |
| - 'cmd' => $cmd, |
80 |
| - 'upload' => $upload, |
81 |
| - 'tax' => $tax, |
82 |
| - 'tax_cart' => $tax_cart, |
83 |
| - 'payment_url' => $payment_url, |
84 |
| - 'account' => $account, |
85 |
| - 'product_items_and_shipping' => $this->getProductItemsAndShipping($order), |
86 |
| - 'address_html' => $this->getAddressHtml($order), |
87 |
| - ]; |
88 |
| - } |
89 |
| - } |
90 |
| - } |
91 |
| -
|
92 |
| - public function getAddressHtml($order) |
93 |
| - { |
94 |
| - $stateCode = $order['customer_address_state']; |
95 |
| - $countryCode = $order['customer_address_country']; |
96 |
| - $country = Yii::$service->helper->country->getCountryNameByKey($countryCode); |
97 |
| - $state = Yii::$service->helper->country->getStateByContryCode($countryCode, $stateCode); |
98 |
| - $str = ' |
99 |
| - <input id="city" name="city" value="'.$order['customer_address_city'].'" type="hidden"/> |
100 |
| - <input id="country" name="country" value="'.$country.'" type="hidden"/> |
101 |
| - <input id="email" name="email" value="'.$order['customer_email'].'" type="hidden"/> |
102 |
| - <input id="first_name" name="first_name" value="'.$order['customer_firstname'].'" type="hidden"/> |
103 |
| - <input id="last_name" name="last_name" value="'.$order['customer_lastname'].'" type="hidden"/> |
104 |
| - <input id="zip" name="zip" value="'.$order['customer_address_zip'].'" type="hidden"/> |
105 |
| - <input id="state" name="state" value="'.$state.'" type="hidden"/> |
106 |
| - <input id="address1" name="address1" value="'.$order['customer_address_street1'].'" type="hidden"/> |
107 |
| - <input id="address2" name="address2" value="'.$order['customer_address_street2'].'" type="hidden"/> |
108 |
| - <input id="address_override" name="address_override" value="0" type="hidden"/> |
109 |
| - '; |
110 |
| -
|
111 |
| - return $str; |
112 |
| - } |
113 |
| -
|
114 |
| - public function getProductItemsAndShipping($order) |
115 |
| - { |
116 |
| - $items = $order['items']; |
117 |
| - $str = ''; |
118 |
| - $i = 1; |
119 |
| - foreach ($items as $item) { |
120 |
| - $sku = isset($item['sku']) ? $item['sku'] : ''; |
121 |
| - $name = isset($item['name']) ? $item['name'] : ''; |
122 |
| - $qty = isset($item['qty']) ? $item['qty'] : ''; |
123 |
| - $price = isset($item['price']) ? str_replace(',', '', number_format($item['price'], 2)) : number_format($item['price'], 0); |
124 |
| -
|
125 |
| - $custom_option_info = isset($item['custom_option_info']) ? $item['custom_option_info'] : ''; |
126 |
| - if ($sku && $qty && $price) { |
127 |
| - $str .= ' |
128 |
| - <input id="item_number_'.$i.'" name="item_number_'.$i.'" value="'.$sku.'" type="hidden"/> |
129 |
| - <input id="item_name_'.$i.'" name="item_name_'.$i.'" value="'.$name.'" type="hidden"/> |
130 |
| - <input id="quantity_'.$i.'" name="quantity_'.$i.'" value="'.$qty.'" type="hidden"/> |
131 |
| - <input id="amount_'.$i.'" name="amount_'.$i.'" value="'.$price.'" type="hidden"/> |
132 |
| - |
133 |
| - '; |
134 |
| - if (is_array($custom_option_info) && !empty($custom_option_info)) { |
135 |
| - $j = 0; |
136 |
| - foreach ($custom_option_info as $co_label=>$co_value) { |
137 |
| - $str .= ' |
138 |
| - <input id="on'.$j.'_'.$i.'" name="on'.$j.'_'.$i.'" type="hidden" value="'.$co_label.'" /> |
139 |
| - <input id="os'.$j.'_'.$i.'" name="os'.$j.'_'.$i.'" type="hidden" value="'.$co_value.'" /> |
140 |
| - '; |
141 |
| - $j++; |
142 |
| - } |
143 |
| - } |
144 |
| - } |
145 |
| - $i++; |
146 |
| - } |
147 |
| - $shipping_total = $order['shipping_total']; |
148 |
| - $shipping_total = str_replace(',', '', number_format($shipping_total, 2)); |
149 |
| -
|
150 |
| - $shipping_method = $order['shipping_method']; |
151 |
| - $shipping_label = Yii::$service->shipping->getShippingLabelByMethod($shipping_method); |
152 |
| - $str .= ' |
153 |
| - <input id="item_number_'.$i.'" name="item_number_'.$i.'" value="'.$shipping_label.'" type="hidden"/> |
154 |
| - <input id="item_name_'.$i.'" name="item_name_'.$i.'" value="'.$shipping_method.'" type="hidden"/> |
155 |
| - <input id="quantity_'.$i.'" name="quantity_'.$i.'" value="1" type="hidden"/> |
156 |
| - <input id="amount_'.$i.'" name="amount_'.$i.'" value="'.$shipping_total.'" type="hidden"/> |
157 |
| - '; |
158 |
| -
|
159 |
| - return $str; |
160 |
| - } |
161 |
| - */ |
162 | 43 | }
|
0 commit comments