Example #1
0
 /**
  * MCAPI constructor.
  * @param \SendPulse\Mageia\Helper\Data $helper
  * @param \Magento\Framework\HTTP\Adapter\Curl $curl
  */
 public function __construct(\SendPulse\Mageia\Helper\Data $helper, \Magento\Framework\HTTP\Adapter\Curl $curl)
 {
     $this->_helper = $helper;
     $this->_curl = $curl;
     $this->_apiKey = $helper->getApiKey();
     $this->_secure = false;
 }
Example #2
0
 /**
  * @param \SendPulse\Mageia\Helper\Data $helper
  */
 public function __construct(\SendPulse\Mageia\Helper\Data $helper, \SendPulse\Mageia\Model\Api $api)
 {
     $this->_helper = $helper;
     $this->_api = $api;
     if ($helper->getApiKey() && $helper->getApiSecret()) {
         $this->_options = $this->_api->info();
     }
 }
Example #3
0
 /**
  * SPAPI constructor.
  *
  * @param \SendPulse\Mageia\Helper\Data        $helper
  * @param \Magento\Framework\HTTP\Adapter\Curl $curl
  */
 public function __construct(\SendPulse\Mageia\Helper\Data $helper, \Magento\Framework\HTTP\Adapter\Curl $curl, \Magento\Newsletter\Model\Session $session, \SendPulse\Mageia\Model\Logger\SendPulse $logger)
 {
     $this->_helper = $helper;
     $this->_curl = $curl;
     $this->_apiKey = $helper->getApiKey();
     $this->_apiSecret = $helper->getApiSecret();
     $this->_secure = false;
     $this->_session = $session;
     $this->_logger = $logger;
     $this->_token = $this->getApiToken();
 }
Example #4
0
 public function beforeSubscribeCustomerById($subscriber, $customerId)
 {
     $subscriber->loadByCustomerId($customerId);
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMageiaEnabled($storeId)) {
         $customer = $this->_customer->load($customerId);
         $mergeVars = $this->_helper->getMergeVars($customer);
         $api = $this->_api;
         $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
         if ($this->_helper->isDoubleOptInEnabled($storeId) && !$isSubscribeOwnEmail) {
             $status = 'pending';
         } else {
             $status = 'subscribed';
         }
         if ($mergeVars) {
             $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => $mergeVars);
         } else {
             $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status);
         }
         $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
         if (isset($return->id)) {
             $subscriber->setMageiaId($return->id);
         }
     }
     return [$customerId];
 }
Example #5
0
 public function testGetMergeVars()
 {
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock();
     $this->_scopeMock->expects($this->atLeastOnce())->method('getValue')->willReturn('a:10:{s:18:"_1455130677743_743";a:2:{s:7:"magento";s:5:"fname";s:9:"sendpulse";s:5:"FNAME";}s:18:"_1455132553917_917";a:2:{s:7:"magento";s:5:"lname";s:9:"sendpulse";s:5:"LNAME";}s:18:"_1455132560288_288";a:2:{s:7:"magento";s:6:"gender";s:9:"sendpulse";s:6:"GENDER";}s:18:"_1455132567137_137";a:2:{s:7:"magento";s:3:"dob";s:9:"sendpulse";s:3:"DOB";}s:18:"_1455132573944_944";a:2:{s:7:"magento";s:15:"billing_address";s:9:"sendpulse";s:7:"BILLING";}s:18:"_1455132594111_111";a:2:{s:7:"magento";s:16:"shipping_address";s:9:"sendpulse";s:8:"SHIPPING";}s:17:"_1455132602049_49";a:2:{s:7:"magento";s:9:"telephone";s:9:"sendpulse";s:9:"TELEPHONE";}s:18:"_1455132614663_663";a:2:{s:7:"magento";s:7:"company";s:9:"sendpulse";s:7:"COMPANY";}s:18:"_1455132622855_855";a:2:{s:7:"magento";s:8:"group_id";s:9:"sendpulse";s:6:"CGROUP";}s:18:"_1455132622855_877";a:2:{s:7:"magento";s:10:"middlename";s:9:"sendpulse";s:5:"MNAME";}}');
     $customerMock->expects($this->any())->method('getData')->will($this->returnCallback([$this, '_getData']));
     $billingMock = $this->getMockBuilder('Magento\\Customer\\Model\\Customer\\Address')->disableOriginalConstructor()->setMethods(array('getTelephone', 'getStreetLine', 'getCompany', 'getCity', 'getRegion', 'getPostCode', 'getCountryId'))->getMock();
     $billingMock->expects($this->any())->method('getTelephone')->willReturn('555 1234');
     $billingMock->expects($this->any())->method('getCompany')->willReturn('sendpulse');
     $billingMock->expects($this->any())->method('getStreetLine')->willReturn('here');
     $billingMock->expects($this->any())->method('getCity')->willReturn('los angeles');
     $billingMock->expects($this->any())->method('getRegion')->willReturn('ca');
     $billingMock->expects($this->any())->method('getPostCode')->willReturn('90210');
     $billingMock->expects($this->any())->method('getCountryId')->willReturn('1');
     $customerMock->expects($this->any())->method('getDefaultBillingAddress')->willReturn($billingMock);
     $customerMock->expects($this->any())->method('getDefaultShippingAddress')->willReturn($billingMock);
     $ret = $this->_helper->getMergeVars($customerMock);
     $ret = $this->_helper->getMergeVars($customerMock);
 }
Example #6
0
 public function beforeUnsubscribe($subscriber)
 {
     $subscriber->loadByEmail($subscriber->getEmail());
     if ($subscriber->getMageiaId()) {
         $emails = [$subscriber->getMageiaId()];
         $data = ['emails' => json_encode($emails)];
         $listId = $this->_helper->getDefaultList();
         $return = $this->_api->listDeleteMember($listId, $data);
         if (isset($return->result) && $return->result) {
             $subscriber->setMageiaId('');
             $subscriber->save();
         }
     }
 }