How to get the paypal customerid(subscriber_id) - php

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?

Related

Omnipay paypal integration - confirming payment status

I use Omnipay paypal library. I can make a successful payment but I have problems confirming the payment status. In the response I always get PAYMENTINFO_0_PAYMENTSTATUS => Pending
Here is my purchase code - I get redirected to paypal and it's all good here:
$gateway = Omnipay::create("PayPal_Express");
$gateway->setUsername( $this->USERNAME );
$gateway->setPassword( $this->PASSWORD );
$gateway->setSignature( $this->SIGNATURE );
$gateway->setTestMode(true);
$params = [
'cancelUrl'=>'http://xxxx.com/paypal_tests/cancel',
'returnUrl'=>'http://xxxx.com/paypal_tests/confirm_paypal',
'amount' => '10.00',
'currency' => 'EUR'
];
$response = $gateway->purchase( $params )->send();
$response->redirect();
And returnUrl, where in the response I always get [PAYMENTINFO_0_PAYMENTSTATUS] => Pending:
$gateway = Omnipay::create("PayPal_Express");
$gateway->setUsername( $this->USERNAME );
$gateway->setPassword( $this->PASSWORD );
$gateway->setSignature( $this->SIGNATURE );
$gateway->setTestMode(true);
$response = $gateway->completePurchase( $this->session->PAYPAL )->send();
$data = $response->getData(); // this is the raw response object
echo print_r($data);
Here is full response, as you can see status is "Pending".
Array
(
[TOKEN] => EC-1RA27631NJ550530P
[SUCCESSPAGEREDIRECTREQUESTED] => false
[TIMESTAMP] => 2016-03-07T10:29:43Z
[CORRELATIONID] => 8010f2af74b8
[ACK] => Success
[VERSION] => 119.0
[BUILD] => 18316154
[INSURANCEOPTIONSELECTED] => false
[SHIPPINGOPTIONISDEFAULT] => false
[PAYMENTINFO_0_TRANSACTIONID] => 97R504742X7344311
[PAYMENTINFO_0_TRANSACTIONTYPE] => expresscheckout
[PAYMENTINFO_0_PAYMENTTYPE] => instant
[PAYMENTINFO_0_ORDERTIME] => 2016-03-07T10:29:41Z
[PAYMENTINFO_0_AMT] => 1.44
[PAYMENTINFO_0_TAXAMT] => 0.00
[PAYMENTINFO_0_CURRENCYCODE] => EUR
[PAYMENTINFO_0_PAYMENTSTATUS] => Pending
[PAYMENTINFO_0_PENDINGREASON] => multicurrency
[PAYMENTINFO_0_REASONCODE] => None
[PAYMENTINFO_0_PROTECTIONELIGIBILITY] => Ineligible
[PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE] => None
[PAYMENTINFO_0_SECUREMERCHANTACCOUNTID] => Z6GHSVEW4KGWG
[PAYMENTINFO_0_ERRORCODE] => 0
[PAYMENTINFO_0_ACK] => Success
)
How to confirm that payment has been processed, confirmed and it is safe to dispatch?
Thanks!
OK, I found the problem, it is here:
[PAYMENTINFO_0_PENDINGREASON] => multicurrency
Basically my customer's test account was in US and seller's test account was charging in EUR, that's why it was pending....
And the answer is here: How do I use omnipay to check if it's a pending payment or not

Update CC info of Braintree in PHP

I am trying to update CC info of braintree but function provided in docs is not working . and I am unable to find out the reason.
Here is my function :
public function updateCC(){
$fname = $this->input->get_post('fname');
$lname = $this->input->get_post('lname');
$expirationYear = $this->input->get_post('expirationYear');
$expirationMonth = $this->input->get_post('expirationMonth');
$cardholderName = $this->input->get_post('cardholderName');
$cvv = $this->input->get_post('cvv');
$cc_no = $this->input->get_post('cc_no');
$token = $this->input->get_post('token');
$BTCustomerID = $this->input->get_post('BTCustomerID ');
$result = Braintree_Customer::update(
$BTCustomerID,
(
'firstName' => $fname,
'lastName' => $lname,
'creditCard' => (
'paymentMethodNonce' => 'fake-valid-nonce',
'options' => (
'updateExistingToken' => $token,
'verifyCard' => true
)
)
));
echo json_encode(array('error'=>-1));
}
Due to this code my application is crashing .
$result = Braintree_Customer::update(
$BTCustomerID,
(
'firstName' => $fname,
'lastName' => $lname,
'creditCard' => (
'paymentMethodNonce' => 'fake-valid-nonce',
'options' => (
'updateExistingToken' => $token,
'verifyCard' => true,
)
)
));
I’m a developer at Braintree. In your call to Braintree_Customer::update(), paymentMethodNonce must be passed inside of creditCard at the same level as options. In your code you are passing the it inside of options. See this code example for reference.

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
(
)
)
)

pay pal express checkout php

i ve been playing with the paypal api for exprescheckout.
the problem: i can not call the L_PAYMENTREQUEST_n_ methods.
the PAYMENTREQUEST_0_ works. but i can use this only for price or itemprice.
for the description and quantity i need to use L_PAYMENTREQUEST_n_ methods.
thx for any help
<?php
// EXpress Checkout Paypal
$paketdata = array(
array(
"name" => "Premium",
"desc" => "Mein Beschreibung",
"preis" => '9.96',
"count" => '2'
)
);
$endpreis = "18.97";
$desc = 'meine beschreibung name';
$paypal ="#";
$user = "paypalap#email.com";
$password = "passwd1234";
$signature ="fhhasHDJKHSAHJAL74327327dbsasahbsdcsadb7434";
$version = "93";
$currency = "EUR";
$params = array(
'METHOD' => 'SetExpressCheckout',
'USER' => $user,
'SIGNATURE' => $signature,
'PWD' => $password,
'RETURNURL' => 'https://localhost/env/paypal/geschafft.php',
'CANCELURL' => 'https://localhost/env/paypal/cancel.php',
'VERSION' => $version,
'PAYMENTREQUEST_0_AMT' => $endpreis,
'PAYMENTREQUEST_0_CURRENCYCODE' => $currency,
);
foreach ($paketdata as $k => $paket){
$params['L_PAYMENTREQUEST_0_NAME$k'] = $paket['name'];
$params['L_PAYMENTREQUEST_0_DESC$k'] = '';
$params['L_PAYMENTREQUEST_0_ITEMAMT$k'] = $paket['preis'];
}
$params = http_build_query($params);
$endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $endpoint,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_VERBOSE => 1
));
$response = curl_exec($curl);
$responseArray = array();
parse_str($response, $responseArray);
if (curl_errno($curl)) {
var_dump(curl_errno($curl));
curl_close($curl);
die();
}else{
if ($responseArray['ACK'] == 'Success') {
}else{
curl_close($curl);
}
}
curl_close($curl);
$paypal = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&useraction=commit&token=' . $responseArray['TOKEN'];
echo '<pre>';
print_r($paket);
echo '</pre>';
print_r($paypal)
?>
PAyPal
Your request is coming out like this...
Array
(
[METHOD] => SetExpressCheckout
[USER] => paypalap#email.com
[SIGNATURE] => fhhasHDJKHSAHJAL74327327dbsasahbsdcsadb7434
[PWD] => passwd1234
[RETURNURL] => https://localhost/env/paypal/geschafft.php
[CANCELURL] => https://localhost/env/paypal/cancel.php
[VERSION] => 93
[PAYMENTREQUEST_0_AMT] => 18.97
[PAYMENTREQUEST_0_CURRENCYCODE] => EUR
[L_PAYMENTREQUEST_0_NAME$k] => Premium
[L_PAYMENTREQUEST_0_DESC$k] =>
[L_PAYMENTREQUEST_0_ITEMAMT$k] => 9.96
)
You need to use double quotes around the param name in order to use $k directly inside like that, so you need this...
foreach ($paketdata as $k => $paket){
$params["L_PAYMENTREQUEST_0_NAME$k"] = $paket['name'];
$params["L_PAYMENTREQUEST_0_DESC$k"] = '';
$params["L_PAYMENTREQUEST_0_ITEMAMT$k"] = $paket['preis'];
}
That change then gives me this, which should go through just fine.
Array
(
[METHOD] => SetExpressCheckout
[USER] => paypalap#email.com
[SIGNATURE] => fhhasHDJKHSAHJAL74327327dbsasahbsdcsadb7434
[PWD] => passwd1234
[RETURNURL] => https://localhost/env/paypal/geschafft.php
[CANCELURL] => https://localhost/env/paypal/cancel.php
[VERSION] => 93
[PAYMENTREQUEST_0_AMT] => 18.97
[PAYMENTREQUEST_0_CURRENCYCODE] => EUR
[L_PAYMENTREQUEST_0_NAME0] => Premium
[L_PAYMENTREQUEST_0_DESC0] =>
[L_PAYMENTREQUEST_0_ITEMAMT0] => 9.96
)
On another note, though, you don't want to use localhost in your return and cancel URL's. PayPal's server is the one redirecting to that URL, so localhost at that time is their own server, which isn't going to do what you want, of course.
You need to use your public IP address or setup a domain that resolves to your IP that you can use.
In fact, it's funny, I just tried to use http:// on the front of localhost here, and Stack won't let me post links with that because of that very reason...they would be linking to themselves.

paypal This transaction cannot be processed. The amount to be charged is zero

Here is the code I used
$max_amount = 20;
//$max_amount = $this->currency->convert($order_info['total'], $this->config->get('config_currency'), 'USD');
$max_amount = min($max_amount * 1.25, 10000);
$max_amount = $this->currency->format($max_amount, $this->currency->getCode(), '', false);
$max_amount = $max_amount*100;
$data = array(
'METHOD' => 'SetExpressCheckout',
'MAXAMT' => $max_amount,
'AMT' => 1000,
'RETURNURL' => $this->url->link('payment/pp_express/checkoutReturn', '', 'SSL'),
'CANCELURL' => $this->url->link('checkout/checkout', '', 'SSL'),
'REQCONFIRMSHIPPING' => 0,
'NOSHIPPING' => 1,
'LOCALECODE' => 'EN',
'LANDINGPAGE' => 'Login',
'HDRIMG' => $this->model_tool_image->resize($this->config->get('pp_express_logo'), 790, 90),
'HDRBORDERCOLOR' => $this->config->get('pp_express_border_colour'),
'HDRBACKCOLOR' => $this->config->get('pp_express_header_colour'),
'PAYFLOWCOLOR' => $this->config->get('pp_express_page_colour'),
'CHANNELTYPE' => 'Merchant',
'ALLOWNOTE' => $this->config->get('pp_express_allow_note'),
);
$data = array_merge($data, $this->model_payment_pp_express->paymentRequestInfo());
echo '<pre>';
$result = $this->model_payment_pp_express->call($data);
print_r($result);
The result of print_r($result) is
Array
(
[TIMESTAMP] => 2014-05-26T13:48:19Z
[CORRELATIONID] => d5ff8073cbde
[ACK] => Failure
[VERSION] => 65.2
[BUILD] => 11110362
[L_ERRORCODE0] => 10525
[L_SHORTMESSAGE0] => Invalid Data
[L_LONGMESSAGE0] => This transaction cannot be processed. The amount to be charged is zero.
[L_SEVERITYCODE0] => Error
)
Whether I have to round up the values?
You don't have the AMT parameter included in your request. As such, it's getting seen as a zero value which PayPal doesn't accept.
You need to add the AMT parameter and pass the current amount of the order at the time the SEC request is made. Of course, this amount could change between that time and the final DoExpressCheckoutPayment request, but you just need to make sure the final amount is not greater than the MAXAMT you're passing here.

Categories