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:
31: class Mage_Paypal_Model_Config
32: {
33: 34: 35: 36:
37: const METHOD_WPS = 'paypal_standard';
38:
39: 40: 41: 42:
43: const METHOD_WPP_EXPRESS = 'paypal_express';
44:
45: 46: 47: 48:
49: const METHOD_WPP_DIRECT = 'paypal_direct';
50:
51: 52: 53: 54:
55: const METHOD_WPP_PE_DIRECT = 'paypaluk_direct';
56:
57: 58: 59: 60:
61: const METHOD_WPP_PE_EXPRESS = 'paypaluk_express';
62:
63: 64: 65: 66:
67: const METHOD_PAYFLOWPRO = 'verisign';
68:
69: const METHOD_PAYFLOWLINK = 'payflow_link';
70: const METHOD_PAYFLOWADVANCED = 'payflow_advanced';
71:
72: const METHOD_HOSTEDPRO = 'hosted_pro';
73:
74: const METHOD_BILLING_AGREEMENT = 'paypal_billing_agreement';
75:
76: 77: 78: 79:
80: const EC_FLAVOR_DYNAMIC = 'dynamic';
81: const EC_FLAVOR_STATIC = 'static';
82: const EC_BUTTON_TYPE_SHORTCUT = 'ecshortcut';
83: const EC_BUTTON_TYPE_MARK = 'ecmark';
84: const PAYMENT_MARK_37x23 = '37x23';
85: const PAYMENT_MARK_50x34 = '50x34';
86: const PAYMENT_MARK_60x38 = '60x38';
87: const PAYMENT_MARK_180x113 = '180x113';
88:
89: const DEFAULT_LOGO_TYPE = 'wePrefer_150x60';
90:
91: 92: 93: 94:
95: const PAYMENT_ACTION_SALE = 'Sale';
96: const PAYMENT_ACTION_ORDER = 'Order';
97: const PAYMENT_ACTION_AUTH = 'Authorization';
98:
99: 100: 101: 102: 103: 104:
105: const AUTHORIZATION_AMOUNT_ZERO = 0;
106: const AUTHORIZATION_AMOUNT_ONE = 1;
107: const AUTHORIZATION_AMOUNT_FULL = 2;
108:
109: 110: 111: 112:
113: const REQUIRE_BILLING_ADDRESS_NO = 0;
114: const REQUIRE_BILLING_ADDRESS_ALL = 1;
115: const REQUIRE_BILLING_ADDRESS_VIRTUAL = 2;
116:
117: 118: 119: 120:
121: const FRAUD_ACTION_ACCEPT = 'Acept';
122: const FRAUD_ACTION_DENY = 'Deny';
123:
124: 125: 126: 127:
128: const REFUND_TYPE_FULL = 'Full';
129: const REFUND_TYPE_PARTIAL = 'Partial';
130:
131: 132: 133: 134:
135: const EC_SOLUTION_TYPE_SOLE = 'Sole';
136: const EC_SOLUTION_TYPE_MARK = 'Mark';
137:
138: 139: 140: 141: 142:
143: const WPS_TRANSPORT_IPN = 'ipn';
144: const WPS_TRANSPORT_PDT = 'pdt';
145: const WPS_TRANSPORT_IPN_PDT = 'ipn_n_pdt';
146:
147: 148: 149: 150: 151:
152: const EC_BA_SIGNUP_AUTO = 'auto';
153: const EC_BA_SIGNUP_ASK = 'ask';
154: const EC_BA_SIGNUP_NEVER = 'never';
155:
156: 157: 158: 159: 160:
161: public $centinelDefaultApiUrl = 'https://paypal.cardinalcommerce.com/maps/txns.asp';
162:
163: 164: 165: 166:
167: protected $_methodCode = null;
168:
169: 170: 171: 172: 173:
174: protected $_storeId = null;
175:
176: 177: 178: 179: 180:
181: protected $_buildNotationPPMap = array(
182: 'paypal_standard' => 'WPS',
183: 'paypal_express' => 'EC',
184: 'paypal_direct' => 'DP',
185: 'paypaluk_express' => 'EC',
186: 'paypaluk_direct' => 'DP',
187: );
188:
189: 190: 191: 192: 193:
194: protected $_ecStyleConfigMap = array(
195: 'page_style' => 'page_style',
196: 'paypal_hdrimg' => 'hdrimg',
197: 'paypal_hdrbordercolor' => 'hdrbordercolor',
198: 'paypal_hdrbackcolor' => 'hdrbackcolor',
199: 'paypal_payflowcolor' => 'payflowcolor',
200: );
201:
202: 203: 204: 205: 206:
207: protected $_supportedCurrencyCodes = array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN',
208: 'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD', 'TWD', 'THB');
209:
210: 211: 212: 213: 214:
215: protected $_supportedCountryCodes = array(
216: 'AE','AR','AT','AU','BE','BG','BR','CA','CH','CL','CR','CY','CZ','DE','DK','DO','EC','EE','ES','FI','FR','GB',
217: 'GF','GI','GP','GR','HK','HU','ID','IE','IL','IN','IS','IT','JM','JP','KR','LI','LT','LU','LV','MQ','MT','MX',
218: 'MY','NL','NO','NZ','PH','PL','PT','RE','RO','SE','SG','SI','SK','SM','TH','TR','TW','US','UY','VE','VN','ZA');
219:
220: 221: 222: 223: 224:
225: protected $_supportedBuyerCountryCodes = array(
226: 'AF ', 'AX ', 'AL ', 'DZ ', 'AS ', 'AD ', 'AO ', 'AI ', 'AQ ', 'AG ', 'AR ', 'AM ', 'AW ', 'AU ', 'AT ', 'AZ ',
227: 'BS ', 'BH ', 'BD ', 'BB ', 'BY ', 'BE ', 'BZ ', 'BJ ', 'BM ', 'BT ', 'BO ', 'BA ', 'BW ', 'BV ', 'BR ', 'IO ',
228: 'BN ', 'BG ', 'BF ', 'BI ', 'KH ', 'CM ', 'CA ', 'CV ', 'KY ', 'CF ', 'TD ', 'CL ', 'CN ', 'CX ', 'CC ', 'CO ',
229: 'KM ', 'CG ', 'CD ', 'CK ', 'CR ', 'CI ', 'HR ', 'CU ', 'CY ', 'CZ ', 'DK ', 'DJ ', 'DM ', 'DO ', 'EC ', 'EG ',
230: 'SV ', 'GQ ', 'ER ', 'EE ', 'ET ', 'FK ', 'FO ', 'FJ ', 'FI ', 'FR ', 'GF ', 'PF ', 'TF ', 'GA ', 'GM ', 'GE ',
231: 'DE ', 'GH ', 'GI ', 'GR ', 'GL ', 'GD ', 'GP ', 'GU ', 'GT ', 'GG ', 'GN ', 'GW ', 'GY ', 'HT ', 'HM ', 'VA ',
232: 'HN ', 'HK ', 'HU ', 'IS ', 'IN ', 'ID ', 'IR ', 'IQ ', 'IE ', 'IM ', 'IL ', 'IT ', 'JM ', 'JP ', 'JE ', 'JO ',
233: 'KZ ', 'KE ', 'KI ', 'KP ', 'KR ', 'KW ', 'KG ', 'LA ', 'LV ', 'LB ', 'LS ', 'LR ', 'LY ', 'LI ', 'LT ', 'LU ',
234: 'MO ', 'MK ', 'MG ', 'MW ', 'MY ', 'MV ', 'ML ', 'MT ', 'MH ', 'MQ ', 'MR ', 'MU ', 'YT ', 'MX ', 'FM ', 'MD ',
235: 'MC ', 'MN ', 'MS ', 'MA ', 'MZ ', 'MM ', 'NA ', 'NR ', 'NP ', 'NL ', 'AN ', 'NC ', 'NZ ', 'NI ', 'NE ', 'NG ',
236: 'NU ', 'NF ', 'MP ', 'NO ', 'OM ', 'PK ', 'PW ', 'PS ', 'PA ', 'PG ', 'PY ', 'PE ', 'PH ', 'PN ', 'PL ', 'PT ',
237: 'PR ', 'QA ', 'RE ', 'RO ', 'RU ', 'RW ', 'SH ', 'KN ', 'LC ', 'PM ', 'VC ', 'WS ', 'SM ', 'ST ', 'SA ', 'SN ',
238: 'CS ', 'SC ', 'SL ', 'SG ', 'SK ', 'SI ', 'SB ', 'SO ', 'ZA ', 'GS ', 'ES ', 'LK ', 'SD ', 'SR ', 'SJ ', 'SZ ',
239: 'SE ', 'CH ', 'SY ', 'TW ', 'TJ ', 'TZ ', 'TH ', 'TL ', 'TG ', 'TK ', 'TO ', 'TT ', 'TN ', 'TR ', 'TM ', 'TC ',
240: 'TV ', 'UG ', 'UA ', 'AE ', 'GB ', 'US ', 'UM ', 'UY ', 'UZ ', 'VU ', 'VE ', 'VN ', 'VG ', 'VI ', 'WF ', 'EH ',
241: 'YE ', 'ZM ', 'ZW'
242: );
243:
244: 245: 246: 247: 248: 249:
250: protected $_supportedImageLocales = array('de_DE', 'en_AU', 'en_GB', 'en_US', 'es_ES', 'es_XC', 'fr_FR',
251: 'fr_XC', 'it_IT', 'ja_JP', 'nl_NL', 'pl_PL', 'zh_CN', 'zh_XC',
252: );
253:
254: 255: 256: 257: 258:
259: public function __construct($params = array())
260: {
261: if ($params) {
262: $method = array_shift($params);
263: $this->setMethod($method);
264: if ($params) {
265: $storeId = array_shift($params);
266: $this->setStoreId($storeId);
267: }
268: }
269: }
270:
271: 272: 273: 274: 275: 276:
277: public function setMethod($method)
278: {
279: if ($method instanceof Mage_Payment_Model_Method_Abstract) {
280: $this->_methodCode = $method->getCode();
281: } elseif (is_string($method)) {
282: $this->_methodCode = $method;
283: }
284: return $this;
285: }
286:
287: 288: 289: 290: 291:
292: public function getMethodCode()
293: {
294: return $this->_methodCode;
295: }
296:
297: 298: 299: 300: 301: 302:
303: public function setStoreId($storeId)
304: {
305: $this->_storeId = (int)$storeId;
306: return $this;
307: }
308:
309: 310: 311: 312: 313: 314:
315: public function isMethodActive($method)
316: {
317: if ($this->isMethodSupportedForCountry($method)
318: && Mage::getStoreConfigFlag("payment/{$method}/active", $this->_storeId)
319: ) {
320: return true;
321: }
322: return false;
323: }
324:
325: 326: 327: 328: 329: 330: 331:
332: public function isMethodAvailable($methodCode = null)
333: {
334: if ($methodCode === null) {
335: $methodCode = $this->getMethodCode();
336: }
337:
338: $result = true;
339:
340: if (!$this->isMethodActive($methodCode)) {
341: $result = false;
342: }
343:
344: switch ($methodCode) {
345: case self::METHOD_WPS:
346: if (!$this->businessAccount) {
347: $result = false;
348: break;
349: }
350:
351: if ($this->isMethodActive(self::METHOD_WPP_DIRECT)
352: || $this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) {
353: $result = false;
354: }
355: break;
356: case self::METHOD_WPP_EXPRESS:
357:
358: if ($this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) {
359: $result = false;
360: } elseif ($this->isMethodActive(self::METHOD_WPP_DIRECT)) {
361: $result = true;
362: }
363: break;
364: case self::METHOD_WPP_PE_EXPRESS:
365:
366: if ($this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) {
367: $result = true;
368: } elseif (!$this->isMethodActive(self::METHOD_WPP_PE_DIRECT)
369: && !$this->isMethodActive(self::METHOD_PAYFLOWPRO)) {
370: $result = false;
371: }
372: break;
373: case self::METHOD_BILLING_AGREEMENT:
374: $result = $this->isWppApiAvailabe();
375: break;
376: case self::METHOD_WPP_DIRECT:
377: case self::METHOD_WPP_PE_DIRECT:
378: break;
379: }
380: return $result;
381: }
382:
383: 384: 385: 386: 387: 388: 389: 390: 391:
392: public function __get($key)
393: {
394: $underscored = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $key));
395: $value = Mage::getStoreConfig($this->_getSpecificConfigPath($underscored), $this->_storeId);
396: $value = $this->_prepareValue($underscored, $value);
397: $this->$key = $value;
398: $this->$underscored = $value;
399: return $value;
400: }
401:
402: 403: 404: 405: 406: 407: 408:
409: protected function _prepareValue($key, $value)
410: {
411:
412: if ($key == 'payment_action'
413: && $value != self::PAYMENT_ACTION_SALE
414: && $this->_methodCode == self::METHOD_WPP_EXPRESS
415: && $this->shouldUseUnilateralPayments())
416: {
417: return self::PAYMENT_ACTION_SALE;
418: }
419: return $value;
420: }
421:
422: 423: 424: 425: 426:
427: public function getSupportedMerchantCountryCodes()
428: {
429: return $this->_supportedCountryCodes;
430: }
431:
432: 433: 434: 435: 436:
437: public function getSupportedBuyerCountryCodes()
438: {
439: return $this->_supportedBuyerCountryCodes;
440: }
441:
442: 443: 444: 445: 446:
447: public function getMerchantCountry()
448: {
449: $countryCode = Mage::getStoreConfig($this->_mapGeneralFieldset('merchant_country'), $this->_storeId);
450: if (!$countryCode) {
451: $countryCode = Mage::helper('core')->getDefaultCountry($this->_storeId);
452: }
453: return $countryCode;
454: }
455:
456: 457: 458: 459: 460: 461:
462: public function isMethodSupportedForCountry($method = null, $countryCode = null)
463: {
464: if ($method === null) {
465: $method = $this->getMethodCode();
466: }
467: if ($countryCode === null) {
468: $countryCode = $this->getMerchantCountry();
469: }
470: $countryMethods = $this->getCountryMethods($countryCode);
471: if (in_array($method, $countryMethods)) {
472: return true;
473: }
474: return false;
475: }
476:
477: 478: 479: 480: 481: 482:
483: public function getCountryMethods($countryCode = null)
484: {
485: $countryMethods = array(
486: 'other' => array(
487: self::METHOD_WPS,
488: self::METHOD_WPP_EXPRESS,
489: self::METHOD_BILLING_AGREEMENT,
490: ),
491: 'US' => array(
492: self::METHOD_PAYFLOWADVANCED,
493: self::METHOD_WPP_DIRECT,
494: self::METHOD_WPS,
495: self::METHOD_PAYFLOWPRO,
496: self::METHOD_PAYFLOWLINK,
497: self::METHOD_WPP_EXPRESS,
498: self::METHOD_BILLING_AGREEMENT,
499: self::METHOD_WPP_PE_EXPRESS,
500: ),
501: 'CA' => array(
502: self::METHOD_WPP_DIRECT,
503: self::METHOD_WPS,
504: self::METHOD_PAYFLOWPRO,
505: self::METHOD_PAYFLOWLINK,
506: self::METHOD_WPP_EXPRESS,
507: self::METHOD_BILLING_AGREEMENT,
508: ),
509: 'GB' => array(
510: self::METHOD_WPP_DIRECT,
511: self::METHOD_WPS,
512: self::METHOD_WPP_PE_DIRECT,
513: self::METHOD_HOSTEDPRO,
514: self::METHOD_WPP_EXPRESS,
515: self::METHOD_BILLING_AGREEMENT,
516: self::METHOD_WPP_PE_EXPRESS,
517: ),
518: 'AU' => array(
519: self::METHOD_WPS,
520: self::METHOD_PAYFLOWPRO,
521: self::METHOD_HOSTEDPRO,
522: self::METHOD_WPP_EXPRESS,
523: self::METHOD_BILLING_AGREEMENT,
524: ),
525: 'NZ' => array(
526: self::METHOD_WPS,
527: self::METHOD_PAYFLOWPRO,
528: self::METHOD_WPP_EXPRESS,
529: self::METHOD_BILLING_AGREEMENT,
530: ),
531: 'JP' => array(
532: self::METHOD_WPS,
533: self::METHOD_HOSTEDPRO,
534: self::METHOD_WPP_EXPRESS,
535: self::METHOD_BILLING_AGREEMENT,
536: ),
537: 'FR' => array(
538: self::METHOD_WPS,
539: self::METHOD_HOSTEDPRO,
540: self::METHOD_WPP_EXPRESS,
541: self::METHOD_BILLING_AGREEMENT,
542: ),
543: 'IT' => array(
544: self::METHOD_WPS,
545: self::METHOD_HOSTEDPRO,
546: self::METHOD_WPP_EXPRESS,
547: self::METHOD_BILLING_AGREEMENT,
548: ),
549: 'ES' => array(
550: self::METHOD_WPS,
551: self::METHOD_HOSTEDPRO,
552: self::METHOD_WPP_EXPRESS,
553: self::METHOD_BILLING_AGREEMENT,
554: ),
555: 'HK' => array(
556: self::METHOD_WPS,
557: self::METHOD_HOSTEDPRO,
558: self::METHOD_WPP_EXPRESS,
559: self::METHOD_BILLING_AGREEMENT,
560: ),
561: );
562: if ($countryCode === null) {
563: return $countryMethods;
564: }
565: return isset($countryMethods[$countryCode]) ? $countryMethods[$countryCode] : $countryMethods['other']; }
566:
567: 568: 569: 570: 571: 572:
573: public function getExpressCheckoutStartUrl($token)
574: {
575: return $this->getPaypalUrl(array(
576: 'cmd' => '_express-checkout',
577: 'token' => $token,
578: ));
579: }
580:
581: 582: 583: 584: 585: 586:
587: public function getExpressCheckoutEditUrl($token)
588: {
589: return $this->getPaypalUrl(array(
590: 'cmd' => '_express-checkout',
591: 'useraction' => 'continue',
592: 'token' => $token,
593: ));
594: }
595:
596: 597: 598: 599: 600: 601: 602:
603: public function getExpressCheckoutCompleteUrl($token)
604: {
605: return $this->getPaypalUrl(array(
606: 'cmd' => '_complete-express-checkout',
607: 'token' => $token,
608: ));
609: }
610:
611: 612: 613: 614: 615: 616:
617: public function getStartBillingAgreementUrl($token)
618: {
619: return $this->getPaypalUrl(array(
620: 'cmd' => '_customer-billing-agreement',
621: 'token' => $token,
622: ));
623: }
624:
625: 626: 627: 628: 629: 630:
631: public function getPaypalUrl(array $params = array())
632: {
633: return sprintf('https://www.%spaypal.com/webscr%s',
634: $this->sandboxFlag ? 'sandbox.' : '',
635: $params ? '?' . http_build_query($params) : ''
636: );
637: }
638:
639: 640: 641: 642: 643:
644: public function areButtonsDynamic()
645: {
646: return $this->buttonFlavor === self::EC_FLAVOR_DYNAMIC;
647: }
648:
649: 650: 651: 652: 653: 654: 655: 656: 657:
658: public function getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal = null, $pal = null)
659: {
660: if ($this->areButtonsDynamic()) {
661: return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_SHORTCUT, $localeCode, $orderTotal, $pal);
662: }
663: if ($this->buttonType === self::EC_BUTTON_TYPE_MARK) {
664: return $this->getPaymentMarkImageUrl($localeCode);
665: }
666: return sprintf('https://www.paypal.com/%s/i/btn/btn_xpressCheckout.gif',
667: $this->_getSupportedLocaleCode($localeCode));
668: }
669:
670: 671: 672: 673: 674: 675: 676: 677: 678: 679:
680: public function getPaymentMarkImageUrl($localeCode, $orderTotal = null, $pal = null, $staticSize = null)
681: {
682: if ($this->areButtonsDynamic()) {
683: return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_MARK, $localeCode, $orderTotal, $pal);
684: }
685:
686: if (null === $staticSize) {
687: $staticSize = $this->paymentMarkSize;
688: }
689: switch ($staticSize) {
690: case self::PAYMENT_MARK_37x23:
691: case self::PAYMENT_MARK_50x34:
692: case self::PAYMENT_MARK_60x38:
693: case self::PAYMENT_MARK_180x113:
694: break;
695: default:
696: $staticSize = self::PAYMENT_MARK_37x23;
697: }
698: return sprintf('https://www.paypal.com/%s/i/logo/PayPal_mark_%s.gif',
699: $this->_getSupportedLocaleCode($localeCode), $staticSize);
700: }
701:
702: 703: 704: 705: 706: 707:
708: public function getPaymentMarkWhatIsPaypalUrl(Mage_Core_Model_Locale $locale = null)
709: {
710: $countryCode = 'US';
711: if (null !== $locale) {
712: $shouldEmulate = (null !== $this->_storeId) && (Mage::app()->getStore()->getId() != $this->_storeId);
713: if ($shouldEmulate) {
714: $locale->emulate($this->_storeId);
715: }
716: $countryCode = $locale->getLocale()->getRegion();
717: if ($shouldEmulate) {
718: $locale->revert();
719: }
720: }
721: return sprintf('https://www.paypal.com/%s/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside',
722: strtolower($countryCode)
723: );
724: }
725:
726: 727: 728: 729: 730: 731: 732:
733: public function getSolutionImageUrl($localeCode, $isVertical = false, $isEcheck = false)
734: {
735: return sprintf('https://www.paypal.com/%s/i/bnr/%s_solution_PP%s.gif',
736: $this->_getSupportedLocaleCode($localeCode),
737: $isVertical ? 'vertical' : 'horizontal', $isEcheck ? 'eCheck' : ''
738: );
739: }
740:
741: 742: 743: 744: 745:
746: public function getPaymentFormLogoUrl($localeCode)
747: {
748: $locale = $this->_getSupportedLocaleCode($localeCode);
749:
750: $imageType = 'logo';
751: $domain = 'paypal.com';
752: list (,$country) = explode('_', $locale);
753: $countryPrefix = $country . '/';
754:
755: switch ($locale) {
756: case 'en_GB':
757: $imageName = 'horizontal_solution_PP';
758: $imageType = 'bnr';
759: $countryPrefix = '';
760: break;
761: case 'de_DE':
762: $imageName = 'lockbox_150x47';
763: break;
764: case 'fr_FR':
765: $imageName = 'bnr_horizontal_solution_PP_327wx80h';
766: $imageType = 'bnr';
767: $locale = 'en_US';
768: $domain = 'paypalobjects.com';
769: break;
770: case 'it_IT':
771: $imageName = 'bnr_horizontal_solution_PP_178wx80h';
772: $imageType = 'bnr';
773: $domain = 'paypalobjects.com';
774: break;
775: default:
776: $imageName='PayPal_mark_60x38';
777: $countryPrefix = '';
778: break;
779: }
780: return sprintf('https://www.%s/%s/%si/%s/%s.gif', $domain, $locale, $countryPrefix, $imageType, $imageName);
781: }
782:
783: 784: 785: 786: 787:
788: public function getAdditionalOptionsLogoTypes()
789: {
790: return array(
791: 'wePrefer_150x60' => Mage::helper('paypal')->__('We prefer PayPal (150 X 60)'),
792: 'wePrefer_150x40' => Mage::helper('paypal')->__('We prefer PayPal (150 X 40)'),
793: 'nowAccepting_150x60' => Mage::helper('paypal')->__('Now accepting PayPal (150 X 60)'),
794: 'nowAccepting_150x40' => Mage::helper('paypal')->__('Now accepting PayPal (150 X 40)'),
795: 'paymentsBy_150x60' => Mage::helper('paypal')->__('Payments by PayPal (150 X 60)'),
796: 'paymentsBy_150x40' => Mage::helper('paypal')->__('Payments by PayPal (150 X 40)'),
797: 'shopNowUsing_150x60' => Mage::helper('paypal')->__('Shop now using (150 X 60)'),
798: 'shopNowUsing_150x40' => Mage::helper('paypal')->__('Shop now using (150 X 40)'),
799: );
800: }
801:
802: 803: 804: 805: 806: 807: 808:
809: public function getAdditionalOptionsLogoUrl($localeCode, $type = false)
810: {
811: $configType = Mage::getStoreConfig($this->_mapGenericStyleFieldset('logo'), $this->_storeId);
812: if (!$configType) {
813: return false;
814: }
815: $type = $type ? $type : $configType;
816: $locale = $this->_getSupportedLocaleCode($localeCode);
817: $supportedTypes = array_keys($this->getAdditionalOptionsLogoTypes());
818: if (!in_array($type, $supportedTypes)) {
819: $type = self::DEFAULT_LOGO_TYPE;
820: }
821: return sprintf('https://www.paypalobjects.com/%s/i/bnr/bnr_%s.gif', $locale, $type);
822: }
823:
824: 825: 826: 827: 828:
829: public function getBuildNotationCode($countryCode = null)
830: {
831: $product = 'WPP';
832: if ($this->_methodCode && isset($this->_buildNotationPPMap[$this->_methodCode])) {
833: $product = $this->_buildNotationPPMap[$this->_methodCode];
834: }
835: if (null === $countryCode) {
836: $countryCode = $this->_matchBnCountryCode($this->getMerchantCountry());
837: }
838: if ($countryCode) {
839: $countryCode = '_' . $countryCode;
840: }
841: return sprintf('Varien_Cart_%s%s', $product, $countryCode);
842: }
843:
844: 845: 846: 847: 848:
849: public function getExpressCheckoutButtonFlavors()
850: {
851: return array(
852: self::EC_FLAVOR_DYNAMIC => Mage::helper('paypal')->__('Dynamic'),
853: self::EC_FLAVOR_STATIC => Mage::helper('paypal')->__('Static'),
854: );
855: }
856:
857: 858: 859: 860: 861:
862: public function getExpressCheckoutButtonTypes()
863: {
864: return array(
865: self::EC_BUTTON_TYPE_SHORTCUT => Mage::helper('paypal')->__('Shortcut'),
866: self::EC_BUTTON_TYPE_MARK => Mage::helper('paypal')->__('Acceptance Mark Image'),
867: );
868: }
869:
870: 871: 872: 873: 874:
875: public function getPaymentActions()
876: {
877: $paymentActions = array(
878: self::PAYMENT_ACTION_AUTH => Mage::helper('paypal')->__('Authorization'),
879: self::PAYMENT_ACTION_SALE => Mage::helper('paypal')->__('Sale')
880: );
881: if (!is_null($this->_methodCode) && $this->_methodCode == self::METHOD_WPP_EXPRESS) {
882: $paymentActions[self::PAYMENT_ACTION_ORDER] = Mage::helper('paypal')->__('Order');
883: }
884: return $paymentActions;
885: }
886:
887: 888: 889: 890: 891:
892: public function getRequireBillingAddressOptions()
893: {
894: return array(
895: self::REQUIRE_BILLING_ADDRESS_ALL => Mage::helper('paypal')->__('Yes'),
896: self::REQUIRE_BILLING_ADDRESS_NO => Mage::helper('paypal')->__('No'),
897: self::REQUIRE_BILLING_ADDRESS_VIRTUAL => Mage::helper('paypal')->__('For Virtual Quotes Only'),
898: );
899: }
900:
901: 902: 903: 904: 905:
906: public function getPaymentAction()
907: {
908: switch ($this->paymentAction) {
909: case self::PAYMENT_ACTION_AUTH:
910: return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
911: case self::PAYMENT_ACTION_SALE:
912: return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE;
913: case self::PAYMENT_ACTION_ORDER:
914: return Mage_Payment_Model_Method_Abstract::ACTION_ORDER;
915: }
916: }
917:
918: 919: 920: 921: 922: 923:
924: public function getAuthorizationAmounts()
925: {
926: return array();
927: }
928:
929: 930: 931: 932: 933: 934: 935:
936: public function getExpressCheckoutSolutionTypes()
937: {
938: return array(
939: self::EC_SOLUTION_TYPE_SOLE => Mage::helper('paypal')->__('Yes'),
940: self::EC_SOLUTION_TYPE_MARK => Mage::helper('paypal')->__('No'),
941: );
942: }
943:
944: 945: 946: 947: 948:
949: public function getExpressCheckoutBASignupOptions()
950: {
951: return array(
952: self::EC_BA_SIGNUP_AUTO => Mage::helper('paypal')->__('Auto'),
953: self::EC_BA_SIGNUP_ASK => Mage::helper('paypal')->__('Ask Customer'),
954: self::EC_BA_SIGNUP_NEVER => Mage::helper('paypal')->__('Never')
955: );
956: }
957:
958: 959: 960: 961: 962: 963:
964: public function shouldAskToCreateBillingAgreement()
965: {
966: return ($this->allow_ba_signup === self::EC_BA_SIGNUP_ASK) && !$this->shouldUseUnilateralPayments();
967: }
968:
969: 970: 971: 972: 973:
974: public function shouldUseUnilateralPayments()
975: {
976: return $this->business_account && !$this->isWppApiAvailabe();
977: }
978:
979: 980: 981: 982: 983:
984: public function isWppApiAvailabe()
985: {
986: return $this->api_username && $this->api_password && ($this->api_signature || $this->api_cert);
987: }
988:
989: 990: 991: 992: 993:
994: public function getWpsPaymentDeliveryMethods()
995: {
996: return array(
997: self::WPS_TRANSPORT_IPN => Mage::helper('adminhtml')->__('IPN (Instant Payment Notification) Only'),
998:
999:
1000:
1001: );
1002: }
1003:
1004: 1005: 1006: 1007: 1008:
1009: public function getWppCcTypesAsOptionArray()
1010: {
1011: $model = Mage::getModel('payment/source_cctype')->setAllowedTypes(array('AE', 'VI', 'MC', 'SM', 'SO', 'DI'));
1012: return $model->toOptionArray();
1013: }
1014:
1015: 1016: 1017: 1018: 1019:
1020: public function getWppPeCcTypesAsOptionArray()
1021: {
1022: $model = Mage::getModel('payment/source_cctype')->setAllowedTypes(array('VI', 'MC', 'SM', 'SO', 'OT', 'AE'));
1023: return $model->toOptionArray();
1024: }
1025:
1026: 1027: 1028: 1029: 1030:
1031: public function getPayflowproCcTypesAsOptionArray()
1032: {
1033: $model = Mage::getModel('payment/source_cctype')->setAllowedTypes(array('AE', 'VI', 'MC', 'JCB', 'DI'));
1034: return $model->toOptionArray();
1035: }
1036:
1037: 1038: 1039: 1040: 1041: 1042:
1043: public static function getIsCreditCardMethod($code)
1044: {
1045: switch ($code) {
1046: case self::METHOD_WPP_DIRECT:
1047: case self::METHOD_WPP_PE_DIRECT:
1048: case self::METHOD_PAYFLOWPRO:
1049: case self::METHOD_PAYFLOWLINK:
1050: case self::METHOD_PAYFLOWADVANCED:
1051: case self::METHOD_HOSTEDPRO:
1052: return true;
1053: }
1054: return false;
1055: }
1056:
1057: 1058: 1059: 1060: 1061: 1062:
1063: public function isCurrencyCodeSupported($code)
1064: {
1065: if (in_array($code, $this->_supportedCurrencyCodes)) {
1066: return true;
1067: }
1068: if ($this->getMerchantCountry() == 'BR' && $code == 'BRL') {
1069: return true;
1070: }
1071: if ($this->getMerchantCountry() == 'MY' && $code == 'MYR') {
1072: return true;
1073: }
1074: return false;
1075: }
1076:
1077: 1078: 1079: 1080: 1081:
1082: public function exportExpressCheckoutStyleSettings(Varien_Object $to)
1083: {
1084: foreach ($this->_ecStyleConfigMap as $key => $exportKey) {
1085: if ($this->$key) {
1086: $to->setData($exportKey, $this->$key);
1087: }
1088: }
1089: }
1090:
1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099:
1100: protected function _getDynamicImageUrl($type, $localeCode, $orderTotal, $pal)
1101: {
1102: $params = array(
1103: 'cmd' => '_dynamic-image',
1104: 'buttontype' => $type,
1105: 'locale' => $this->_getSupportedLocaleCode($localeCode),
1106: );
1107: if ($orderTotal) {
1108: $params['ordertotal'] = sprintf('%.2F', $orderTotal);
1109: if ($pal) {
1110: $params['pal'] = $pal;
1111: }
1112: }
1113: return sprintf('https://fpdbs%s.paypal.com/dynamicimageweb?%s',
1114: $this->sandboxFlag ? '.sandbox' : '', http_build_query($params)
1115: );
1116: }
1117:
1118: 1119: 1120: 1121: 1122: 1123:
1124: protected function _getSupportedLocaleCode($localeCode = null)
1125: {
1126: if (!$localeCode || !in_array($localeCode, $this->_supportedImageLocales)) {
1127: return 'en_US';
1128: }
1129: return $localeCode;
1130: }
1131:
1132: 1133: 1134: 1135: 1136: 1137:
1138: protected function _getSpecificConfigPath($fieldName)
1139: {
1140: $path = null;
1141: switch ($this->_methodCode) {
1142: case self::METHOD_WPS:
1143: $path = $this->_mapStandardFieldset($fieldName);
1144: break;
1145: case self::METHOD_WPP_EXPRESS:
1146: case self::METHOD_WPP_PE_EXPRESS:
1147: $path = $this->_mapExpressFieldset($fieldName);
1148: break;
1149: case self::METHOD_WPP_DIRECT:
1150: case self::METHOD_WPP_PE_DIRECT:
1151: $path = $this->_mapDirectFieldset($fieldName);
1152: break;
1153: case self::METHOD_BILLING_AGREEMENT:
1154: case self::METHOD_HOSTEDPRO:
1155: $path = $this->_mapMethodFieldset($fieldName);
1156: break;
1157: }
1158:
1159: if ($path === null) {
1160: switch ($this->_methodCode) {
1161: case self::METHOD_WPP_EXPRESS:
1162: case self::METHOD_WPP_DIRECT:
1163: case self::METHOD_BILLING_AGREEMENT:
1164: case self::METHOD_HOSTEDPRO:
1165: $path = $this->_mapWppFieldset($fieldName);
1166: break;
1167: case self::METHOD_WPP_PE_EXPRESS:
1168: case self::METHOD_WPP_PE_DIRECT:
1169: $path = $this->_mapWpukFieldset($fieldName);
1170: break;
1171: }
1172: }
1173:
1174: if ($path === null) {
1175: $path = $this->_mapGeneralFieldset($fieldName);
1176: }
1177: if ($path === null) {
1178: $path = $this->_mapGenericStyleFieldset($fieldName);
1179: }
1180: return $path;
1181: }
1182:
1183: 1184: 1185: 1186: 1187: 1188:
1189: private function _matchBnCountryCode($code)
1190: {
1191: switch ($code) {
1192:
1193: case 'GB':
1194: return 'UK';
1195:
1196: case 'AU': case 'AT': case 'BE': case 'CA': case 'CN': case 'FR': case 'DE': case 'HK': case 'IT':
1197:
1198: case 'JP': case 'MX': case 'NL': case 'PL': case 'SG': case 'ES': case 'CH': case 'UK': case 'US':
1199: return $code;
1200: }
1201: }
1202:
1203: 1204: 1205: 1206: 1207: 1208:
1209: protected function _mapStandardFieldset($fieldName)
1210: {
1211: switch ($fieldName)
1212: {
1213: case 'line_items_summary':
1214: case 'sandbox_flag':
1215: return 'payment/' . self::METHOD_WPS . "/{$fieldName}";
1216: default:
1217: return $this->_mapMethodFieldset($fieldName);
1218: }
1219: }
1220:
1221: 1222: 1223: 1224: 1225: 1226:
1227: protected function _mapExpressFieldset($fieldName)
1228: {
1229: switch ($fieldName)
1230: {
1231: case 'transfer_shipping_options':
1232: case 'solution_type':
1233: case 'visible_on_cart':
1234: case 'visible_on_product':
1235: case 'require_billing_address':
1236: case 'authorization_honor_period':
1237: case 'order_valid_period':
1238: case 'child_authorization_number':
1239: case 'allow_ba_signup':
1240: return "payment/{$this->_methodCode}/{$fieldName}";
1241: default:
1242: return $this->_mapMethodFieldset($fieldName);
1243: }
1244: }
1245:
1246: 1247: 1248: 1249: 1250: 1251:
1252: protected function _mapDirectFieldset($fieldName)
1253: {
1254: switch ($fieldName)
1255: {
1256: case 'useccv':
1257: case 'centinel':
1258: case 'centinel_is_mode_strict':
1259: case 'centinel_api_url':
1260: return "payment/{$this->_methodCode}/{$fieldName}";
1261: default:
1262: return $this->_mapMethodFieldset($fieldName);
1263: }
1264: }
1265:
1266: 1267: 1268: 1269: 1270: 1271:
1272: protected function _mapWppFieldset($fieldName)
1273: {
1274: switch ($fieldName)
1275: {
1276: case 'api_authentication':
1277: case 'api_username':
1278: case 'api_password':
1279: case 'api_signature':
1280: case 'api_cert':
1281: case 'sandbox_flag':
1282: case 'use_proxy':
1283: case 'proxy_host':
1284: case 'proxy_port':
1285: case 'button_flavor':
1286: return "paypal/wpp/{$fieldName}";
1287: default:
1288: return null;
1289: }
1290: }
1291:
1292: 1293: 1294: 1295: 1296: 1297:
1298: protected function _mapWpukFieldset($fieldName)
1299: {
1300: $pathPrefix = 'paypal/wpuk';
1301:
1302: if ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS
1303: && !$this->isMethodAvailable(self::METHOD_WPP_PE_DIRECT)) {
1304: $pathPrefix = 'payment/verisign';
1305: }
1306: switch ($fieldName) {
1307: case 'partner':
1308: case 'user':
1309: case 'vendor':
1310: case 'pwd':
1311: case 'sandbox_flag':
1312: case 'use_proxy':
1313: case 'proxy_host':
1314: case 'proxy_port':
1315: return $pathPrefix . '/' . $fieldName;
1316: default:
1317: return null;
1318: }
1319: }
1320:
1321: 1322: 1323: 1324: 1325: 1326:
1327: protected function _mapGenericStyleFieldset($fieldName)
1328: {
1329: switch ($fieldName) {
1330: case 'logo':
1331: case 'page_style':
1332: case 'paypal_hdrimg':
1333: case 'paypal_hdrbackcolor':
1334: case 'paypal_hdrbordercolor':
1335: case 'paypal_payflowcolor':
1336: return "paypal/style/{$fieldName}";
1337: default:
1338: return null;
1339: }
1340: }
1341:
1342: 1343: 1344: 1345: 1346: 1347:
1348: protected function _mapGeneralFieldset($fieldName)
1349: {
1350: switch ($fieldName)
1351: {
1352: case 'business_account':
1353: case 'merchant_country':
1354: return "paypal/general/{$fieldName}";
1355: default:
1356: return null;
1357: }
1358: }
1359:
1360: 1361: 1362: 1363: 1364: 1365:
1366: protected function _mapMethodFieldset($fieldName)
1367: {
1368: if (!$this->_methodCode) {
1369: return null;
1370: }
1371: switch ($fieldName)
1372: {
1373: case 'active':
1374: case 'title':
1375: case 'payment_action':
1376: case 'allowspecific':
1377: case 'specificcountry':
1378: case 'line_items_enabled':
1379: case 'cctypes':
1380: case 'sort_order':
1381: case 'debug':
1382: case 'verify_peer':
1383: return "payment/{$this->_methodCode}/{$fieldName}";
1384: default:
1385: return null;
1386: }
1387: }
1388:
1389: 1390: 1391: 1392: 1393:
1394: public function getApiAuthenticationMethods()
1395: {
1396: return array(
1397: '0' => Mage::helper('paypal')->__('API Signature'),
1398: '1' => Mage::helper('paypal')->__('API Certificate')
1399: );
1400: }
1401:
1402: 1403: 1404: 1405: 1406:
1407: public function getApiCertificate()
1408: {
1409: $websiteId = Mage::app()->getStore($this->_storeId)->getWebsiteId();
1410: return Mage::getModel('paypal/cert')->loadByWebsite($websiteId, false)->getCertPath();
1411: }
1412: }
1413:
1414: