I am trying to send CC to another email using the previously-mentioned code,
and I am getting the following error:
Varien_Exception Object ( [message:protected] => Invalid method Mage_Core_Model_Email_Template::addCc(Array ( [0] => abc#gmail.com ) ) [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/domains/alldaychemist/lib/Varien/Object.php [line:protected] => 652 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/domains/alldaychemist/adminuser.php [line] => 59 [function] => __call [class] => Varien_Object [type] => -> [args] => Array ( [0] => addCc [1] => Array ( [0] => abc#gmail.com ) ) ) [1] => Array ( [file] => /var/domains/alldaychemist/adminuser.php [line] => 59 [function] => addCc [class] => Mage_Core_Model_Email_Template [type] => -> [args] => Array ( [0] => abc#gmail.com ) ) ) [previous:Exception:private] => )
When ever I send the email using the below code I get this error,
-Invalid method Mage_Core_Model_Email_Template::addCc
My code looks like this:
$templateId = 15;
// Set sender information
$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
$sender = array('name' => $senderName,
'email' => $senderEmail);
// Set recepient information
$recepientEmail = 'adcc#gmailcom';
$recepientName = 'John Doe';
// Get Store ID
$store = Mage::app()->getStore()->getId();
// Set variables that can be used in email template
$vars = array('customerName' => 'customer#example.com',
'customerEmail' => 'Mr. Nil Cust');
$translate = Mage::getSingleton('core/translate');
// Send Transactional Email
try{
Mage::getModel('core/email_template')
->addCc('abc#gmail.com')
->addBcc('abcd2#gmail.com')
->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
}
catch(Exception $e){
print_r($e);
}
$translate->setTranslateInline(true);
Unlike addBcc,addCc is not defined in class Mage_Core_Model_Email_Template. You can either extend Mage_Core_Model_Email_Template class to include addCc method in a similar fashion as addBcc, or modify your code like this:
// Send Transactional Email
try{
$mail = Mage::getModel('core/email_template');
$mail->getMail()->addCc('abc#gmail.com');
$mail->addBcc('abcd2#gmail.com')
->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
}
catch(Exception $e){
print_r($e);
}
Related
I'm implementing a simple webservice client in Moodle 3.3 and testing some functions. For some reason, this doesn't seem to be working.
<?php
$token = '.......';
$domainname = 'http://localhost/moodle';
$functionname = 'core_course_get_contents';
$cid = 5;
/// SOAP CALL
$serverurl = $domainname . '/webservice/soap/server.php'. '?wsdl=1&wstoken=' . $token;
////Do the main soap call
$client = new SoapClient($serverurl);
try {
$resp = $client->__soapCall($functionname, array($cid));
} catch (Exception $e) {
print_r($e);
}
if (isset($resp)) {
print_r($resp);
}
I keep getting the error below:
SoapFault Object ( [message:protected] => Invalid parameter value detected | ERRORCODE: invalidparameter [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/html/client.php [line:protected] => 15 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/html/client.php [line] => 15 [function] => __soapCall [class] => SoapClient [type] => -> [args] => Array ( [0] => core_course_get_contents [1] => Array ( [0] => 5 ) ) ) ) [previous:Exception:private] => [faultstring] => Invalid parameter value detected | ERRORCODE: invalidparameter [faultcode] => Receiver [faultactor] => invalidparameter [detail] => options => Invalid parameter value detected: Only arrays accepted. The bad value is: '' )
The documentation for the webservice is:
REST (POST parameters)
courseid= int
XML-RPC (PHP structure)
[options] =>
Array
(
[0] =>
Array
(
[name] => string
[value] => string
)
)
According to the code: https://github.com/moodle/moodle/blob/ae82333cf25219ba627538f7e8de72f0b4028460/course/externallib.php#L49
The expected params are:
courseid
options (optional)
So, I would expect the call to look something like:
$resp = $client->__soapCall($functionname, array('courseid' => $cid));
If you wanted to specify any of the options, it would look like:
$resp = $client->__soapCall($functionname, array('courseid' => $cid, 'options' => [['name' => 'nameofoption', 'value' => 'valuetoset'], ['name' => 'secondoption', 'value' => 'secondvalue]]));
I've been asked to retrieve the buyer's email address via the PayPal API using a transaction ID. I can see that I can use the GetTransactionDetails function to do this.
I've managed to login using the credentials I've been given using SOAP but when it comes to running GetTransactionDetails, I'm getting errors.
Here's my code:
$user = "XXXXXX";
$pass = "XXXXXX";
$sign = "XXXXXX";
$socket_context = stream_context_create(array('http' => array('protocol_version' => 1.0)));
$client = new SoapClient("https://www.paypal.com/wsdl/PayPalSvc.wsdl", array('exceptions' => 0,'stream_context' => $socket_context,'trace' => 1));
$params = array(
"Username" => $user,
"Password" => $pass,
"Signature" => $sign);
$credentials = new stdClass();
$credentials->Credentials = new SoapVar(
$params,
SOAP_ENC_OBJECT,
'Credentials');
$headers = new SoapVar(
$credentials,
SOAP_ENC_OBJECT,
'CustomSecurityHeaderType',
'urn:ebay:apis:eBLBaseComponents');
$client->__setSoapHeaders(
new SoapHeader(
'urn:ebay:api:PayPalAPI',
'RequesterCredentials',
$headers)
);
if (is_soap_fault($credentials)) {
print "SOAP Fault: $credentials->faultcode, $credentials->faultstring<br />";
} else {
print "logged in";
}
$args = array(
"Version" => "124.0",
"TransactionID" => "12345ABCDE");
$GetTransactionDetailsRequest = new stdClass();
$GetTransactionDetailsRequest->GetTransactionDetailsRequest = new SoapVar(
$args,
SOAP_ENC_OBJECT,
'GetTransactionDetailsRequestType',
'urn:ebay:api:PayPalAPI');
$params = new SoapVar(
$GetTransactionDetailsRequest,
SOAP_ENC_OBJECT,
'GetTransactionDetailsRequest');
$result = $client->GetTransactionDetails($params);
print "<pre>";
print_r($result);
print "</pre>";
And this is the error I'm seeing after running it:
SoapFault Object
(
[message:protected] => Bad Request
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /location/to/file.php
[line:protected] => 42
[trace:Exception:private] => Array
(
[0] => Array
(
[function] => __doRequest
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => XXXXXXXXXXXXXXXXXXXX
[1] => https://api.sandbox.paypal.com/2.0/
[2] =>
[3] => 1
[4] => 0
)
)
[1] => Array
(
[file] => /location/to/file.php
[line] => 42
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => GetTransactionDetails
[1] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => stdClass Object
(
[GetTransactionDetailsRequest] => SoapVar Object
(
[enc_type] => 301
[enc_value] => Array
(
[Version] => 124.0
[TransactionID] => 12345ABCDE
)
[enc_stype] => GetTransactionDetailsRequestType
[enc_ns] => urn:ebay:api:PayPalAPI
)
)
[enc_stype] => GetTransactionDetailsRequest
)
)
)
)
[2] => Array
(
[file] => /location/to/file.php
[line] => 42
[function] => GetTransactionDetails
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => stdClass Object
(
[GetTransactionDetailsRequest] => SoapVar Object
(
[enc_type] => 301
[enc_value] => Array
(
[Version] => 124.0
[TransactionID] => 12345ABCDE
)
[enc_stype] => GetTransactionDetailsRequestType
[enc_ns] => urn:ebay:api:PayPalAPI
)
)
[enc_stype] => GetTransactionDetailsRequest
)
)
)
)
[previous:Exception:private] =>
[faultstring] => Bad Request
[faultcode] => HTTP
)
The line it's failing on is:
$result = $client->GetTransactionDetails($params);
I've never worked with the PayPal API before and I've scraped code from several different examples so if someone knows of a better way to do this, that would be great!
NOTES:
I've made up the login details, location of file and TransactionID
for this post.
The real TransactionID is correct, I've double checked it in PayPal
directly
The Version number is from the WSDL (it states that number at the
beginning)
I only added $socket_context because without it, it came back
saying "Error Fetching http headers".
After much digging, it turns out the API was defaulting the Sandbox Endpoint! I've added the following code to my script right after I call the SoapClient:
$client->__setLocation('https://api-3t.paypal.com/2.0/');
Now it works!
I'm trying to get PayPal user basic personal data.
When I pass attributes, it gives me this error:
Invalid request parameter: Requested Attributes are incorrect
API Docs:
https://developer.paypal.com/docs/classic/api/permissions/GetBasicPersonalData_API_Operation/
My code:
function GetBasicPersonalData(){
$paypal_config = Config::get('paypal');
$requestEnvelope = new RequestEnvelope();
$requestEnvelope->errorLanguage = "en_US";
$request = new GetBasicPersonalDataRequest();
$request->requestEnvelope = $requestEnvelope;
$request->attributeList = array('http://axschema.org/namePerson/first', 'http://axschema.org/namePerson/last', 'http://axschema.org/contact/email');
$service = new PermissionsService($paypal_config);
$response = $service->GetBasicPersonalData($request);
return $response;
}
This is how request looks like:
PayPal\Types\Perm\GetBasicPersonalDataRequest Object
(
[requestEnvelope] => PayPal\Types\Common\RequestEnvelope Object
(
[detailLevel] =>
[errorLanguage] => en_US
)
[attributeList] => Array
(
[0] => http://axschema.org/namePerson/first
[1] => http://axschema.org/namePerson/last
[2] => http://axschema.org/contact/email
)
)
And response:
PayPal\Types\Perm\GetBasicPersonalDataResponse Object
(
[responseEnvelope] => PayPal\Types\Common\ResponseEnvelope Object
(
[timestamp] => 2015-05-26T17:27:05.060-07:00
[ack] => Failure
[correlationId] => 02023e9639483
[build] => 2210301
)
[response] => PayPal\Types\Perm\PersonalDataList Object
(
[personalData] =>
)
[error] => Array
(
[0] => PayPal\Types\Common\ErrorData Object
(
[errorId] => 580022
[domain] => PLATFORM
[subdomain] => Application
[severity] => Error
[category] => Application
[message] => Invalid request parameter: Requested Attributes are incorrect
[exceptionId] =>
[parameter] => Array
(
[0] => PayPal\Types\Common\ErrorParameter Object
(
[name] =>
[value] => PersonalAttributeList
)
)
)
)
)
I don't see my mistake here, some help?
Just create a new PersonalAttributeList object to hold the array attributes:
$personal_attribute = new PersonalAttributeList();
$personal_attribute->attribute = array('http://axschema.org/namePerson/first', 'http://axschema.org/namePerson/last', 'http://axschema.org/contact/email');
$request->attributeList = $persoanl_attribute;
Here is how it works for me:
{
"requestEnvelope": {
"errorLanguage": "en_US"
},
"attributeList": {
"attribute": [
"http://axschema.org/contact/postalCode/home"
]
}
}
I got converted WSDL to PHP script but something is not working very I am trying to connect http://www.regcheck.org.uk/api/reg.asmx?wsdl, but getting this error
Array ( [RegCheckServiceCheck::Check] => SoapFault Object ( [message:protected] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line:protected] => 32 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => Check [1] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => Check [class] => SoapClient [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) [2] => Array ( [file] => C:\xampp\htdocs\sample-regcheck.php [line] => 46 [function] => Check [class] => RegCheckServiceCheck [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [previous:Exception:private] => [faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [faultcode] => soap:Server [detail] => ) )
I am sure something is missing in config files, mybe someone got idea ?
It's possible to call that web service via a HTTP GET request as follows;
<?php
$username = 'Your username here';
$regNumber = 'SK08KPT';
$xmlData = file_get_contents("https://www.regcheck.org.uk/api/reg.asmx/Check?RegistrationNumber=" . $regNumber ."&username=" . $username);
$xml=simplexml_load_string($xmlData);
$strJson = $xml->vehicleJson;
$json = json_decode($strJson);
print_r($json->Description);
?>
Not as elegant as a SOAP call, but simpler.
Script open source files
You can see all main files
https://www.wsdltophp.com/Wsdls/8a71627601a684624c5694104cce023f/RegCheck-1-0-1-1-1-1-0-0-0-0
I have this data generate, but how do I get the values for the data such as the
User ID -> [id] => 1429517
message -> [data:ProtocolNode:private] => get my message
Array
(
[0] => ProtocolNode Object
(
[tag:ProtocolNode:private] => message
[attributeHash:ProtocolNode:private] => Array
(
[id] => 1429517
[offline] => 0
[type] => text
[t] => 14722889
)
[children:ProtocolNode:private] => Array
(
[0] => ProtocolNode Object
(
[tag:ProtocolNode:private] => body
[attributeHash:ProtocolNode:private] => Array
(
)
[children:ProtocolNode:private] =>
[data:ProtocolNode:private] => get my message
)
)
[data:ProtocolNode:private] =>
)
)
I have tried using this:
foreach($msgs as $msg) {
echo 'test: ' . $msg->tag ;
}
but I get the error:
Fatal error: Cannot access private property ProtocolNode::$tag
$reflection = new ReflectionClass($msg);
$prop = $reflection->getProperty("tag");
$prop->setAccessible(true);
$tag = $prop->getValue();
But this is little bit hack way, if you has ProtocolNode in your sorce then it is better to add getter "getTag", if ProtocolNode is some vendor lib class, then you can extend ProtocolNode to MyProtocolNode and add getter