Paypal transaction tracking with Wordpress insert query? - php

I have done a transaction by sandbox mode on PayPal and I am using the Wordpress platform. The problem is my insert query was not executed.
After transaction, I have redirected the page from sandbox to xyz.com/payments-recieved and here I have printed the array and got this
Array
(
[tx] => 44K35922JH447994H
[st] => Completed
[amt] => 29.00
[cc] => USD
[cm] =>
[item_number] =>
[sig] => NXsJYzHJsIoReedCjkhnpWPQgoqLa5j4fAxcqk+CxJqgVHjdlBB/yWx0h4JVez/e2k+OOKeuhdgh/YxcD0bcR8JwmCd3GFE5N2UxoOws2JusqegLytKpcp6PmEb92aj9B1+e6MMHOf5VKjwX0z50imRiRtjYUSRasFT5IKiNbyA=
)
After that I am trying to insert all the details into the table and here is my full code.
<?php
/*
Template Name: All Payments History
*/
get_header();
echo "Thanks for choosing our plan<br />";
echo "<pre>";print_r($_REQUEST);
global $wpdb; //global query variable
if($_GET['st']=="Completed") /*check if transaction successfull or not*/
{
$item_transaction = $_GET['tx'];
$item_price = $_GET['amt'];
$item_currency = $_GET['cc'];
$item_no = $_GET['item_number'];
$wpdb->insert("wp_paypal_payments_tracking", array(
"transaction_id" => $item_transaction,
"amount" => $item_price,
"currency_type" => $item_currency,
"item_number" => $item_no,
));
echo "Payment Done Successfully";
}
get_footer();
?>
How we can fire insert query is there any problem in my code, please let me know and help me out.
Best Regards!!!

