One list, two different thank you pages with Mailchimp - mailchimp

Mailchimp ties each form to one list.
I'd like to have a signup form on Page1.html that sends users to Page1ty.html and another form on Page2.html that sends users to Page2ty.html. But both forms need to feed users into the same list. As stated above, this isn't possible using their basic forms. I would need two list.
Mailchimp says this kind of routing might be possible using their API. Does any one know how to go about accomplishing the above kind of signups?

You would just create custom forms and tie into the MailChimp API, but as of their latest update you'll need to make sure you have administrator privileges.
You include (require) the MCAPI.class.php and config.inc.php files from their API downloads, and then write your process (I use PHP).
Once you have downloaded the files and set up your 'config.inc.php` file with the proper credentials, (API Key and list ID) you're ready to go.
Here's a sample in PHP that subscribes a user to a list, but you'll have to read the API docs to get the exact functionality you're looking for.
<?php
session_start();
// --- Sample fields - depends on your list
$mailChimpTIME = date('Y-m-d H:i:s');
$mailChimpFirstName = // First Name
$mailChimpLastName = // Last Name
$mailChimpEmailAddress = // Email Address
require_once 'MCAPI.class.php';
require_once 'config.inc.php'; //contains apikey
$api = new MCAPI($apikey);
$merge_vars = array(
'FNAME'=>$mailChimpFirstName,
'LNAME'=>$mailChimpLastName,
'EMAIL'=>$mailChimpEmailAddress,
'OPTIN_IP'=>$_SERVER['REMOTE_ADDR'],
'OPTIN_TIME'=>$mailChimpTIME
);
$email_type = 'html';
$double_optin = true;
$update_existing = true;
$replace_interests = false;
// By default this sends a confirmation email - you will not see new members
// until the link contained in it is clicked!
$retval = $api->listSubscribe( $listId, $mailChimpEmailAddress, $merge_vars, $email_type, $double_optin, $update_existing, $replace_interests);
if ($api->errorCode){
echo "Unable to load listSubscribe()!\n";
echo "\tCode=".$api->errorCode."\n";
echo "\tMsg=".$api->errorMessage."\n";
} else {
// Success
//echo "Subscribed - look for the confirmation email!\n";
}
?>

Related

How to get payer email after a success payment wit paypal API (Laravel paypal/rest-api-sdk-php)?

I'm using the paypal API with Laravel, everything works fine. I just need to find the way to get the user email address and name.
$payment = Payment::get($payment_id, $this->_api_context);
$execution = new PaymentExecution();
$execution->setPayerId( $request->query('PayerID') );
$result = $payment->execute($execution, $this->_api_context);
if ($result->getState() == 'approved') {
// I should get the info about the payer here
}
The v1/payments PayPal-PHP-SDK is deprecated, you should not use it for any new integration.
The current supported SDK is the v2/checkout/orders Checkout-PHP-SDK, which you should use instead.
You can try the srmklive package "v3" if you like, otherwise integrate directly.
You should be able to create two routes, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
The capture order response may have details about the payer and payment, if not use can do a 'Get' API call on the order ID for this information. Store it in your database before returning the JSON to the client code.

How do I allow a 3rd party (twilio) access to current user account in laravel

I am making an application using laravel and twilio that gets feedback about student performance. The logic as follows.
A user, in my case the Student(called resident) logs in and uses a
web page form to send an eval request to a teacher (called
attending). This step starts a session and saves teacher info and
student info.
A random question is picked from a database and saved to the session.
The phone number of the teacher is pulled from a database and the random question is pulled from session and sent to the teacher on SMS using twilio.
The teacher responds with yes, no, or DNS (did not see) via Twilio SMS.
The teacher's response along with the student name, the teacher name and the question asked are saved to a database.
My application works up until step 5. The problem is that a new session is being started when the teacher responds via SMS. So everything after the response is saved to a new session. I can't get access to the original session. I think I need a way to automatically grant the teacher access to the student(ie. user's account). This seems to be a problem with it being a 3rd party application. Can this be done or is there another way to accomplish this?
Below is the code I am using for the response. It is not able to access the session that contains the residentName, the firstQuestion, or the attending_name data. It puts null for those values and uploads null to the database. How do I get access to the initial session in this situation?
namespace App\Http\Controllers;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Session;
use Twilio\Rest\Client;
use Twilio\Twiml;
use App\Question;
use App\Answer;
class AskFirstQuestionsController extends Controller
{
public function qOneResponse(Request $request) {
$responderNumber = $request->input('From');
session()->put('responderNumber', $responderNumber);
session()->save();
$responderAnswer = strtolower($request->input('Body'));
$residentName = session::get('residentName');
$firstQuestion = session::get('first_question');
$attending_name = session::get('attending_name');
if (strpos($responderAnswer, 'yes') !== false) {
$answer = new
Answer(['attending'=>$attending_name,'resident_name'=>$residentName,'question_body'
=>$firstQuestion, 'answer_yes'=>1]);
$answer->save();
$smsResponse = "Great! Please help us reinforce this action by providing specific feedback
to the resident about what they did. Thank You for teaching!";
} else if (strpos($responderAnswer, 'no') !== false) {
$answer = new
answer::create(['attending'=>$attending_name,'resident_name'=>$resident_name,'question_body'
=>$firstQuestion, 'answer_no'=>1]);
$answer->save();
$smsResponse = "Ugh, ok...we will work on this. If you feel comfortable, please help us by
providing specific feedback to the resident about what they need to work on. Thank You for
teaching!";
} else if (strpos($responderAnswer, 'dns') !== false) {
$answer = new
answer::create(['attending'=>$attending_name,'resident_name'=>$resident_name,'question_body'
=>$firstQuestion, 'answer_dns'=>1]);
$answer->save();
$smsResponse = "How about trying a different question?";
} else {
$smsResponse = 'Please answer yes, no or dns.';
}
return response($this->respond($smsResponse))->header('Content-Type', 'application/xml');
}
public function respond($smsResponse) {
//get responderNumber and use it below
$responderNumber = session::get('responderNumber');
$response = new Twiml();
$response->message($smsResponse, ['to' => $responderNumber]);
return $response;
}
Do I need to do some type of multiauth approach and somehow grant the teacher automatic access to the student's account (user account)? Or do I have to re-write the logic so that the response-request lifecycle closes and then try to write to the database (maybe it will then use the original session data?)? Or is there a simpler way? Please help. I have been stuck for more than a week.
Twilio developer evangelist here.
I'm not a Laravel developer, but session objects in web application frameworks like this are normally tied to a cookie that either stores the contents of the session or an ID for the session which points to the contents in a database in order to add state to a user's session within a browser.
When Twilio receives an incoming SMS message the webhook that is sent to your server is not connected to the browser session that the user is part of, so you cannot access the same data.
Instead of using the session, you should store this as part of your actual database so that you can look up the details from the database when you receive the SMS.

virtuemart 2 - how to send invoice as email attachment on confirm order

I want to send invoice as email attachment on order confirmation ,how to go about sending the invoice.
searched a lot ,not relevant data found.
The VM Order Confirmation Email work flow is as follows,
Check the function notifyCustomer() inside orders.php in administrator/components/com_virtuemart/models/
There is a section like shopFunctionsF::renderMail() It calls a function from shopefunctionsf helper file in /components/com_virtuemart/helpers/shopfunctionsf.php
renderMail() calls sendVmMail() in the same file there you can find option for attaching media or anything you want .
if (isset($view->mediaToSend)) {
foreach ((array)$view->mediaToSend as $media) {
//Todo test and such things.
$mailer->addAttachment($media);
}
}
Hope its helps..

Magento returning incorrect customer data on frontend pages

isn't this the right method to get Name of logged in customer?
<?php echo Mage::helper('customer')->getCustomer()->getName(); ?>
I have a website with live chat functionality. Yesterday I have been asked to pass email address and the name of the logged into the user into the Javascript Tracking variable code placed in the head section of the website. So that the operators could see who is on the website and whom are they talking to without any need to ask about their information.
So I passed the information from Magento into the Javascript code but now I see this very strange thing happening. For example,
If I am logged in with credentials Name = John Email =
john12#yahoo.com
Then This name and email variable values are changing with the change of pages. For example if I click on any product page the variable values which I am passing changes to some other user's information.
Name becomes Ricky Email becomes ricky23#gmail.com
this variable values are kept on changing back to john and from john to something else with the change of pages. So operator does not have any idea whom are they talking because the values are kept on changing. Also, user ricky or who ever it changes to also exist in the database. so it is picking up random person from the database.
This is what i did to pass the code to javascript. Please let me know if that is not the right code to pass the information. Please check the php code I am using to fetch information from Magento. Roughly, I receive incorrect value once in 5 times. Please provide some assistance. Thanks in advance.
<?php
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail();
$firstname = $customer->getFirstname();
$lastname= $customer->getLastname();
$name = $firstname . ' ' . $lastname;
?>
<script type="text/javascript">
if (typeof(lpMTagConfig) == "undefined"){ lpMTagConfig = {};}
if (typeof(lpMTagConfig.visitorVar) == "undefined"){ lpMTagConfig.visitorVar = [];}
lpMTagConfig.visitorVar[lpMTagConfig.visitorVar.length] = 'Email=<?php echo $email; ?>';
lpMTagConfig.visitorVar[lpMTagConfig.visitorVar.length] = 'Name=<?php echo $name; ?>';
</script>
I'm also attaching a snap shot
I'd be interested to hear how you're adding this code to the page? Is it in it's own block, or are you adding it to footer.phtml, or similar? If your adding to an existing block be sure to check the block caching settings of that template.
To confirm the caching hypothesis I'd ask the following:
Do you get the same name, all the time, on the same page? When you refresh the page, do you get the same name and email in the Javascript?
Does the problem persist with caching disabled?
This doesn't sound like a singleton problem at all. Each execution of the PHP script is isolated from the others, serving one page request. There's no chance of another customer's object moving between invokations of the script.
It is a matter of understanding the singleton pattern. If you call your code twice:
$customer_1 = Mage::helper('customer')->getCustomer()->getName();
$customer_2 = Mage::helper('customer')->getCustomer()->getName();
you get two different instances of the object. But... if one of them has already implemented a singleton pattern in its constructor or has implemented a singleton getInstance then both objects will actually point to the same thing.
Looking at the customer/helper/Data.php code you can see the function
public function getCustomer()
{
if (empty($this->_customer)) {
$this->_customer = Mage::getSingleton('customer/session')->getCustomer();
}
return $this->_customer;
}
That means that in one of the cases singleton is already implemented/called and in other one - not as the property is already set.
The correct way to work with quote/customer/cart in order to get always the correct data is always to use the singleton pattern.
So using this:
$customer = Mage::getSingleton('customer/session')->getCustomer();
always guarantee that you get the correct customer in that session. And as may be you know singleton pattern is based on registry pattern in app/Mage.php:
public static function getSingleton($modelClass='', array $arguments=array())
{
$registryKey = '_singleton/'.$modelClass;
if (!self::registry($registryKey)) {
self::register($registryKey, self::getModel($modelClass, $arguments));
}
return self::registry($registryKey);
}
and looking at app/Mage.php:
public static function register($key, $value, $graceful = false)
{
if (isset(self::$_registry[$key])) {
if ($graceful) {
return;
}
self::throwException('Mage registry key "'.$key.'" already exists');
}
self::$_registry[$key] = $value;
}
...
public static function registry($key)
{
if (isset(self::$_registry[$key])) {
return self::$_registry[$key];
}
return null;
}
you can see that Magento checks is it is already set. If so, Magento will either throw an Exception, which is the default behavior or return null.
Hope this will help you to understand the issue you face.
I have sorted this out. I have moved the code from footer.phtml to head.phtml and it's working fine now.Values are not changing anymore. If anyone know the logic behind please post and I will change my answer. So far this is working.

Connecting to Magento API with SOAP

I'm trying to follow a tutorail on connecting to magento API with Soap, but am stuck already ? SOAP seems to be installed on my sever as i can browse to the ?wsld and it displays an xml file.
I've setup the user and role in magento admin webservices.
i'm confused by 2 things in the tutorial
choosing a soap client, In this tutorial we will assume the usage of the PHP SoapClient. what is this where do i find it ?
Logging with the SOAP client
"So let's create a simple PHP-script that allows us to login into Magento through SOAP. The logic is here that we first need to initialize a new SoapClient object with as argument the Magento SOAP URL."
// Magento login information
$mage_url = 'http://MAGENTO/api/?wsdl';
$mage_user = 'soap_user';
$mage_api_key = '********';
// Initialize the SOAP client
$soap = new SoapClient( $mage_url );
// Login to Magento
$session_id = $soap->login( $mage_user, $mage_api_key );
Where do you create this script - is it a simple php file ? and how do you actualy make the call - do you just browse to it ?
http://blog.opensourcenetwork.eu/tutorials/guru/connecting-through-soap-with-magento-1
Many thanks in advance
You put this into a new blank file. Save this as name.php und run this is on your server:
<?php
$host = "127.0.0.1/magento/index.php"; //our online shop url
$client = new SoapClient("http://".$host."/api/soap/?wsdl"); //soap handle
$apiuser= "user"; //webservice user login
$apikey = "key"; //webservice user pass
$action = "sales_order.list"; //an action to call later (loading Sales Order List)
try {
$sess_id= $client->login($apiuser, $apikey); //we do login
print_r($client->call($sess_id, $action));
}
catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage(); //we print this
exit();
}
?>
Regards boti
Yes, the Soap Client the documents refer to is the built in PHP SoapClient object. There are a plethora of soap client's written in a plethora of different languages. SOAP, as a protocol, is language/platform independent. (although individual languages/platforms tend to have their own quirks). Magento provides a Soap Server, which can interacted with via a client. This is client/server architecture.
You call this script however you want. You can load it in an individual web page, you can run it from the command line $ php script.php, you can put it in an include files, you can place it in another framework's class files, etc.
this helped alot thanks
answered Nov 16 '11 at 7:26 boti
You put this into a new blank file. Save this as name.php und run this is on your server:
<?php
$host = "127.0.0.1/magento/index.php"; //our online shop url
$client = new SoapClient("http://".$host."/api/soap/?wsdl"); //soap handle
$apiuser= "user"; //webservice user login
$apikey = "key"; //webservice user pass
$action = "sales_order.list"; //an action to call later (loading Sales Order List)
try {
$sess_id= $client->login($apiuser, $apikey); //we do login
print_r($client->call($sess_id, $action));
}
catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage(); //we print this
exit();
}
?>
HI All,
The solution is :
from Magento Admin Panel...
System -> Configuration -> Web -> Url Options -> Add Store Code to Urls = NO
AND !!!!
Auto-redirect to Base URL = NO
Then Add user from
System -> Web Services-> Users
Make a user to use with the soapclient
Then make a role from
System -> Web Services -> Roles
Attach all resources if you want do it this way.
This is important ! add this role to the user you’ve just created
Also Make sure that PHP.ini from
;extension=php_soap.dll
to
extension=php_soap.dll
Then you can connect with this user I use this code
$proxy = new SoapClient(’http://localhost/api/soap/?wsdl’,array(
$apiuser = "user",
$apikey = "key"));
download soapui from forgesource
http://sourceforge.net/projects/soapui/?source=directory
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
<soapenv:Header/>
<soapenv:Body>
<urn:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<username xsi:type="xsd:string">username</username>
<apiKey xsi:type="xsd:string">password</apiKey>
</urn:login>
</soapenv:Body>
</soapenv:Envelope>
Get the link of our server with link below and save as magentoV2.wsdl
http://localhost/index.php/api/v2_soap?wsdl
I hope this will help others because I a lost half a day to understand this simple things because there were no enough detail information on one place.
HR
They are referring to the standard SOAP client functionality of PHP(provided, i can't read the link you posted, but I'm assuming it is). Have a look here for more: http://php.net/manual/en/class.soapclient.php
As per your question i will tel you simple steps, follow those steps then you wii get result as we require.
1. Login to Magento admin panel then navigate to system-->webservices-->SOAP RPC Roles create SOAP RPC roles
2. Navigate to system-->webservices-->SOAP RPC users create SOAP RPC user map this user with roles.
3. Create one PHP file name it as magentoapi.php inside xampp-->htdocs-->folder(project name).
4. Here I am giving you one example, how to get customer Info.
5. Open magentoapi.php file create one function name it as customerInfo
Below is the code:
function customerInfo($api_url, $api_user, $api_pwd) {
$websites = '' . $api_url . "/index.php/api/soap/?wsdl";
try {
$client = new SoapClient($websites);
$session = $client->login($api_user, $api_pwd);
$result = $client->call($session, 'customer.info', '1');
print_r($result);
} catch (\SoapFault $e) {
echo $e->getMessage();
}
}
Here,
$api_url is your store url,$api_user= api user name, $api_pwd = api password
pass this value to the customerInfo function. We will get complete information about a particular customer
Do same thing for all functions
Here is the API reference URL http://devdocs.magento.com/guides/m1x/api/soap/customer/customer.list.html
Finally run the below URL in browser you will get results
http://localhost/yourprojectname/magentoapi.php?functionName=customerLogout&store_url=http://127.0.0.1/magento19&api_username=magento&api_key=123456

Resources