Im using the authorize.net recurring transaction.
What Im trying to do is give the an option to check off a donation if they want it recurring for the next 12 months.
So before the ARB - I want to verify the card but 0.00 isn't a valid amount. so if i made the amount 0.01 - how can I void the transaction after the card is verified?
Also - when a subscription is made I dont get an email from authorize.net telling me a transaction was made like when a regular transaction is processed.
My code:
$authorization = new AuthnetAIM($apilogin, $apitranskey, true);
$authorization->setTransaction($creditcard, $expiration, '0.01');
$authorization->setTransactionType('AUTH_ONLY');
$authorization->process();
if ($authorization->isApproved())
{
$subscription = new AuthnetARB($apilogin, $apitranskey, AuthnetARB::USE_DEVELOPMENT_SERVER);
// Set subscription information
$subscription->setParameter('amount', $amount);
$subscription->setParameter('cardNumber', $creditcard);
$subscription->setParameter('expirationDate', $expiration);
$subscription->setParameter('firstName', $business_firstname);
$subscription->setParameter('lastName', $business_lastname);
$subscription->setParameter('address', $business_address);
$subscription->setParameter('city', $business_city);
$subscription->setParameter('state', $business_state);
$subscription->setParameter('zip', $business_zipcode);
$subscription->setParameter('email', $email);
// Set the billing cycle for every three months
$subscription->setParameter('interval_length', 1);
$subscription->setParameter('startDate', date("Y-m-d", strtotime("+ 1 months")));
// Create the subscription
$subscription->createAccount();
// Check the results of our API call
if ($subscription->isSuccessful())
{
// Get the subscription ID
$subscription_id = $subscription->getSubscriberID();
Send_email();
}
else
{
$transError = 'your subscription was not created';
$hasError = true;
}
}
else if ($authorization->isDeclined())
{
$transError = 'This card is not valid';
$hasError = true;
}
}
catch (AuthnetARBException $e)
{
$transError = 'There was an error processing the transaction. Here is the error message:<br/> ';
echo $e->__toString();
$hasError = true;
}
}
With the new SDK for authorize this would work
$authorize = new AuthorizeNetAIM(self::AUTHNET_LOGIN, self::AUTHNET_TRANSKEY);
$authorize->setFields(array(
'amount' => '0.01',
'card_num' => $cardNumber,
'exp_date' => $expDate
));
$response = $authorize->authorizeOnly();
if ($response->response_code == 1) {
// good card
}else{
// bad card
}
Not only is 0.00 a valid amount, but if you're just trying to verify a credit card is legitimate you are required by Visa and Mastercard to use that amount. A few years ago they stopped allowing pre-auths of any real value to be done for this reason. I think there are fines for merchants who fail to do so.
Having said that, if you're going to take the "charge $.01 and then void the transaction" route, the following code should work:
$transaction_id = $authorization->getTransactionID();
$void = new AuthnetAIM($apilogin, $apitranskey, true);
$void->setTransactionType("VOID");
$void->setParameter('x_trans_id', $transaction_id);
$void->process();
Related
$check_request = new AnetAPI\GetTransactionDetailsRequest();
$check_request->setMerchantAuthentication($merchantAuthentication);
$check_request->setTransId($transId);
$check_controller = new AnetController\GetTransactionDetailsController($check_request);
if(env('AUTHORIZE_MODE') == 'SANDBOX'){
$response2 = $check_controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
}
else{
$response2 = $check_controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
}
$card_no = $response2->getTransaction()->getPayment()->getCreditCard()->getCardNumber();
I am getting card no like this but it is giving last four digits of card just not full card no.
I have this credit card adding when a customer first signs up
// CREDIT CARD CODE (STRIPE)
$q_get_user = "select * from users where `id` = '$user_id' ";
$r_get_user = mysqli_query($conn,$q_get_user);
$get_user = mysqli_fetch_assoc($r_get_user);
if(1) {
\Stripe\Stripe::setApiKey("sk_live_9N676756776");
try {
$t = \Stripe\Token::create(
array(
"card" => array(
"name" => $get_user['first_name']." ".$get_user['last_name'],
"number" => $credit_num,
"exp_month" => $credit_month,
"exp_year" => $credit_year,
"cvc" => $credit_ccv
)
)
);
if($t->id != '') {
try {
$c = \Stripe\Customer::create(array(
"description" => "Customer for ".$get_user['email'],
"source" => $t->id)
);
if($c->id != '') {
$stripe_token_response = mysqli_real_escape_string($conn, json_encode($t));
$stripe_token_id = mysqli_real_escape_string($conn, $t->id);
$stripe_customer_response = mysqli_real_escape_string($conn, json_encode($c));
$stripe_customer_id = mysqli_real_escape_string($conn, $c->id);
$stripe_card_id = mysqli_real_escape_string($conn, $c->default_source);
}
} catch (Exception $e) {
//print_r($e->getMessage());
header('Location: /credits?error=cc&message='.urlencode($e->getMessage()));die;
}
}
} catch (Exception $e) {
//print_r($e->getMessage());
header('Location: /credits?error=cc&message='.urlencode($e->getMessage()));die;
}
}
// END - CREDIT CARD CODE (STRIPE)
How can I make it inside of it being for a new customer for it to add to an existing customer? Therefore the customer is adding a new card (they will have more than one)
You are sending card details through the API directly, which is probably not something you want to do. This means that you get the card numbers on your server which has some serious PCI compliance implications. I would strongly advise you to modify your integration so that you always tokenize the card details first by using Stripe.js or Stripe Checkout client-side to send the card details to Stripe directly and get a unique card token (tok_XXX) that you'd then send safely to your server to create the Customer or add as a Card.
You can find a description of the 'card update' process here; the only difference you need is that, instead of doing this to replace the card:
$cu->source = $_POST['stripeToken']; // obtained with Checkout
You want to do this to add a new one:
$customer->sources->create(array("source" => $t->id));
I am using the php example from the authorize.net website, but cannot get it to work. I have already downloaded all of the vendor software and updated composer.
In the phplog I keep getting the same error:
<code>E00045</code>
<text>The root node does not reference a valid XML namespace.</text>
</message></messages></ErrorResponse>
After updating composer errors are no longer being logged.
My php:
require("anetsdkphp/autoload.php");
$logName = "MYAUTHKEY";
$transKey = "MYTRANSKEY";
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
function chargeCreditCard($amount){
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName($logName);
$merchantAuthentication->setTransactionKey($transKey);
$refId = 'ref' . time();
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber(4111111111111111);
$creditCard->setExpirationDate(1238);
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
//create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType( "authCaptureTransaction");
$transactionRequestType->setAmount($amount);
$transactionRequestType->setPayment($paymentOne);
$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setTransactionRequest($transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
#$result = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"',
'', $result);
if ($response != null)
{
$tresponse = $response->getTransactionResponse();
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
{
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
echo $tresponse->getResponseCode();
}
else
{
echo "Charge Credit Card ERROR : Invalid response\n";
var_dump("$tresponse");
}
}
else
{
echo "Charge Credit card Null response returned";
}
}
chargeCreditCard(55.00);
Response: Charge Credit Card ERROR : Invalid response(0)
Response after updating composer: Charge Credit Card ERROR : Invalid response
Thanks very much in advance!
Your message is a bit old, and I am sure has been resolved. However, the problem is almost definitely your input data. This answer is pretty vague and will not necessarily provide a solution, but it will help you identify the cause.
print_r($response)
You will see the following object representations:
[messages:net\authorize\api\contract\v1\ANetApiResponseType:private] => net\authorize\api\contract\v1\MessagesType Object
(
[resultCode:net\authorize\api\contract\v1\MessagesType:private] => Error
[message:net\authorize\api\contract\v1\MessagesType:private] => Array
(
[0] => net\authorize\api\contract\v1\MessagesType\MessageAType Object
(
[code:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => ERROR_CODE_IS_HERE
[text:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => ERROR_MESSAGE_IS_HERE)
I'm currently building a site that will offer services that customers can pay for in Dogecoin. I am using DogeAPI and these example checkout scripts to try and build my checkout pages.
The problem is I can't get the address ($new_address) to echo to the page. When I run the script all that shows up is "Please pay 1000 DOGE to to receive your item. It may take up to 10 minutes to confirm your payment." When I log into my dashboard on DogeAPI, it doesn't show that any addresses were created.
I have a feeling that I need some sort of code that will wait until file_get_ contents() is finished and then start the JSON decoding. My code is below.
NOTE: I do have the API key in my code, I just obviously removed it before posting the code here.
//set to your API_KEY
$api_key = 'MY API HERE';
//set this to your users id
//must be alphanumeric only
$user_id = 'test123';
//set this to the amount the item costs
$amount_doge = '1000';
//send a request to the API to make a new payment address
//put info about the request in
$response = file_get_contents("https://www.dogeapi.com/wow/?api_key=$api_key&a=get_new_address&address_label=$user_id");
if($response !== 'Bad Query' && $response !== '') {
$new_address = json_decode($response);
//insert the new pending payment
mysql_query("INSERT INTO `api_payments`
(`payment_label`,`payment_address`,`paid`,`amount`)
VALUES ('$user_id', '$new_address', '0', '$amount_doge')");
//give them the address or echo a widget here
//for this example we will just echo an address
echo "Please pay $amount_doge DOGE to $response to receive your item. It may take up to 10 minutes to confirm your payment.";
} else {
echo 'There was a problem processing your order.';
}
In my site I want to integrate a paypal subscription method in which I want to transfer a particular amount from a user's paypal account to an admin's paypal account daily, weekly or monthly depending on the choice. For that i use the below code:
$obj=new paypal_recurring;
$obj->environment = 'sandbox'; // or 'beta-sandbox' or 'live'
$obj->paymentType = urlencode('Authorization'); // or 'Sale' or 'Order'
// Set request-specific fields.
$obj->startDate = urlencode("2011-9-6T0:0:0");
$obj->billingPeriod = urlencode("Month"); // or "Day", "Week", "SemiMonth", "Year"
$obj->billingFreq = urlencode("4"); // combination of this and billingPeriod must be at most a year
$obj->paymentAmount = urlencode('10');
$obj->currencyID = urlencode('USD'); // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
/* PAYPAL API DETAILS */
$obj->API_UserName = urlencode('sdfsdfsdfbiz_api1.website.us');
$obj->API_Password = urlencode('543564353');
$obj->API_Signature = urlencode('sdfsdfsdf ');
$obj->API_Endpoint = "https://api-3t.paypal.com/nvp";
/*SET SUCCESS AND FAIL URL*/
$obj->returnURL = urlencode("http://www.mysite.com/index.php?task=getExpressCheckout");
$obj->cancelURL = urlencode('http://www.mysite.comindex.php?task=error');
$task="setExpressCheckout"; //set initial task as Express Checkout
switch($task)
{
case "setExpressCheckout":
$obj->setExpressCheckout();
exit;
case "getExpressCheckout":
$obj->getExpressCheckout();
exit;
case "error":
echo "setExpress checkout failed";
exit;
}
But in this code how can i add the admin's paypal email id so that i can transfer funds to that account?
You need to create an account with paypal,sign up for the API keys, and then the money would go to your account. You can't transfer it to an arbitrary account.