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();
Related
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.
On making the TransactionSearch request I receive the list of the transactions with the TRANSACTIONID field for the transactions, corresponding to the recurring payments, in the form e.g. "I-BRPN2RUD8W0G" (current is fake).
For the rest transactions - I get usual 17 single-byte alphanumeric string. That means, that for recurring payments PayPal returns ProfileID, but not TransactionID.
As a result when I request the GetTransactionDetails with this transaction id passed to PayPal I receive valid details for ordinary payments and ERROR with the message "The transaction id is not valid" for the case of recurring payments.
You will need to set IPN as suggested by Sanjiv. You can get the fields as per IPN Variables. In case of refund you will also need to use parent_txn_id
If you are new with this and finding tough, you can use IPN listener class and then integrate below code
$listener = new IpnListener();
try {
$verified = $listener->processIpn();
} catch (Exception $e) {
return Log::error($e->getMessage());
}
if ($verified) {
$data = $_POST;
$user_id = json_decode($data['custom'])->user_id;
$subscription = ($data['mc_gross_1'] == '10') ? 2 : 1;
$txn = array(
'txn_id' => $data['txn_id'],
'user_id' => $user_id,
'paypal_id' => $data['subscr_id'],
'subscription' => $subscription,
'expires' => date('Y-m-d H:i:s', strtotime('+1 Month')),
);
Payment::create($txn);
} else {
Log::error('Transaction not verified');
}
Save this file code in file let say, ipn.php and now assign web path for this file in your paypal account.
PS: make sure your IPN file is on publicly accessible URL. Do not use local or restricted server.
You have to set IPN in your Paypal merchant account (specially for recurring payments), Which sends you back a transaction details when a recurring payment happens, from there you can get $_POST['txn_id'] which is your TRANSACTIONID if $_POST['txn_type'] is recurring_payment. Save the details in your database and then you can call GetTransactionDetails method when you need transaction details. More
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.
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.
I was download and edit the code for google checkout from google help.Here i specify murchent calculation url in my site.But that function donot work in my site.Here is my code
function UseCase3() {
//Create a new shopping cart object
$merchant_id = "xxxxxxxxxxxxx"; // Your Merchant ID
$merchant_key = "xxxxxxxxxxxxx";
$server_type = "sandbox";
$currency = "USD";
$cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
// Add items to the cart
$item = new GoogleItem("MegaSound 2GB MP3 Player",
"Portable MP3 player - stores 500 songs", 1, 175.49);
$item->SetMerchantPrivateItemData("<color>blue</color><weight>3.2</weight>");
$cart->AddItem($item);
// Add merchant calculations options
$cart->SetMerchantCalculations(
"https://mysite.com/google2/demo/responsehandlerdemo.php",
"false", // merchant-calculated tax
"true", // accept-merchant-coupons
"true"); // accept-merchant-gift-certificates
// Add merchant-calculated-shipping option
$ship = new GoogleMerchantCalculatedShipping("2nd Day Air", // Shippping method
10.00); // Default, fallback price
$restriction = new GoogleShippingFilters();
$restriction->AddAllowedPostalArea("GB");
$restriction->AddAllowedPostalArea("US");
$restriction->SetAllowUsPoBox(false);
$ship->AddShippingRestrictions($restriction);
$address_filter = new GoogleShippingFilters();
$address_filter->AddAllowedPostalArea("GB");
$address_filter->AddAllowedPostalArea("US");
$address_filter->SetAllowUsPoBox(false);
$ship->AddAddressFilters($address_filter);
$cart->AddShipping($ship);
// Set default tax options
$tax_rule = new GoogleDefaultTaxRule(0.15);
$tax_rule->SetWorldArea(true);
$cart->AddDefaultTaxRules($tax_rule);
$cart->AddRoundingPolicy("UP", "TOTAL");
// Specify <edit-cart-url>
$cart->SetEditCartUrl("https://mysite.com/google/demo/cartdemo.php");
// Specify "Return to xyz" link
$cart->SetContinueShoppingUrl("https://mysite.com");
// Display XML data
// echo "<pre>";
// echo htmlentities($cart->GetXML());
// echo "</pre>";
// Display a disabled, small button
echo $cart->CheckoutButtonCode("SMALL");
}
Clarifications:
Merchant Calculations URL - as the name implies is the URL that Google will use to send a callback request for Shipping and Tax, promotions calculations. That is its purpose as documented in Merchant Calculations API. It is part of the Checkout Phase (sending information to Google for checkout).
API Callback URL - which is set in your account (Integration Settings) and not sent in any request (unlike merchant calculations url) and is the URL Google will send Notifications to as documented in Notification API. This is the API you need to implement in order to obtain data from Google (getting information from Google - e.g. after checkout)
So these urls/APIs serve different purposes.
Based on your comment:
I need to execute a php file after user pay through Google checkout
You need to implement the Notification API (the merchant calcuations url/api is not what you need).