Going nuts here with Authorize.Net extremely POOR documentation and error reporting. I am trying to implement an Accept Hosted page to process credit cards. I am able to generate the token but when I pass the token into the form (in the iFrame) I am getting an error MISSING OR INVALID TOKEN
The token is getting created without issue, but when trying to use it is when things go sideways.
And in the chrome inespector console I am getting two javascript errors returned:
ERROR TypeError: Cannot read property 'billTo' of null
ERROR TypeError: Cannot read property 'offsetHeight' of null
So, printing out my $request json I am able to validate my json object that is being passed to create the token is correct:
{
"merchantAuthentication": {"name":"xxxxxxxx","transactionKey":"yyyyyyyyyyyy"},
"clientId":"sdk-php-2.0.0-ALPHA",
"refId":"ref1608564012",
"transactionRequest": {
"transactionType":"authCaptureTransaction",
"amount":"360.00",
"order": {"invoiceNumber":"11373-0","description":"2020-11-01 bill for All Regions\/All Sites"},
"customer":{"type":"business","id":"1002","email":"pjohnson#gmail.com"},
"billTo":{"firstName":"Preston","lastName":"Johnson","company":"Backyard Grill","address":"123 Main St","city":"Tampa","state":"FL","zip":"33611","country":"USA"},
"shipTo":{"firstName":"Preston","lastName":"Johnson","company":"Backyard Grill","address":"123 Main St","city":"Tampa","state":"FL","zip":"33611","country":"USA"}
},
"hostedPaymentSettings":
{"setting":[
{"settingName":"hostedPaymentReturnOptions","settingValue":"{ \"url\": \"https:\/\/portal.attendago.com\/adminInvoicePaid.html\", \"cancelUrl\": \"https:\/\/portal.attendago.com\/adminInvoicePay.html?invID=11373-0\", \"showReceipt\":true }"},
{"settingName":"hostedPaymentButtonOptions","settingValue":"{ \"text\": \"Submit Payment\" }"},
{"settingName":"hostedPaymentStyleOptions","settingValue":"{ \"bgColor\": \"#192a67\" }"},
{"settingName":"hostedPaymentPaymentOptions","settingValue":"{ \"cardCodeRequired\":true, \"showCreditCard\":true, \"showBankAccount\":true }"},
{"settingName":"hostedPaymentShippingAddressOptions","settingValue":"{ \"show\":false, \"required\":true }"},
{"settingName":"hostedPaymentBillingAddressOptions","settingValue":"{ \"show\":true, \"required\":true }"},
{"settingName":"hostedPaymentCustomerOptions","settingValue":"{ \"showEmail\":true, \"requiredEmail\":true, \"addPaymentProfile\":false }"},
{"settingName":"hostedPaymentOrderOptions","settingValue":"{ \"show\":false }"},
{"settingName":"hostedPaymentIFrameCommunicatorUrl","settingValue":"{ \"url\": \"https:\/\/portal.attendago.com\/adminInvoiceFrame.html\" }"}
]}
}
Here is my function to create the token:
function getCustomerToken($ss) {
$ii = $ss['invoiceData'] ;
if (isSet($ss['payMethods'])) {
$pp = $ss['payMethods'] ;
}
////////////////////////////////////////////////
/// global objects needed for all transactions
////////////////////////////////////////////////
// Create a merchantAuthenticationType, pulled from constants file
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\AuthorizeConstants::sandboxID); // loginID / sandboxID
$merchantAuthentication->setTransactionKey(\AuthorizeConstants::sandboxKey); // loginKey / sandboxKey
// Set the transaction's refId
$refId = 'ref' . time();
// Set order information
$order = new AnetAPI\OrderType();
$order->setInvoiceNumber($ss['invoiceID']);
if (strpos($ii['invName'], "S") !== false) {
$invDesc = $ii['servMonth']. " bill for Site " .$ii['venue'] ;
} else if (strpos($ii['invName'], "R") !== false) {
$invDesc = $ii['servMonth']. " bill for Region " .$ii['venue'] ;
} else {
$invDesc = $ii['servMonth']. " bill for " .$ii['venue'] ;
}
$order->setDescription($invDesc);
// Set the customer's identifying information
$customerData = new AnetAPI\CustomerDataType();
$customerData->setType("business");
$customerData->setId($ii['cID']);
$customerData->setEmail($ii['cEmail']);
// Set the Bill To info for new payment type
$billTo = new AnetAPI\CustomerAddressType();
$billTo->setFirstName($ii['cFirstName']);
$billTo->setLastName($ii['cLastName']);
$billTo->setCompany($ii['cName']);
$billTo->setAddress($ii['cAddress']. " " .$ii['cAddress1']);
$billTo->setCity($ii['cCity']);
$billTo->setState($ii['cState']);
$billTo->setZip($ii['cZip']);
$billTo->setCountry("USA");
//$billTo->setFaxNumber('8005551212') ;
//$billTo->setPhoneNumber($ii['cPhone']);
// set shipping profile
$shippingProfiles[] = $billTo ;
//create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($ss['balance']);
$transactionRequestType->setCustomer($customerData) ;
$transactionRequestType->setOrder($order) ;
if (isSet($ss['authMerchID'])) {
$profileType = new AnetAPI\CustomerProfilePaymentType();
$profileType->setCustomerProfileId($ss['authMerchID']) ;
$transactionRequestType->setProfile($profileType) ;
} else {
$transactionRequestType->setBillTo($billTo) ;
$transactionRequestType->setShipTo($billTo) ;
}
// Set Hosted Form options
$setting0 = new AnetAPI\SettingType();
$setting0->setSettingName("hostedPaymentReturnOptions");
$setting0->setSettingValue( "{ \"url\": \"https://portal.mysdomain.com/adminInvoicePaid.html\", \"cancelUrl\": \"https://portal.mydomain.com/adminInvoicePay.html?invID=" .$ss['invoiceID']. "\", \"showReceipt\":true }" );
$setting1 = new AnetAPI\SettingType();
$setting1->setSettingName("hostedPaymentButtonOptions");
$setting1->setSettingValue("{ \"text\": \"Submit Payment\" }");
$setting2 = new AnetAPI\SettingType();
$setting2->setSettingName("hostedPaymentStyleOptions");
$setting2->setSettingValue("{ \"bgColor\": \"#192a67\" }");
$setting3 = new AnetAPI\SettingType();
$setting3->setSettingName("hostedPaymentPaymentOptions");
$setting3->setSettingValue("{ \"cardCodeRequired\":true, \"showCreditCard\":true, \"showBankAccount\":true }");
$setting4 = new AnetAPI\SettingType();
$setting4->setSettingName("hostedPaymentShippingAddressOptions");
$setting4->setSettingValue("{ \"show\":false, \"required\":true }");
$setting5 = new AnetAPI\SettingType();
$setting5->setSettingName("hostedPaymentBillingAddressOptions");
$setting5->setSettingValue("{ \"show\":true, \"required\":true }");
$setting6 = new AnetAPI\SettingType();
$setting6->setSettingName("hostedPaymentCustomerOptions");
$setting6->setSettingValue("{ \"showEmail\":true, \"requiredEmail\":true, \"addPaymentProfile\":false }");
$setting7 = new AnetAPI\SettingType();
$setting7->setSettingName("hostedPaymentOrderOptions");
$setting7->setSettingValue("{ \"show\":false }");
$setting8 = new AnetAPI\SettingType();
$setting8->setSettingName("hostedPaymentIFrameCommunicatorUrl");
$setting8->setSettingValue("{ \"url\": \"https://portal.mydomain.com/adminInvoiceFrame.html\" }");
// Build transaction request
$request = new AnetAPI\GetHostedPaymentPageRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setTransactionRequest($transactionRequestType);
$request->addToHostedPaymentSettings($setting0);
$request->addToHostedPaymentSettings($setting1);
$request->addToHostedPaymentSettings($setting2);
$request->addToHostedPaymentSettings($setting3);
$request->addToHostedPaymentSettings($setting4);
$request->addToHostedPaymentSettings($setting5);
$request->addToHostedPaymentSettings($setting6);
$request->addToHostedPaymentSettings($setting7);
$request->addToHostedPaymentSettings($setting8);
//execute request
$controller = new AnetController\GetHostedPaymentPageController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
$gToken=[] ;
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) {
//echo $response->getToken()."\n";
$gToken["Error"] = 0 ;
$gToken["Token"] = $response->getToken() ;
} else {
//echo "ERROR : Failed to get hosted payment page token\n";
$errorMessages = $response->getMessages()->getMessage();
//echo "RESPONSE : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
$gToken["Error"] = 1 ;
$gToken["errMsg"] = $errorMessages[0]->getCode() . ": " .$errorMessages[0]->getText() ;
}
return array($gToken,$request);
}
*** UPDATE***
Looking at the network console logs, there is a request going out to https://test.authorize.net/payment/payment - but the key token is empty, which would appear to be the reason for the error Missing or Invalid Token. In my form, I can validate the TOKEN is there. But when I click the trigger popup iFrame button, I can visually see the token being deleted from the hidden form field.
The code to open the popup iframe, copied verbatim from the Authorize.net code sample had this bit of code $("#popupToken").val($("#inputtoken").val()); - this is erasing/deleting the token value before it was being submitted to payment gateway - what the heck?! Why would their own example code do that? Commenting this out fixed it.
AuthorizeNetPopup.openPopup = function () {
var popup = document.getElementById("divAuthorizeNetPopup");
var popupScreen = document.getElementById("divAuthorizeNetPopupScreen");
var ifrm = document.getElementById("iframeAuthorizeNet");
var form = document.forms["formAuthorizeNetPopup"];
//$("#popupToken").val($("#inputtoken").val()); // WTH authorize????
form.action = "https://test.authorize.net/payment/payment";
ifrm.style.width = "442px";
ifrm.style.height = "578px";
form.submit();
popup.style.display = "";
popupScreen.style.display = "";
centerPopup();
};
I am using dialogflow php client library for accessing v2 rest api of dialogflow. I can call detectIntent and other stuffs and it is working. But some times i should need to search for a specific trainingPhrase and if not present then add new training phrase for detected intent. How could i do this using php client library? I am tired of searching on this. Please help me. Any answers will be appreciated. The function I'm using to getIntent with the some text is as below,
function detect_intent_texts($projectId, $text, $sessionId, $languageCode = 'en-US')
{
global $common;
// new session
$test = array('credentials' => 'key_file.json');
$sessionsClient = new SessionsClient($test);
$session = $sessionsClient->sessionName($projectId, $sessionId ?: uniqid());
//printf('Session path: %s' . PHP_EOL, $session);
// create text input
$textInput = new TextInput();
$textInput->setText($text);
$textInput->setLanguageCode($languageCode);
// create query input
$queryInput = new QueryInput();
$queryInput->setText($textInput);
// get response and relevant info
$response = $sessionsClient->detectIntent($session, $queryInput);
$queryResult = $response->getQueryResult();
$queryText = $queryResult->getQueryText();
$intent = $queryResult->getIntent();
$displayName = $intent->getDisplayName();
$common->write_to_log("intent displayName : ".$displayName);
if($displayName == "Default Fallback Intent")
{
$result = json_encode(array("result"=>false));
$common->write_to_log("No matching intent found");
}
else
{
$confidence = $queryResult->getIntentDetectionConfidence();
$fulfilmentText = $queryResult->getFulfillmentText();
$common->write_to_log("intent response : ".$fulfilmentText);
$result = json_encode(array("result"=>true,"message"=>$fulfilmentText));
}
echo $result;
$sessionsClient->close();
}
I'm trying to add new users to moodle 3.2 using a REST web service, and i want to customize thees fields (phone1, department, institution) in the student profile.
I used this code
$token = 'a38805c00f33023f7854d5adc720c7a7';
$domainname = 'http://localhost/moodle';
$functionname = 'core_user_create_users';
$restformat = 'json';
$user2 = new stdClass();
$user2->username = strtolower( $rsnew['Serial']);
$user2->password = $rsnew['pass'];
$user2->firstname = $rsnew['Fname'];
$user2->lastname = $rsnew['Lname'];
$user2->email = $rsnew['Email'];
$user2->lang = 'en';
$user2->auth = 'manual';
$user2->country = $rsnew['Country'];
$user2->timezone = '99';
$user2->phone1 = $rsnew['phone'];
$user2->department = $rsnew['dept'];
$user2->institution = $rsnew['branch'];
$user2->idnumber = $rsnew['grade'];
$users = array($user2);
$params = array('users' => $users);
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
require_once('./curl.php');
$curl = new curl;
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->post($serverurl . $restformat, $params);
But i get this error :
{
"exception": "invalid_parameter_exception",
"errorcode": "invalidparameter",
"message": "Invalid parameter value detected",
"debuginfo": "users => Invalid parameter value detected: Unexpected keys (phone1, department, institution) detected in parameter array."
}
What should I do to fix that?
Just as the error suggests, that web service does not support the fields you are giving it. You can refer to the function itself to find out what fields are supported and what data they must contain.
core_user_get_users
I am not aware of a workaround for your problem using existing web services. However, you can create your own which includes those additional fields.
Note that this sounds to me like this is a desirable feature and should be raised on the issue tracker.
My Code given below:
Route::get('/facebook', 'ApiUserController#socialConnect');
public function socialConnect()
{
// get data from input
$code = Input::get( 'code' );
// get fb service
$fb = OAuth::consumer( 'Facebook' );
// check if code is valid
// if code is provided get user data and sign in
if ( !empty( $code ) ) {
// This was a callback request from facebook, get the token
$token = $fb->requestAccessToken( $code );
// Send a request with it
$result = json_decode( $fb->request( '/me' ), true );
$message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
echo $message. "<br/>";
//Var_dump
//display whole array().
dd($result);
}
// if not ask for permission first
else {
// get fb authorization
$url = $fb->getAuthorizationUri();
// return to facebook login url
return Redirect::to( (string)$url );
}
}
Error : Method [getData] does not exist on Redirect.
It does always bring this error while invoking http://localhost:8000/v1/facebook even though I added the url http://localhost:8000/v1/facebook in Valid OAuth redirect URIs
Please suggest the same
$duration = Benchmarking::end('application');
$duration = ($duration * 1000) . 'ms';
Log::info($response->getStatusCode() . ' ' . $request->path() . ' :: ' . $duration);
if (!Config::get('app.debug'))
{
return $response;
}
$data = $response->getData();
if (is_array($data)) {
return $response;
}
$data->queryLog = DB::getQueryLog();
$data->responseTime = $duration;
$response->setData($data);
return $response;
This filter is creating problem what can we fixed it out
Just need to update the response in json format works fine
There is a very simple package for social auth: https://github.com/laravel/socialite
I am trying to send context and payload to the Dialogflow V2 API. I am able to successfully send a queryString and get a response from my agent. However, I need to pass context and payload parameters with this query and I cannot seem to find ANY help on this for PHP. Please see my code below. I am able to create the context object and the payload object (atleast I think its created), but how do I pass it to the API?
Any help would be appreciated as I am very new to dialogflow and have been struggling with this for a few days now.
function detect_intent_texts($projectId, $text, $sessionId, $context, $parameters, $languageCode = 'en-US') {
// new session
$test = array('credentials' => 'client-secret.json');
$sessionsClient = new SessionsClient($test);
$session = $sessionsClient->sessionName($projectId, $sessionId ?: uniqid());
//printf('Session path: %s' . PHP_EOL, $session);
// create text input
$textInput = new TextInput();
$textInput->setText($text);
$textInput->setLanguageCode($languageCode);
$contextStruct = new Struct();
$contextStruct->setFields($context['parameters']);
$paramStruct = new Struct();
$paramStruct->setFields($parameters['parameters']);
$contextInput = new Context();
$contextInput->setLifespanCount($context['lifespan']);
$contextInput->setName($context['name']);
$contextInput->setParameters($contextStruct);
$queryParams = new QueryParameters();
$queryParams->setPayload($paramStruct);
// create query input
$queryInput = new QueryInput();
$queryInput->setText($textInput);
// get response and relevant info
$response = $sessionsClient->detectIntent($session, $queryInput); // Here I don't know how to send the context and payload
$responseId = $response->getResponseId();
$queryResult = $response->getQueryResult();
$queryText = $queryResult->getQueryText();
$intent = $queryResult->getIntent();
$displayName = $intent->getDisplayName();
$confidence = $queryResult->getIntentDetectionConfidence();
$fulfilmentText = $queryResult->getFulfillmentText();
$returnResponse = array(
'responseId' => $responseId,
'fulfillmentText' => $fulfilmentText
);
$sessionsClient->close();
return $returnResponse;
}
Just as it happens, the moment I post my question, I get a result.
Thanks to this post How to set query parameters dialogflow php sdk.
I added the following to my code and it worked.
Added
$optionalsParams = ['queryParams' => $queryParams];
Changed
$response = $sessionsClient->detectIntent($session, $queryInput, $optionalsParams);