Authorize.net AIM Transaction - php

require_once 'anet_php_sdk/AuthorizeNet.php';
define("AUTHORIZENET_API_LOGIN_ID", $authLogin);
define("AUTHORIZENET_TRANSACTION_KEY", $authKey);
//Set to true for test account, set to false for real account
define("AUTHORIZENET_SANDBOX", true);
$sale = new AuthorizeNetAIM;
$sale->amount = $contractorRate;
$sale->card_num = $ccnumber;
$sale->exp_date = $ccexpire;
$sale->card_code = $cccvv;
$response = $sale->authorizeAndCapture();
//If approved, use this for getting the transaction ID.
if ($response->approved) {
$transaction_id = $response->transaction_id;
//ARB creates the subscription and sets the start date 30 days from the time of submission.
require_once 'anet_php_sdk/AuthorizeNet.php';
define("AUTHORIZENET_API_LOGIN_ID", $authLogin);
define("AUTHORIZENET_TRANSACTION_KEY", $authKey);
$subscription = new AuthorizeNet_Subscription;
$subscription->name = "PumpSpy Monitoring";
$subscription->intervalLength = "1";
$subscription->intervalUnit = "months";
$subscription->startDate = $subStartDate;
$subscription->totalOccurrences = "9999";
$subscription->amount = $contractorRate;
$subscription->creditCardCardNumber = $ccnumber;
$subscription->creditCardExpirationDate= $ccexpire;
$subscription->creditCardCardCode = $cccvv;
$subscription->billToFirstName = $firstname;
$subscription->billToLastName = $lastname;
// Create the subscription.
$request = new AuthorizeNetARB;
$response = $request->createSubscription($subscription);
Above is my code for validating the credit card (using AIM) and creating the subscription 30 days later (using ARB). The issue I'm having is trying to use 0.00 for the AIM sale amount. It's not accepting anything, even if I change the sale to AUTH_ONLY.
I think Visa requires an address and zip code? Is there something I'm missing with the required values with AIM to charge 0.00?
Note: This code works as long as $contractorRate has a value above 0 - which is fine, but if the contractor wants to wait 30 days to charge the customer, I don't want to charge them with AIM at first.

The merchant account provider probably does not support $0.00 amounts. You should content them to verify they do. If they don't you can do an authorization for $0.01 and then void the transaction afterwards.
Address and zip code is not required to process a transaction but is required to perform AVS. Failure to perform AVS can result in a transaction being charged the maximum rate applicable.

Related

PHP: Moneris Vault with Recurring Bills

I want to add customer profiles to the vault, without charging any money up front, then start billing on a monthly basis starting in 1 month (it's a free 1 month trial). I have this working with the sandbox, but when I change to live credentials and URL, it only adds a profile to the vault and fails to set up recurring bills... there is no response in $mpgResponse->getRecurSuccess();
I have a basic form with email and client/customer name that is submitted to https://www3.moneris.com/HPPDP/index.php. This sets up a temporary profile in the vault (becomes permanent once credit card info has been added) and responds with the form to enter payment info (I simply have the form target set to an iframe so this response is loaded automatically). When the payment info is submitted, Moneris POSTs the result back to my PHP script, where I get the "data_key", which is what I am using instead of "credential on file". Is that a problem?
//GET CUSTOMER ID AND BILLING KEY FROM MONERIS
$client_name = $_POST["cust_id"];
$billing_key = $_POST["data_key"];
//PRIMARY TRANSACTION - No money up front (free 30 day trial)
$txnArray=array(
'type'=>'res_purchase_cc',
'data_key'=>$billing_key,
'order_id'=>$orderID,
'cust_id'=>$client_name,
'amount'=>'0.00',
'crypt_type'=>'7'
);
$mpgTxn = new mpgTransaction($txnArray);
//START BILLING IN 30 DAYS (will upgrade or use EOM to prevent issues like Feb 30th not existing)
$startDate = date('Y/m/d', strtotime('+30 day', strtotime(date('Y/m/d'))));
$recurArray = array(
'recur_unit'=>'day',
'start_now'=>'false',
'start_date'=>$startDate,
'num_recurs'=>'98',
'period' => '1',
'recur_amount'=> '99.00'
);
$mpgRecur = new mpgRecur($recurArray);
//ADD RECURRING VARS TO MAIN TRANSACTION OBJECT
$mpgTxn->setRecur($mpgRecur);
//SEND IT TO MONERIS
$mpgRequest = new mpgRequest($mpgTxn);
$mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest);
//GET RESPONSE FROM MONERIS
$mpgResponse = $mpgHttpPost->getMpgResponse();
$respCode = $mpgResponse->getResponseCode();
$message = $mpgResponse->getMessage();
//$mpgResponse->getIssuerId();
//GET RECUR RESULT: THIS IS EMPTY IN LIVE ENVIRONMENT, BUT "true" IN SANDBOX
$recurResult = $mpgResponse->getRecurSuccess();

How to complete pending transactions in paypal payouts

I am trying to implement a single Payout functionality in Paypal. I have referred to the sample code given by Paypal's documentation here. Everything seems to be working in order but the response given by PayPal indicates this: "batch_status": "PENDING". Here is my payout function:
public function payoutWithPaypal()
{
$request_amount = session()->get('request_amount');
$transaction_id = session()->get('transaction_id');
$receiver_email = session()->get('receiver_email');
$payouts = new \PayPal\Api\Payout();
$senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
$senderBatchHeader->setSenderBatchId(uniqid())->setEmailSubject("You have a Payout!");
$senderItem = new \PayPal\Api\PayoutItem();
$senderItem->setRecipientType('Email')
->setNote('Thanks for your patronage!')
->setReceiver($receiver_email)
->setSenderItemId("001")
->setAmount(new \PayPal\Api\Currency('{
"value":"'.$request_amount.'",
"currency":"USD"
}'));
$payouts->setSenderBatchHeader($senderBatchHeader)->addItem($senderItem);
$request = clone $payouts;
try {
$output = $payouts->create(array('sync_mode' => 'false'), $this->_api_context);
} catch (\Exception $ex) {
dd($ex);
}
return $output;
}
The solutions provided here have not really solved my issue.
Payouts run in a batch. For a batch status to begin as 'PENDING' is normal. The status of each payout within the batch is what matters. You can query them as needed, and if they are individually pending some reason may be given.
The most common reason for a PayPal payment to be pending in sandbox or live is if there is no PayPal account with a confirmed email (in sandbox or live, respectively) at the address to which the payment was sent. Receivers have 30 days to create an account and/or confirm the email on their account to accept the payment, otherwise it will be automatically refunded after 30 days. Reminders are sent to that email during this period.

CyberSource SOAP Toolkit API Token Payment?

I would like to test a payment with already created token from the previous transaction, but can't really find a way to do that using SOAP Toolkit API.
I found this in their documentation:
Requesting an On-Demand Transaction
An on-demand transaction is a real-time transaction using the details stored in a customer profile. On-demand transactions that you can request are:
 Credit cards—authorization, sale (an authorization and capture), and credit.
 Electronic checks—debit and credit.
 PINless debits—debit.
To request an on-demand sale transaction:
Step 1 Set the ccAuthService_run service field to true.
Step 2 Set the ccCaptureService_run service field to true.
Step 3 Include the following fields in the request:
 merchantID
 merchantReferenceCode
 purchaseTotals_currency
 purchaseTotals_grandTotalAmount
 recurringSubscriptionInfo_subscriptionID
So I assumed that recurringSubscriptionInfo_subscriptionID is the token that I need to provide, and wrote this code:
$referenceCode = 'my_merchant_id';
$client = new CybsSoapClient();
$request = $client->createRequest($referenceCode);
// Build a sale request (combining an auth and capture).
$ccAuthService = new stdClass();
$ccAuthService->run = 'true';
$request->ccAuthService = $ccAuthService;
$ccCaptureService = new stdClass();
$ccCaptureService->run = 'true';
$request->ccCaptureService = $ccCaptureService;
$request->merchantID = 'my_merchant_id';
$request->merchantReferenceCode = uniqid();
$request->purchaseTotals_currency = 'USD';
$request->purchaseTotals_grandTotalAmount = '25';
$request->recurringSubscriptionInfo_subscriptionID = 'xxxxxxxx';
$reply = $client->runTransaction($request);
When I first run this code, the API complained that I didn't provide billing info, but I thought that's not necessary cause I provided the token for payment. After adding the billing info, it started complaining about missing credit card number, which doesn't make any sense, cause the whole point is to avoid sending those information and use payment token instead.
I believe you need to enable name-value-pairs in order to provide fields using _ for nesting (e.g: recurringSubscriptionInfo_subscriptionID), when I changed your code to use XML payloads it worked:
// ...
$ccAuthService = new stdClass();
$ccAuthService->run = 'true';
$request->ccAuthService = $ccAuthService;
$ccCaptureService = new stdClass();
$ccCaptureService->run = 'true';
$request->ccCaptureService = $ccCaptureService;
$request->merchantID = '<my merchant id>';
$request->merchantReferenceCode = uniqid();
$recurringSubscriptionInfo = new stdClass();
$recurringSubscriptionInfo->subscriptionID = '<my subscription token>';
$request->recurringSubscriptionInfo = $recurringSubscriptionInfo;
$purchaseTotals = new stdClass();
$purchaseTotals->currency = 'USD';
$purchaseTotals->grandTotalAmount = '100';
$request->purchaseTotals = $purchaseTotals;
// ...

Recurlyv3 API doesn't find any data associated with valid token id

This is the essential bit of PHP:
// Add subscription
$subscription = new Recurly_Subscription();
$subscription->plan_code = $planCode;
$subscription->currency = 'USD';
$subscription->quantity = 1;
if ($couponCode != "") { $subscription->coupon_code = $couponCode; }
$subscription->account = new Recurly_Account();
$subscription->account->account_code = $customerID;
$subscription->billing_info = new Recurly_BillingInfo();
$subscription->account->billing_info->token_id = $token;
$subscription->create();
When this code runs, $token has the tokenID created by an earlier call to recurly.token (...) with the billing info.
The account already exists on Recurly -- the account ID, first and last names, but no billing info. This is because we allow people to signup for a complimentary service before subscribing. So I want to create the subscription on the extant account. Initially, following the code examples, the create() call was subscription->account->create(). But that failed because the account existed already.
This sounds like an issue with the old PHP library, which did not support tokenization of billing information. An upgrade to the PHP client library should fix this issue.

paypal recurring payment with initial payment

Hello im using paypal express checkout with the merchant sdk.
I have implemented recurring payment using the integration manual, but the given example doesnt make an initial payment(charge the user right away).
My code for making the payment is:
Initializing the payment:
$cart = $this->cart->getCart();
$items = $cart['items'];
$itemTotal = 0;
foreach ($items as $k => $item) {
$product = $this->addItem($item);
$itemTotal += $product->Amount;
$this->paymentDetails->PaymentDetailsItem[$k] = $product;
}
$this->orderTotal->currencyID = 'USD';
$this->orderTotal->value = $this->cart->getCartAmount();
$this->paymentDetails->OrderTotal = $this->orderTotal;
$this->paymentDetails->PaymentAction = 'Sale';
$this->paymentDetails->InvoiceID = $invoice_id->{'$id'};
$setECReqDetails = new \PayPal\EBLBaseComponents\SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[0] = $this->paymentDetails;
$setECReqDetails->CancelURL = $this->cancelURL;
$setECReqDetails->ReturnURL = $this->returnURL;
$billingAgreementDetails = new \PayPal\EBLBaseComponents\BillingAgreementDetailsType('RecurringPayments');
$billingAgreementDetails->BillingAgreementDescription = 'recurringbilling';
$setECReqDetails->BillingAgreementDetails = array($billingAgreementDetails);
$setECReqType = new \PayPal\PayPalAPI\SetExpressCheckoutRequestType();
$setECReqType->Version = $this->version;
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new \PayPal\PayPalAPI\SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
return $this->paypalService->SetExpressCheckout($setECReq);
And then on the return url i supplied i create the recurring payment with this code:
$profileDetails = new \PayPal\EBLBaseComponents\RecurringPaymentsProfileDetailsType();
$profileDetails->BillingStartDate = "2014-01-24T00:00:00:000Z";
$paymentBillingPeriod = new \PayPal\EBLBaseComponents\BillingPeriodDetailsType();
$paymentBillingPeriod->BillingFrequency = 10;
$paymentBillingPeriod->BillingPeriod = "Day";
$paymentBillingPeriod->Amount = new \PayPal\CoreComponentTypes\BasicAmountType("USD", "1.0");
$scheduleDetails = new \PayPal\EBLBaseComponents\ScheduleDetailsType();
$activationDetails = new \PayPal\EBLBaseComponents\ActivationDetailsType();
$activationDetails->InitialAmount = new \PayPal\CoreComponentTypes\BasicAmountType('USD', 49);
$activationDetails->FailedInitialAmountAction = 'ContinueOnFailure';
$scheduleDetails->Description = "recurringbilling";
$scheduleDetails->ActivationDetails = $activationDetails;
$scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
$createRPProfileRequestDetails = new \PayPal\EBLBaseComponents\CreateRecurringPaymentsProfileRequestDetailsType();
$createRPProfileRequestDetails->Token = $token;
$createRPProfileRequestDetails->ScheduleDetails = $scheduleDetails;
$createRPProfileRequestDetails->RecurringPaymentsProfileDetails = $profileDetails;
$createRPProfileRequest = new \PayPal\PayPalAPI\CreateRecurringPaymentsProfileRequestType();
$createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetails;
$createRPProfileReq = new \PayPal\PayPalAPI\CreateRecurringPaymentsProfileReq();
$createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
return $this->paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
}
In my sandbox account i can see that the recurring payment is created, but there is no initial payment.
My question is: How can i setup this recurring payment, so that an initial payment is made?
Hope i`ve explained good my problem. If you need more information comment.
EIDT: My question was how to create a recurring payment with initial payment. and i edited my code snippet. After some reading i saw that i missed to set it up with setting "ActivationDetailsType". I set it up and it works fine with one problem ... The payment profile is pending for 4-5 hours and then comes through. I read in forums and etc... that this was a sandbox issue but unfortunetly i cannot be sure that the payment will not be deleyd. In my case i need the payment to be approved right away. My new question is, when creating recurring payment profile, and the response for the account is ok(succes or what not) and the profile is pending can i count the payment as successful and be sure i`ll get the money for sure
Thank you for the time.
Regards,
Georgi
Quite late but I'm having similar concerns.
My new question is, when creating recurring payment profile, and the response for the account is ok(succes or what not) and the profile is pending can i count the payment as successful and be sure i`ll get the money for sure?
I'm currently working on it but I wouldn't count the pay until PayPal reflects the payment. I would utilize the IPN to trigger actions that should be made when the payment has come through. As for the 4-5 hour processing by PayPal (though sources from the web say production should not have the same delay), I'll just be sure to notify the buyer that his/her payment is still being processed by PayPal.

Categories