Hello. I'm attempting to implement the Accept Hosted instead of SIM, like many others, but am having a lot of initial issues getting things working.
I'm trying to focus on a simple example first, and simply grabbing this file to see the token printed out that is received.
I want to paste my exact code so that it's obvious below. Right now my error is:
Fatal error: Class 'net\authorize\api\contract\v1\GetHostedPaymentPageRequest' not found in /home/xxxxxxxxxxxx/pay/sdk-php-1.9.3/get-an-accept-payment-page.php on line 42
Similar to this thread: https://community.developer.authorize.net/t5/Integration-and-Testing/Class-GetHostedPaymentPageReque...
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'autoload.php'; //this file is IN the SDK folder v1.9.3.
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
function getAnAcceptPaymentPage(){
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("XXXXXXXXX");
$merchantAuthentication->setTransactionKey("YYYYYYYY");
// Set the transaction's refId
$refId = 'ref' . time();
//create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount("12.23"); // To be defined through form field.
// Set Hosted Form options
$setting1 = new AnetAPI\SettingType();
$setting1->setSettingName("hostedPaymentButtonOptions");
$setting1->setSettingValue("{\"text\": \"Pay\"}");
$setting2 = new AnetAPI\SettingType();
$setting2->setSettingName("hostedPaymentOrderOptions");
$setting2->setSettingValue("{\"show\": false}");
$setting3 = new AnetAPI\SettingType();
$setting3->setSettingName("hostedPaymentReturnOptions");
$setting3->setSettingValue("{\"url\": \"https://mysite.com/receipt\", \"cancelUrl\": \"https://mysite.com/cancel\", \"showReceipt\": true}");
// Build transaction request
$request = new AnetAPI\GetHostedPaymentPageRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransactionRequest($transactionRequestType);
$request->addToHostedPaymentSettings($setting1);
$request->addToHostedPaymentSettings($setting2);
$request->addToHostedPaymentSettings($setting3);
//execute request
$controller = new AnetController\GetHostedPaymentPageController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::PRODUCTION);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
echo $response->getToken()."\n";
}
else
{
echo "ERROR : Failed to get hosted payment page token\n";
$errorMessages = $response->getMessages()->getMessage();
echo "RESPONSE : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}
if(!defined('DONT_RUN_SAMPLES'))
getAnAcceptPaymentPage();
?>
โ07-28-2017 08:13 PM
No. You neeed to post the token to
Sandbox: https://test.authorize.net/payment/payment
or
Production: https://accept.authorize.net/payment/payment
as the case may be, in order to retrieve the hosted payment form. Writing the HTML results would defeat the purpose of using a hosted form.
โ07-30-2017 04:18 AM
Ah, I see - so this is the method to get it to load an iframe from YOUR server, that makes sense to me now. Thanks for the help... will see if I can finalize this and if I have any further questions. Appreciate it!
โ07-30-2017 04:38 AM
Back again. I am having an issue that whenever the form is loaded it loads in a very skinny (height) window with a scroll bar. Please see screenshot:
Is this common, is there a simple fix for this?
โ08-04-2017 02:24 PM
Just style your iframe with height and width attributes like the following:
<iframe id="payframe" name="payframe" style="height:800px;width:100%;border-style:none;"></iframe>
โ08-04-2017 03:39 PM - edited โ08-04-2017 03:41 PM
Hi, I was wondering if anyone here knows if this is applicable to integrating the API into a joomla site that is already live? I have FTP access but reading through the github documentation for the php sdk is confusing me as I do not have php experience in general and do not understand the whole composer thing, it seems to me that it applies to developing a solution locally and I am not doing that. Please if anyone has any insight as to how I might accomplish this I would appreciate it. All I am trying to do is redirect my users to the Authorize.Net payment gateway upon a form submission.
โ11-15-2017 07:47 AM
Hello @QHunt,
If you are not interested in building your own solution, there are extensions for Joomla, that may work for you, one of which is at https://extensions.joomla.org/extension/pay-my-bill-authorize-net/
โ11-15-2017 08:52 AM