pay pal express checkout php - 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.

Related

Can't get an unenrolled 3d-secure card authenticaited (secrure trading)

I am running a PHP 7.3, running on apache server. I used composer to get this library:
https://github.com/SecureTrading/PHP-API
For the code provided, I am now using the test site reference. I already managed to use for regular transitions. I now started managing 3D secure transactions, with the test MAESTRO card provided by secure trading here: https://docs.securetrading.com/document/testing/. the one designed not to demand 3D auth - that is 5000000000000421
The code provided next, will sum up the way I think thought this should work: I start by creating AUTH request, get error 30004, using CACHETOKENISE request to get a token, run THREEDQUERY to figure out if I need a full auth sceme on this card, get N as an answer, and run another AUTH request, this time with the transactionreference.
I am providing a version of the code I am testing (obviously, username, password and site reference name was removed to protect my privacy, but the code otherwise is the same)
<?php
$configData = array(
'username' => 'api#gigsberg.com',
'password' => 'xq!Kq$j4',
);
$site_refrance = 'test_gigsberg74319';
?>
<?php
$configData = array(
'username' => '*****',
'password' => '*****',
);
$site_refrance = '*****';
if (!($autoload = realpath(__DIR__ . '/vendor/autoload.php'))) {
throw new \Exception('Composer autoloader file could not be found.');
}
require_once($autoload);
$api = \Securetrading\api($configData);
$requestData = array(
'sitereference' => $site_refrance,
'requesttypedescription' => 'AUTH',
'accounttypedescription' => 'ECOM',
'currencyiso3a' => 'GBP',
'mainamount' => '1000',
'pan' => '5000000000000421',
'expirymonth' => '12',
'expiryyear' => '2030',
'securitycode' => '123',
);
echo '<pre>';
print_r($requestData);
$response = $api->process($requestData)->toArray();
print_r( $response['responses'] ); // $response['responses'][0]['errorcode'] == 30004
echo "\n--------------------------------------\n";
$transactionreference = $response['responses'][0]['transactionreference'];
$requestData = array(
'sitereference' => $site_refrance,
'expirymonth' => '12',
'expiryyear' => '2030',
'requesttypedescriptions' => array('CACHETOKENISE'),
'securitycode' => '123',
'orderreference' => $transactionreference,
'pan' => '5000000000000421'
);
print_r($requestData);
$response = $api->process($requestData)->toArray();
echo "\n--------------------------------------\n";
$cachetoken = $response['responses'][0]['cachetoken'];
$requestData = array(
'termurl' => 'https://termurl.com',
'accept' => 'text/html,*/*',
'currencyiso3a' => 'GBP',
'requesttypedescription' => 'THREEDQUERY',
'accounttypedescription' => 'ECOM',
'sitereference' => $site_refrance,
'baseamount' => '1000',
'pan' => '5000000000000421',
'expirymonth' => '12',
'expiryyear' => '2030',
'cachetoken' => $cachetoken,
);
print_r($requestData);
$response = $api->process($requestData)->toArray(); // $response['responses'][0]['enrolled'] == 'N'
/* Copying from the docs here: https://docs.securetrading.com/document/api/security/3-d-secure/
* If the enrolled value returned in the response is “Y”, the customer’s card is enrolled in 3-D secure. Please refer to the following table for enrolled values:
* .
* .
* N - The card is not enrolled in the card issuer’s 3-D Secure scheme. - Perform an AUTH Request, including the transactionreference returned in the THREEDQUERY response.
* .
* .
*/
print_r( $response['responses'] );
echo "\n--------------------------------------\n";
$transactionreference = $response['responses'][0]['transactionreference'];
$requestData = array(
'sitereference' => $site_refrance,
'requesttypedescription' => 'AUTH',
'accounttypedescription' => 'ECOM',
'currencyiso3a' => 'GBP',
'mainamount' => '1000',
'pan' => '5000000000000421',
'expirymonth' => '12',
'expiryyear' => '2030',
'securitycode' => '123',
'transactionreference' => $transactionreference
);
print_r($requestData);
$response = $api->process($requestData)->toArray();
print_r( $response['responses'] ); // Still get $response['responses'][0]['errorcode'] == 30004
I expected it to give me a note that all works well, but I still got error 30004, as if the transactionreference wasn't provided. Any idea what I can do, to fix this code, and prevent this error?
Thanks in advance
Yair
Well, I read the Api tests, and I found my error. On the last request data, instead of
$requestData = array(
.
.
'transactionreference' => $transactionreference
.
.
);
I should use
$requestData = array(
.
.
'parenttransactionreference' => $transactionreference
.
.
);
Anyway, home this helps somone

authentication to MQ via mqseries library php

I need some help with php mqseries library.
I have some troubles connecting to Queue-manager. It does connect without authentication, but when I'm trying to use MQCSP, I get
2035 error.
I've contacted the developers, one of them told me that he no longer works on it, others don't respond.
It looks like on IBM it doesn't work.
Here is my connection code:
$cfg = array();
$cfg['ESB_ADDRESS'] = '10.4.116.110(1416)';
$cfg['ESB_CHANNEL'] = 'SITEEXT.SVRCONN';
$cfg['ESB_QUEUE_MANAGER'] = 'IIB.ADP.MI1';
$cfg['ESB_QUEUE_NAME'] = 'SITEEXT_TO_ESB';
$cfg['ESB_TOPIC_STRING'] = '';
$cfg['USERID'] = 'svcgo-site';
$cfg['PASSWORD'] = 'site91';
$cfg['QMgrName'] = 'IIB.ADP.MI1';
$cfg['DiscInterval'] = '10';
/*
$cfg['ESB_ADDRESS'] = '10.4.111.139(1414)';
$cfg['ESB_CHANNEL'] = 'SITEEXT.SVRCONN';
$cfg['ESB_QUEUE_MANAGER'] = 'QM01';
$cfg['ESB_QUEUE_NAME'] = 'TEST_QUEUE1';
//$cfg['ESB_QUEUE_NAME'] = 'SITEEXT_TO_ESB';
$cfg['ESB_TOPIC_STRING'] = '';
$cfg['USERID'] = 'svcgo-site';
$cfg['PASSWORD'] = 'site91';
//$cfg['QMgrName'] = 'QM01';
$cfg['DiscInterval'] = '10';
*/
$connectionOptions = array(
'StrucId' => MQSERIES_MQCNO_STRUC_ID,
'Version' => MQSERIES_MQCNO_CURRENT_VERSION,
'Options' => MQSERIES_MQCNO_STANDARD_BINDING,
//MQSERIES_USE_MQCSP_AUTHENTICATION,
'MQCD' => array(
//'Version' => MQSERIES_MQCD_VERSION_11,
'ChannelName' => $cfg['ESB_CHANNEL'],
'TransportType' => MQSERIES_MQXPT_TCP,
'ConnectionName' => $cfg['ESB_ADDRESS']
),
MQSERIES_USE_MQCSP_AUTHENTICATION => true,
MQSERIES_MQCSP_AUTHENTICATION => true,
USER_AUTHENTICATION_MQCSP => true,
USE_MQCSP_AUTHENTICATION => true,
MQSERIES_USER_AUTHENTICATION_MQCSP => true,
useMQCSPAuthentication => true,
'MQCSP' => array(
'Version' => MQSERIES_MQCSP_CURRENT_VERSION,
'StrucId' => MQSERIES_MQCSP_STRUC_ID,
'AuthenticationType' => MQSERIES_MQCSP_AUTH_USER_ID_AND_PWD,
'CSPUserIdPtr' => $cfg['USERID'],
'CSPUserIdLength' => strlen($cfg['USERID']),
'CSPPasswordLength' => strlen($cfg['PASSWORD']),
'CSPPasswordPtr' => $cfg['PASSWORD']
),
/*
'ClientConnPtr' => array(
//'Version' => MQSERIES_MQCD_VERSION_11,
'ChannelName' => $cfg['ESB_CHANNEL'],
'TransportType' => MQSERIES_MQXPT_TCP,
'ConnectionName' => $cfg['ESB_ADDRESS']
)
*/
);
mqseries_connx($cfg['ESB_QUEUE_MANAGER'], $connectionOptions, $connection, $completionCode, $reason);
if ($completionCode !== MQSERIES_MQCC_OK) {
die("Connx CompCode : {$completionCode} Reason : {$reason} Text : " . mqseries_strerror($reason));
}
else{echo "Good<br>";}
Php v.5.3.17
IBM MQ 9
Mqseries client library v 0.15.0
That PHP package does not have the code in it to handle the MQCSP structure and add it to the CNO. Looks like you would need to modify the _mqseries_set_mqcno_from_array function and how it is called.

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

how to setup recurring payments in paypal

I'm trying to setup recurring payments in paypal with PHP. But the problem that I'm having is that I don't know if I'm doing the right thing. I have this class which makes the request to the Paypal API:
<?php
class Paypal {
protected $_errors = array();
protected $_credentials = array(
'USER' => 'my-user-id',
'PWD' => 'my-pass',
'SIGNATURE' => 'my-signature',
);
protected $_endPoint = 'https://api-3t.sandbox.paypal.com/nvp';
protected $_version = '74.0';
public function request($method,$params = array()) {
$this -> _errors = array();
if( empty($method) ) {
$this -> _errors = array('API method is missing');
return false;
}
$requestParams = array(
'METHOD' => $method,
'VERSION' => $this -> _version
) + $this -> _credentials;
$request = http_build_query($requestParams + $params);
$http_header = array(
'X-PAYPAL-SECURITY-USERID' => 'my-user-id',
'X-PAYPAL-SECURITY-PASSWORD' => 'my-pass',
'X-PAYPAL-SECURITY-SIGNATURE' => 'my-signature',
'X-PAYPAL-REQUEST-DATA-FORMAT' => 'JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT' => 'JSON'
);
$curlOptions = array (
CURLOPT_HTTPHEADER => $http_header,
CURLOPT_URL => $this -> _endPoint,
CURLOPT_VERBOSE => 1,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $request
);
$ch = curl_init();
curl_setopt_array($ch,$curlOptions);
$response = curl_exec($ch);
if (curl_errno($ch)) {
$this -> _errors = curl_error($ch);
curl_close($ch);
return false;
} else {
curl_close($ch);
$responseArray = array();
parse_str($response,$responseArray);
return $responseArray;
}
}
}
?>
Then I'm making the initial request like this:
session_start();
require_once('Paypal.php');
$paypal = new Paypal();
$amount = 1;
$requestParams = array(
'RETURNURL' => 'http://localhost/tester/paypal/new_test/test_done.php',
'CANCELURL' => 'http://localhost/tester/paypal/new_test/test_cancel.php',
'NOSHIPPING' => '1',
'ALLOWNOTE' => '1',
'L_BILLINGTYPE0' => 'RecurringPayments',
'L_BILLINGAGREEMENTDESCRIPTION0' => 'site donation'
);
$orderParams = array(
'PAYMENTREQUEST_0_AMT' => '1',
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
'PAYMENTREQUEST_0_ITEMAMT' => $amount
);
$item = array(
'L_PAYMENTREQUEST_0_NAME0' => 'site donation',
'L_PAYMENTREQUEST_0_DESC0' => 'site donation',
'L_PAYMENTREQUEST_0_AMT0' => $amount,
'L_PAYMENTREQUEST_0_QTY0' => '1'
);
$response = $paypal->request('SetExpressCheckout', $requestParams + $orderParams + $item);
$sandbox_location = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=';
if(is_array($response) && $response['ACK'] == 'Success'){
$token = $response['TOKEN'];
$_SESSION['token'] = $token;
header('Location: ' . $sandbox_location . urlencode($token));
}
?>
As you can see I'm using the SetExpressCheckout API method to get the token that I need and store it in a session so that I can use it later with the request for CreateRecurringPaymentsProfile.
I'm currently redirected to a page similar to this:
Once the user is done logging in with paypal and confirming the amount it redirects to the success page that I've specified which contains this code:
session_start();
require_once('Paypal.php');
$amount = 1;
$paypal = new Paypal();
$token_param = array('TOKEN' => $_SESSION['token']);
$current_date = date('Y-m-d');
$recurring_payment_params = array(
'PROFILESTARTDATE' => gmdate('Y-m-d H:i:s', strtotime($current_date . ' + 1 months')),
'DESC' => 'site donation',
'BILLINGPERIOD' => 'Month',
'BILLINGFREQUENCY' => '1',
'TOTALBILLINGCYCLES' => '0',
'AMT' => $amount
);
$recurringpayment_response = $paypal->request('CreateRecurringPaymentsProfile', $recurring_payment_params + $token_param);
This works, I've verified in the sandbox account that the recurring payment profile was created and that the next billing due is next month. But the problem is that its not really visible in the paypal interface (the screenshot earlier) that they're paying for a subscription. Perhaps I'm getting the redirect url wrong? (https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=) or do I have to add additional arguments to the SetExpressCheckout method? Please help.
You're only showing the login screen. After you login you'll see information about the subscription and the button will see "Agree and Pay" or "Agree and Continue" (depending on your useraction value in the return URL) instead of just "Pay" or "Continue".

Categories