You can insert using the query, where wp_paypal_payments_tracking is your table name, you can change it
if ( !empty( $_REQUEST) && $_REQUEST['st']=='completed' ){
$wpdb->insert( 'wp_paypal_payments_tracking', array(
'tx' => $_REQUEST['tx'],
'st' => $_REQUEST['st'],
'amt' => $_REQUEST['amt'],
'cc' => $_REQUEST['cc'],
'cm' => $_REQUEST['cm'],
'item_number' => $_REQUEST['item_number'],
'sig' => $_REQUEST['sig'],
);
}

Related

How to get the paypal customerid(subscriber_id)

I am using cakephp2.0 framework. I am doing recurring payment. I am not getting the customer_id and other variables. And I also send the Recurring to Y.
Here is my code:
$paypalParams = array(
'paymentAction' => "Sale",
'amount' => $_POST['amount'],
'currencyCode' => "USD",
'creditCardType' => $_POST['card_type'],
'creditCardNumber' => trim(str_replace(" ","",$_POST['card_number'])),
'expMonth' => $_POST['expiry_month'],
'expYear' => $_POST['expiry_year'],
'cvv' => $_POST['cvv'],
'firstName' => $firstName,
'lastName' => $lastName,
'city' => $city,
'zip' => $zipcode,
'countryCode' => $countryCode,
'recurring' => 'Y',
'billingPeriod' => $session_details['paymentType'],
'billingFrequency' => "1",
'totalBillingCycles' => "0",
);
echo "<pre>"; print_r($paypalParams);
$response = $paypal->paypalCall($paypalParams);
When I call paypalCall function:
public function paypalCall($params){
/*
* Construct the request string that will be sent to PayPal.
* The variable $nvpstr contains all the variables and is a
* name value pair string with & as a delimiter
*/
$recurringStr = (array_key_exists("recurring",$params) && $params['recurring'] == 'Y')?'&RECURRING=Y':'';
$nvpstr = "&TOTALBILLINGCYCLES=".$params['totalBillingCycles']."&BILLINGFREQUENCY=".$params['billingFrequency']."&BILLINGPERIOD=".$params['billingPeriod']."&PAYMENTACTION=".$params['paymentAction']."&AMT=".$params['amount']."&CREDITCARDTYPE=".$params['creditCardType']."&ACCT=".$params['creditCardNumber']."&EXPDATE=".$params['expMonth'].$params['expYear']."&CVV2=".$params['cvv']."&FIRSTNAME=".$params['firstName']."&LASTNAME=".$params['lastName']."&CITY=".$params['city']."&ZIP=".$params['zip']."&COUNTRYCODE=".$params['countryCode']."&CURRENCYCODE=".$params['currencyCode'].$recurringStr;
//echo "<pre>"; print_r($nvpstr); die;
/* Make the API call to PayPal, using API signature.
The API response is stored in an associative array called $resArray */
$resArray = $this->hashCall("DoDirectPayment",$nvpstr);
echo "<pre>"; print_r($resArray); die;
return $resArray;
}
When I print this array($resArray) it gives only these parameters:
enter code here
<pre>Array
(
[TIMESTAMP] => 2016-12-29T09:05:26Z
[CORRELATIONID] => 42743fa743c6
[ACK] => Success
[VERSION] => 65.1
[BUILD] => 24616352
[AMT] => 19.99
[CURRENCYCODE] => USD
[AVSCODE] => X
[CVV2MATCH] => M
[TRANSACTIONID] => 9A3464215B244930U
)
There is no customerid(subscriber_id).
Could anyone help me to see what I am doing wrong?

Unable to get session data from paypal express checkout in laravel 4

I am unable to get session information in omnipay laravel 4 after getting express checkout return after making express checkout.
I do get Tokens and PayerID noting else. Session data of that site become empty.
Please tell how can I completePurchase Process. Is there any way to get purchase order ID from paypal. I am using omnipay.
public function doSaveAndProcessedToPayPal( $purchaseOrder)
{
$purchaseOrderId = $purchaseOrder->id;
Session::put('currentUserEmail', $email);
Session::put('purchaseOrderId', $purchaseOrderId);
Session::put('amount', $amount);
$gateway = $this->getPayPalGateway();
$items = new Omnipay\Common\ItemBag();
$items->add(array(
'name' => $productName,
'quantity' => '1',
'price' => (float)$amount,
));
$response = $gateway->purchase(
array(
'cancelUrl' => CANCEL_URL,
'returnUrl' => RETURN_URL,
'amount' => (float)$amount,
'currency' => $currency
)
)->setItems($items)->send();
$response->redirect();
}
public function doPerformPostPaymentOperation()
{
$gateway = $this->getPayPalGateway();
$purchaseOrderId = Session::get('purchaseOrderId');
$amount = Session::get('amount');
$currency = Session::get('currency');
$data = Session::all();
echo "<pre>";
print_r( $data );
echo "</pre>";
echo $purchaseOrderId;
die();
$response = $gateway->completePurchase(array(
'transactionId' => "ORD-".$purchaseOrderId,
'transactionReference' => "REF-".$purchaseOrderId,
'amount' => (float)$amount,
'currency' => $currency,
))->send();
if ( ! $response->isSuccessful())
{
throw new Exception($response->getMessage());
}
}
Output
Array
(
[_token] => lnvG1S3eU2JsHJSciOTjixEEHiSwZVX47daRLDXE
[flash] => Array
(
[old] => Array
(
)
[new] => Array
(
)
)
)

Use Paypal Pro instead of Paypal Express - Omnipay for Laravel

I have a shopping cart that currently is redirecting users to paypal directly to make their payment. I am wanting to allow customers to input their credit card on the site and paypal to process it. I have Paypal Pro account but I am having trouble using it. I am not sure how I can use the Paypal Pro package via Omnipay. In my vendors folder I have a ExpressGateway.php and a Progateway.php but not sure how to call the Progateway.php page. The only way I can see to set it is by using Omnipay::getway('paypal') which I currently do for express. What is the process i need to use in order to use Paypal Pro?
$gateway = Omnipay::gateway('paypal');
if(Auth::user() != NULL && Auth::user()->super_user == 1) {
//sandbox
$gateway->setUsername('#######');
$gateway->setPassword('#######');
$gateway->setSignature('#######');
$gateway->setTestMode('true');
} else {
//production
$gateway->setUsername('#######');
$gateway->setPassword('#######');
$gateway->setSignature('######');
}
$cardInput = array(
'firstName' => $info['first_name_bill'],
'lastName' => $info['last_name_bill'],
'billingAddress1' => $info['street_address_1_bill'],
'billingAddress2' => $info['street_address_2_bill'],
'billingPhone' => $info['phone_bill'],
'billingCity' => $info['city_bill'],
'billingState' => $info['state_bill'],
'billingPostCode' => $info['zip_bill'],
'shippingAddress1' => $info['street_address_1_ship'],
'shippingAddress2' => $info['street_address_2_ship'],
'shippingPhone' => $info['phone_ship'],
'shippingCity' => $info['city_ship'],
'shippingState' => $info['state_ship'],
'shippingPostCode' => $info['zip_ship'],
);
$card = Omnipay::creditCard($cardInput);
$response = Omnipay::purchase(
array(
'cancelUrl' => URL::to('cart'),
'returnUrl' => URL::action('CartController#getSuccessPayment', array('id' =>$invoice->id)),
'amount' => Input::get('total'),
'currency' => 'USD',
'card' => $card,
'description' => '#####'
)
)->send();`
Set the gateway this way:
$gateway = Omnipay::gateway('Paypal_Pro');

Omnipay with Paypal Express

I have an ecommerce website that redirects to a Paypal express checkout using Omnipay. It will correctly redirect the user to Paypal and return with a successful message with payerID and everything. However, it does not actually take any payment and it does not show up on our paypal account as any payment taken. I am not sure if this is a paypal issue or a configuration problem with Omnipay. I would imagine that Paypal handles this part of it but since it's not working (on our old site it works fine but we do not use Omnipay.)
$gateway = Omnipay::gateway('paypal');
//production
$gateway->setUsername('11111111');
$gateway->setPassword('1111111111');
$gateway->setSignature('111111111');
$cardInput = array(
'firstName' => $info['first_name_bill'],
'lastName' => $info['last_name_bill'],
'billingAddress1' => $info['street_address_1_bill'],
'billingAddress2' => $info['street_address_2_bill'],
'billingPhone' => $info['phone_bill'],
'billingCity' => $info['city_bill'],
'billingState' => $info['state_bill'],
'billingPostCode' => $info['zip_bill'],
'shippingAddress1' => $info['street_address_1_ship'],
'shippingAddress2' => $info['street_address_2_ship'],
'shippingPhone' => $info['phone_ship'],
'shippingCity' => $info['city_ship'],
'shippingState' => $info['state_ship'],
'shippingPostCode' => $info['zip_ship'],
);
$card = Omnipay::creditCard($cardInput);
//live
$response = Omnipay::purchase(
array(
'cancelUrl' => 'http://store.site.com/cart/cancel-payment',
'returnUrl' => 'http://store.site.com/cart/successful-payment',
'amount' => Input::get('total'),
'currency' => 'USD',
'card' => $card,
'description' => 'Stuff'
)
)->send();
if ($response->isSuccessful()) {
return Redirect('cart/successful-payment');
} elseif ($response->isRedirect()) {
$response->redirect(); // this will automatically forward the customer
} else {
return Redirect::back()->with('error', 'There was a problem. Please try again.');
}
} else {
return Redirect::to('cart/successful-payment');
}
So basically what this will do is redirect them to Paypal to make a payment then redirect back to our store. That all works fine. They can input their card number and then come back to our store after submitting it. The issue is after it gets return nothing happens through paypal. No orders or payment are exchanged.
In your return function, the function that gets called when this URL is executed: http://store.site.com/cart/successful-payment you need to call completePurchase. Something like this:
$gateway = Omnipay::gateway('paypal');
//production
$gateway->setUsername('11111111');
$gateway->setPassword('1111111111');
$gateway->setSignature('111111111');
$purchaseId = $_GET['PayerID'];
$response = $gateway->completePurchase([
'transactionReference' => $purchaseId
])->send();
// .. check $response here.

Show billing and shipping information in Paypal Express using Omnipay

I am using Laravel with Omnipay for our ecommerce application. We direct the customers to Paypal to make their purchase. We require shipping and billing information prior to placing an order and we would like that information to continue to Paypal to make it easier for them. However, only the first name and last name are crossing over to Paypal correctly. We can also use email with no issues.
public function postPayment() {
//var_dump(Session::get('shipping_info')); die;
$info = Session::get('shipping_info');
$gateway = Omnipay::gateway('paypal');
//sandbox
$gateway->setUsername('xxxx');
$gateway->setPassword('xxxx');
$gateway->setSignature('xxx');
$gateway->setTestMode('true');
//production
// $gateway->setUsername('xxxx');
// $gateway->setPassword('xxxx');
// $gateway->setSignature('xxxx');
$cardInput = array(
'firstName' => $info['first_name_bill'],
'lastName' => $info['last_name_bill'],
'billingAddress1' => $info['street_address_1_bill'],
'billingAddress2' => $info['street_address_2_bill'],
'billingPhone' => $info['phone_bill'],
'billingCity' => $info['city_bill'],
'billingState' => $info['state_bill'],
'billingPostCode' => $info['zip_bill'],
'shippingAddress1' => $info['street_address_1_ship'],
'shippingAddress2' => $info['street_address_2_ship'],
'shippingPhone' => $info['phone_ship'],
'shippingCity' => $info['city_ship'],
'shippingState' => $info['state_ship'],
'shippingPostCode' => $info['zip_ship'],
);
$card = Omnipay::creditCard($cardInput);
// var_dump($card); die;
$response = Omnipay::purchase(
array(
'cancelUrl' => 'http://localhost/public/',
'returnUrl' => 'http://localhost/public/',
'amount' => Input::get('total'),
'currency' => 'USD',
'card' => $card,
'description' => 'Stuff'
)
)->send();
$response->redirect();
}
According to the docs https://github.com/omnipay/omnipay it should work with no issues. dumping the sessions reveals the correct billing and shipping parameters.
It was just needing a cache refresh.

Categories