How to complete pending transactions in paypal payouts - php

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.

Related

Could not process Bank Of America debit or credit cards -> Card declined by issuer

We’ve just implemented Authorize.net on our new platform to replace our old one (braintree).
We have done some tests, from the charge credit card example that we adapted to our code.
It worked perfectly fine with Chase and Capital One debits card but didn’t work on any of bank of america debit and credit cards for some mysterious reasons. When looking on my profile I can read "Card declined by issuer”. I called the bank and they said the card wasn’t activated (When you receive a new card you need to activate it first). But all the card we’ve tried have been activated for long and we already processed payments online with (it also work on Braintree).
I went to my merchant service representative but they haven’t been able to help me. Am I doing something wrong? Did you hear about similar issues ? I’m concerned for other issues with banks when turning this thing live.
Here is my piece of code :
`
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName($this->ci->config->item('AUTHNETAPILOGINID'));
$merchantAuthentication->setTransactionKey($this->ci->config->item('AUTHNETKEY'));
$refId = 'ref' . time();
// Remove potential white spaces
$ccn = preg_replace('/\s+/', '', $ccn);
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber( intval( $ccn ) );
$creditCard->setExpirationDate( $exp );
$creditCard->setCardCode( $cvc );
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
$order = new AnetAPI\OrderType();
$order->setDescription("Ticket");
// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount( $amount );
$transactionRequestType->setOrder( $order );
$transactionRequestType->setPayment($paymentOne);
$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId( $refId );
$request->setTransactionRequest($transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);
$response_api = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
if ($response_api != null)
{ // more code }`
I was hoping you could help me debut if it’s coming from here. Should I add the postal code or address to make sure it’s not a security issue on their end ? Where could that come from ? I’m a little lost on this.
Thanks!

Magento Credit card number mismatch with credit card type exception

I am using stripe credit card payment method for website on my magento store and developing a mobile application. I am developing the api's using native magento api. Problem occurred on create order api, everything till adding payment for stripe credit card works fine but when I hit the create order api it throws the exception.
"Credit card number mismatch with credit card type exception"
Below is api code, Please share your knowledge for this issue. Thanks in advance.
$proxy = new SoapClient($this->_client); //soap handle
$sessionId = $proxy->login($this->_apiuser, $this->_apikey);
$resultCustomerAddresses = $proxy->call($sessionId, "cart_customer.addresses", array($shoppingCartId, $arrAddresses));
if ($resultCustomerAddresses != TRUE)
{
return json_encode(array('status' => 0, 'result' => array(),'message' => 'Error in saving address'));
}
$resultShippingMethods = $proxy->call($sessionId, "cart_shipping.list", array($shoppingCartId));
$randShippingMethodIndex = rand(0, count($resultShippingMethods)-1 );
$shippingMethod = $resultShippingMethods[$randShippingMethodIndex]["code"];
$resultShippingMethod = $proxy->call($sessionId, "cart_shipping.method", array($shoppingCartId, $shipping_method));
//$resultTotalOrder = $proxy->call($sessionId,'cart.totals',array($shoppingCartId));
$paymentMethod = array(
"method" => $payment_method
);
$resultPaymentMethod = $proxy->call($sessionId, "cart_payment.method", array($shoppingCartId, $payment_method));
$licenseForOrderCreation = null;
$resultOrderCreation = $proxy->call($sessionId,"cart.order",array($shoppingCartId, null, $licenseForOrderCreation));
I had the same problem and successfully solved it, see this answer: https://stackoverflow.com/a/41948259/1052675
Basically, you supply the card information before you save the quote. It will validate the card against regex patterns and configured purchase limits and make sure you can use the payment method.
Then it will forget the payment information.
So before you tell it to submit the order, you need to supply the card info again.
My solution was a custom endpoint for simplicity on the front end app and it enabled me to keep the card info in memory to re-save between saving the quote and submitting the order.

PayPal - Get transaction details for recurring profile

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

Authorize.net AIM Transaction

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.

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