1: <?php
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: class Mage_Paypal_Model_Api_Standard extends Mage_Paypal_Model_Api_Abstract
31: {
32: 33: 34: 35:
36: protected $_globalMap = array(
37:
38: 'business' => 'business_account',
39: 'notify_url' => 'notify_url',
40: 'return' => 'return_url',
41: 'cancel_return' => 'cancel_url',
42: 'bn' => 'build_notation_code',
43: 'paymentaction' => 'payment_action',
44:
45: 'invoice' => 'order_id',
46: 'currency_code' => 'currency_code',
47: 'amount' => 'amount',
48: 'shipping' => 'shipping_amount',
49: 'tax' => 'tax_amount',
50: 'discount_amount' => 'discount_amount',
51:
52: 'item_name' => 'cart_summary',
53:
54: 'page_style' => 'page_style',
55: 'cpp_header_image' => 'hdrimg',
56: 'cpp_headerback_color' => 'hdrbackcolor',
57: 'cpp_headerborder_color' => 'hdrbordercolor',
58: 'cpp_payflow_color' => 'payflowcolor',
59:
60: 'lc' => 'locale',
61: );
62: protected $_exportToRequestFilters = array(
63: 'amount' => '_filterAmount',
64: 'shipping' => '_filterAmount',
65: 'tax' => '_filterAmount',
66: 'discount_amount' => '_filterAmount',
67: );
68:
69: 70: 71: 72:
73: protected $_commonRequestFields = array(
74: 'business', 'invoice', 'currency_code', 'paymentaction', 'return', 'cancel_return', 'notify_url', 'bn',
75: 'page_style', 'cpp_header_image', 'cpp_headerback_color', 'cpp_headerborder_color', 'cpp_payflow_color',
76: 'amount', 'shipping', 'tax', 'discount_amount', 'item_name', 'lc',
77: );
78:
79: 80: 81: 82: 83:
84: protected $_debugReplacePrivateDataKeys = array('business');
85:
86: 87: 88: 89:
90: protected $_lineItemTotalExportMap = array(
91: Mage_Paypal_Model_Cart::TOTAL_SUBTOTAL => 'amount',
92: Mage_Paypal_Model_Cart::TOTAL_DISCOUNT => 'discount_amount',
93: Mage_Paypal_Model_Cart::TOTAL_TAX => 'tax',
94: Mage_Paypal_Model_Cart::TOTAL_SHIPPING => 'shipping',
95: );
96: protected $_lineItemExportItemsFormat = array(
97: 'id' => 'item_number_%d',
98: 'name' => 'item_name_%d',
99: 'qty' => 'quantity_%d',
100: 'amount' => 'amount_%d',
101: );
102:
103: protected $_lineItemExportItemsFilters = array(
104: 'qty' => '_filterQty'
105: );
106:
107: 108: 109: 110:
111: protected $_addressMap = array(
112: 'city' => 'city',
113: 'country' => 'country_id',
114: 'email' => 'email',
115: 'first_name' => 'firstname',
116: 'last_name' => 'lastname',
117: 'zip' => 'postcode',
118: 'state' => 'region',
119: 'address1' => 'street',
120: 'address2' => 'street2',
121: );
122:
123: 124: 125: 126: 127:
128: public function getStandardCheckoutRequest()
129: {
130: $request = $this->_exportToRequest($this->_commonRequestFields);
131: $request['charset'] = 'utf-8';
132:
133: $isLineItems = $this->_exportLineItems($request);
134: if ($isLineItems) {
135: $request = array_merge($request, array(
136: 'cmd' => '_cart',
137: 'upload' => 1,
138: ));
139: if (isset($request['tax'])) {
140: $request['tax_cart'] = $request['tax'];
141: }
142: if (isset($request['discount_amount'])) {
143: $request['discount_amount_cart'] = $request['discount_amount'];
144: }
145: } else {
146: $request = array_merge($request, array(
147: 'cmd' => '_ext-enter',
148: 'redirect_cmd' => '_xclick',
149: ));
150: }
151:
152:
153: $this->_importAddress($request);
154: $this->_debug(array('request' => $request));
155: return $request;
156: }
157:
158: 159: 160: 161:
162: public function getBusinessAccount()
163: {
164: return $this->_getDataOrConfig('business_account');
165: }
166:
167: 168: 169: 170:
171: public function getPaymentAction()
172: {
173: return strtolower(parent::getPaymentAction());
174: }
175:
176: 177: 178: 179: 180:
181: public function debugRequest($request)
182: {
183: return;
184: }
185:
186: 187: 188: 189: 190: 191: 192: 193: 194:
195: protected function _exportLineItems(array &$request, $i = 1)
196: {
197: if (!$this->_cart) {
198: return;
199: }
200: if ($this->getIsLineItemsEnabled()) {
201: $this->_cart->isShippingAsItem(true);
202: }
203: return parent::_exportLineItems($request, $i);
204: }
205:
206: 207: 208: 209: 210:
211: protected function _importAddress(&$request)
212: {
213: $address = $this->getAddress();
214: if (!$address) {
215: if ($this->getNoShipping()) {
216: $request['no_shipping'] = 1;
217: }
218: return;
219: }
220:
221: $request = Varien_Object_Mapper::accumulateByMap($address, $request, array_flip($this->_addressMap));
222:
223:
224: if (!$request['email']) {
225: $order = $this->getOrder();
226: if ($order) {
227: $request['email'] = $order->getCustomerEmail();
228: }
229: }
230:
231: $regionCode = $this->_lookupRegionCodeFromAddress($address);
232: if ($regionCode) {
233: $request['state'] = $regionCode;
234: }
235: $this->_importStreetFromAddress($address, $request, 'address1', 'address2');
236: $this->_applyCountryWorkarounds($request);
237:
238: $request['address_override'] = 1;
239: }
240:
241: 242: 243: 244: 245: 246:
247: protected function _applyCountryWorkarounds(&$request)
248: {
249: if (isset($request['country']) && $request['country'] == 'PR') {
250: $request['country'] = 'US';
251: $request['state'] = 'PR';
252: }
253: }
254: }
255: