I have this problem. I've follow this tutorial -> http://www.youtube.com/watch?v=rzRR1i-F_VA
and after setting everything, I have some problem with getting through the authentification process. And After some research on authentification, I've tested this -> https://developer.paypal.com/webapps/developer/docs/classic/lifecycle/ug_sandbox/
At some point in the process (Making test requests), I've tested it in a bash console, and my userid, password and signature worked. So I figure that the problem was in the code I was using.
So here's the code:
<?php
class PaypalTest extends CComponent{
public $api_user = "**********************";
public $api_pass = "***********";
public $api_sig = "**************************";
public $app_id = "APP-80W284485P519543T";
public $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
public $paypalUrl="https://www.paypal.com/webscr?cmd=_ap-payment&paykey=";
public $headers;
public function __construct(){
$this->headers = array(
"X-PAYPAL-SECURITY-USERID: ".$this->api_user,
"X-PAYPAL-SECURITY-PASSWORD: ".$this->api_pass,
"X-PAYPAL-SECURITY-SIGNATURE: ".$this->api_sig,
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ".$this->app_id,
);
}
public function getPaymentOptions($paykey){
}
public function setPaymentOptions(){
}
public function _paypalSend($data,$call){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->apiUrl.$call);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HEADER, $this->headers);
$response = json_decode(curl_exec($ch),true);
return $response;
}
public function splitPay(){
// create the pay request
$createPacket = array(
"actionType" =>"PAY",
"currencyCode" => "USD",
"receiverList" => array(
"receiver" => array(
array(
"amount"=> "1.00",
"email"=>"********#hotmail.com"
),
array(
"amount"=> "2.00",
"email"=>"********#gmail.ca"
),
),
),
"returnUrl" => "http://test.local/payments/confirm",
"cancelUrl" => "http://test.local/payments/cancel",
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
);
$response = $this->_paypalSend($createPacket,"Pay");
}
}
And here's the call:
$payment = new PaypalTest();
$payment->splitPay();
Quite simple, but something is not working. And I'm not really familiar with Curl so I thought you guys could help me
P.S: I'm in sandbox mode
Thanks
Carl
change CURLOPT_HEADER to CURLOPT_HTTPHEADER
Related
I need help to use the following code Paypal Adaptive Payment in WordPress Website.
I do not understand from where the CComponent class extend.
<?php
class PaypalTest extends CComponent{
public $api_user = "**********************";
public $api_pass = "***********";
public $api_sig = "**************************";
public $app_id = "APP-80W284485P519543T";
public $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
public $paypalUrl="https://www.paypal.com/webscr?cmd=_ap-payment&paykey=";
public $headers;
public function __construct(){
$this->headers = array(
"X-PAYPAL-SECURITY-USERID: ".$this->api_user,
"X-PAYPAL-SECURITY-PASSWORD: ".$this->api_pass,
"X-PAYPAL-SECURITY-SIGNATURE: ".$this->api_sig,
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ".$this->app_id,
);
}
public function getPaymentOptions($paykey){
}
public function setPaymentOptions(){
}
public function _paypalSend($data,$call){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->apiUrl.$call);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
$response = json_decode(curl_exec($ch),true);
return $response;
}
public function splitPay(){
// create the pay request
$createPacket = array(
"actionType" =>"PAY",
"currencyCode" => "USD",
"receiverList" => array(
"receiver" => array(
array(
"amount"=> "1.00",
"email"=>"********#hotmail.com"
),
array(
"amount"=> "2.00",
"email"=>"********#gmail.ca"
),
),
),
"returnUrl" => "http://test.local/payments/confirm",
"cancelUrl" => "http://test.local/payments/cancel",
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
);
$response = $this->_paypalSend($createPacket,"Pay");
}
}
?>
It looks like simple, but something I do not understand. And I'm not really familiar with Paypal Adaptive Payments. I'm in sandbox mode.
I am working on integrating PayPal's AdaptivePayment API but everytime I make a call I am getting the error "Internal server error. Please check the server logs for details" returned from the CURL call. I believe I have all the required headers. Has anyone else had this issue? My code is below:
$appID = "APP-80W284485P519543T";
$username = "***********";
$password = "***********";
$signature = "**********";
$endpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/";
$headers = array(
"X-PAYPAL-SECURITY-USERID: " . $username,
"X-PAYPAL-SECURITY-PASSWORD: ". $password,
"X-PAYPAL-SECURITY-SIGNATURE: ". $signature,
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ". $appID
);
$packet = array(
"actionType" => "PAY",
"currencyCode" => "USD",
"cancelUrl" => "cancel.html",
"returnUrl" => "success.html",
"receiverList" => array(
"receiver" => array(
array(
"amount" => "1.00",
"email" => "example#gmail.com",
"primary" => true
),
array(
"amount" => "0.50",
"email" => "example2#gmail.com",
"primary" => false
)
)
),
"requestEnvelope" => array(
"errorLanguage" => "en_US"
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint."PAY");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//turning off the server and peer verification(TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($packet));
$response = curl_exec($ch);
if (curl_errno($ch))
{
// moving to display page to display curl errors
echo curl_errno($ch);
echo curl_error($ch);
//Execute the Error handling module to display errors.
}
else
{
echo "RESPONSE";
header('Content-Type: application/json');
echo $response;
curl_close($ch);
}
Your endpoint URL is wrong, it should be:
$endpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay";
I'm looking for XMLRPC keywords to find out a list of users of a BUGZILLA project.
Here is my code, login works fine and im' able to use several keywords to find out what i need : Bug.search, Bug.fields.
public function loginBz($url,$login,$password,$getResult)
{
set_time_limit(0);
$URI = $url;
$xml_data = array(
'login' => $login,
'password' => $password,
'remember' => 1
);
$ch = curl_init();
$file_cookie = tempnam ("/tmp", "CURLCOOKIE");
$options = array(
//CURLOPT_VERBOSE => true,
CURLOPT_URL => $URI,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt_array($ch, $options);
$request = xmlrpc_encode_request("User.login", $xml_data);
// var_dump($request);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_COOKIEJAR, $file_cookie);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$server_output = curl_exec($ch); // Array( [id] => 1 ) for example
$response = xmlrpc_decode($server_output);
//print_r ($response);
if($getResult)
return $response;
else
return $ch;
}
public function getFieldsBz($product,$component,$ch){
$xml_data = array(
'product' => $product,
'component' => '$component'
);
$request = xmlrpc_encode_request("Bug.user", $xml_data); // create a request for filing bugs
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$server_output = curl_exec($ch); // Array( [id] => 1 ) for example
$response = xmlrpc_decode($server_output);
return $response;
}
I've been searching into BugZilla API but did not found what I need : List of Users for a product Bz.
Does anyone know which keyword I have to use in xmlrpc_encode_request(keyword,array_filter) ?
It would help :)
First there isn't a method called Bug.user, see https://www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/Bug.html for a complete list.
There is a method called User.get, see https://www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/User.html#get
There is a parameter called groups which may do what you want depending on how you setup Bugzilla security.
You can use https://xmlrpc.devzing.com/ to experiment or if you upgrade to Bugzilla 5.x you can use the new REST API. https://www.bugzilla.org/docs/5.0/en/html/api/Bugzilla/WebService/Server/REST.html
I have been recently trying to make an API request using PHP to PayPal to pay multiple accounts but so far I have no luck.
`
class PayPal
{
public $_headers = array();
public $_config = array();
public $_data = array();
public function __construct()
{
if (!in_array('curl', get_loaded_extensions()))
{
trigger_error("CURL extension is not installed or enabled", E_USER_ERROR);
}
}
public function update_headers(array $credentails)
{
$this->_headers = $credentails;
return $this;
}
public function update_config(array $config)
{
$this->_config = $config;
return $this;
}
public function pay($data, $call)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->get_url());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->_headers);
return curl_exec($ch);
}
public function split_pay()
{
// create the pay request
$this->_data = array(
"actionType" =>"PAY",
"currencyCode" => "USD",
"receiverList" => array(
"receiver" => array(
array(
"amount"=> "1.00",
"email"=>"******#gmail.com"
),
array(
"amount"=> "2.00",
"email"=>"*********.co.uk"
),
),
),
"returnUrl" => "http://test.local/payments/confirm",
"cancelUrl" => "http://test.local/payments/cancel",
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
);
return $this->pay($this->_data, "PAY");
}
private function get_url()
{
if (empty($this->_config))
{
trigger_error("You have not setup the config", E_USER_ERROR);
}
return $this->_config['url'];
}
public function call_headers()
{
if (empty($this->_headers))
{
trigger_error("You have not set any headers", E_USER_ERROR);
}
print_r($this->_headers);
}
}
?>`
This is a class file which I have created, it is very rough but its not working. Here is some more code.
`load->library('paypal');
$pp = new PayPal();
//Bring me the money!
//Headers for paypal
$headers = array(
"X-PAYPAL-SECURITY-USERID: ********",
"X-PAYPAL-SECURITY-PASSWORD: *********",
"X-PAYPAL-SECURITY-SIGNATURE: **********",
"X-PAYPAL-REQUEST-DATA-FORMAT: NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT: NV",
"X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T"
);
$config = array(
'url' => 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay',
'username' => '********',
'password' => '********',
'signature' => '********',
'app_id' => 'APP-80W284485P519543T',
);
$pp->update_headers($headers)->update_config($config);
print_r($pp->split_pay());
?>
`
I am being returned with this response.
responseEnvelope.timestamp=2014-04-22T06%3A15%3A49.821-07%3A00&responseEnvelope.ack=Failure&responseEnvelope.correlationId=b3d05fe547e22&responseEnvelope.build=10680030&error(0).errorId=580001&error(0).domain=PLATFORM&error(0).subdomain=Application&error(0).severity=Error&error(0).category=Application&error(0).message=Invalid+request%3A+%7B0%7D
Does anyone have any ideas why this might be
I am new to curl so I am using code found on the Paypal Developer blog and I am having a hard time getting it to work for me. Here is the code I am using
class paypal {
private $access_token;
private $token_type;
/**
* Constructor
*
* Handles oauth 2 bearer token fetch
* #link https://developer.paypal.com/webapps/developer/docs/api/#authentication--headers
*/
public function __construct(){
$postvals = "grant_type=client_credentials";
$uri = PAYMENT_URI . "v1/oauth2/token";
$auth_response = self::curl($uri, 'POST', $postvals, true);
$this->access_token = $auth_response['body']->access_token;
$this->token_type = $auth_response['body']->token_type;
}
/**
* cURL
*
* Handles GET / POST requests for auth requests
* #link http://php.net/manual/en/book.curl.php
*/
private function curl($url, $method = 'GET', $postvals = null, $auth = false){
$ch = curl_init($url);
//if we are sending request to obtain bearer token
if ($auth){
$headers = array("Accept: application/json", "Accept-Language: en_US");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, CLIENT_ID . ":" .CLIENT_SECRET);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
//if we are sending request with the bearer token for protected resources
} else {
$headers = array("Content-Type:application/json", "Authorization:{$this->token_type} {$this->access_token}");
}
$options = array(
CURLOPT_HEADER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true,
CURLOPT_TIMEOUT => 10
);
if ($method == 'POST'){
$options[CURLOPT_POSTFIELDS] = $postvals;
$options[CURLOPT_CUSTOMREQUEST] = $method;
}
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$header = substr($response, 0, curl_getinfo($ch,CURLINFO_HEADER_SIZE));
$body = json_decode(substr($response, curl_getinfo($ch,CURLINFO_HEADER_SIZE)));
curl_close($ch);
return array('header' => $header, 'body' => $body);
}
// Function for Processing Payment
function process_payment($request) {
$postvals = $request;
$uri = PAYMENT_URI . "v1/payments/payment";
return self::curl($uri, 'POST', $postvals);
}
}
if (isset($_SESSION['payment_type']) && ($_SESSION['payment_type'] == 'paypal')) { // User has chosen to pay with Paypal.
// Retrive Shopping cart contents
$r = mysqli_query($dbc, "CALL get_shopping_cart_contents('$uid')");
$request = array(
'intent' => 'sale',
'redirect_urls' => array(
'return_url' =>'http://store.example.com/final',
'cancel_url' =>'http://store.example.com/payment'
),
'payer' => array(
'payment_method' =>'paypal'
),
'transactions' => array(
'amount' => array(
'total' =>''.number_format($order_total,2).'',
'currency' =>'USD',
'details' => array(
'subtotal' =>''.number_format($subtotal,2).'',
'shipping' =>''.number_format($shipping,2).''
),
'item_list' => array(
)
),
'description' =>'Mike and Maureen Photography - Order ID #'.$order_id.''
)
);
while ($items = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$newitems = array(
'quantity' =>''.$items['quantity'].'',
'name' =>''.$items['name'].'',
'price' =>''.get_price($items['price'],$items['sales_price']).'',
'currency' =>'USD'
);
$request['transactions']['amount']['item_list']['items'][] = $newitems;
}
$request = json_encode($request);
process_payment($request);
}
I am good with php but this whole class, public/private stuff is throwing me off. Can I use this code without that or will it open me up to trouble? How do I run the process_payment function without it throwing an error. I am getting "Fatal error: Call to undefined function process_payment()"
Didnt I just define the function in the paypal class? I have read through the documentation on paypal and I cant get a grasp on what I am doing wrong. Any help would be great.
The function process_payment() is part of the paypal class. To call it, you will have to do one of the ways outlined here: https://stackoverflow.com/a/4216347/1715048