I want to create recurring profile using Direct Payment Method.
I have enabled Business Pro account in sandbox accounts like as shown below.
And here are the API Credentials.
And below is my source code that I am using to create a Recurring Profile.
$data = array(
'USER' => urlencode('tahir.jumpstart-facilitator_api1.nxvt.com'),
'PWD' => urlencode('BHVM3E9XSLAJP9PX'),
'SIGNATURE' => urlencode('AAYoJuE-6E-mj5oERynM8zN4s4OrAvfUS7h9g45hGPQmxWb5RJxdJEBp'),
'VERSION' => '69.0',
'METHOD' => urlencode('CreateRecurringPaymentsProfile'),
'PROFILESTARTDATE' => gmdate("Y-m-d\TH:i:s\Z"),
'DESC' => urlencode('RacquetClubMembership'),
'BILLINGPERIOD' => 'Month',
'BILLINGFREQUENCY' => 1,
'AMT' => 10,
'MAXFAILEDPAYMENTS' => 3,
'ACCT' => '4032030239913727',
'CREDITCARDTYPE' => 'VISA',
'CVV2' => '123',
'FIRSTNAME' => 'James',
'LASTNAME' => 'Smith',
'STREET' => 'FirstStreet',
'CITY' => 'SanJose',
'STATE' => 'CA',
'ZIP' => '95131',
'COUNTRYCODE' => 'US',
'CURRENCYCODE' => 'USD',
'EXPDATE' => '072021'
);
$fields_string = http_build_query($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields_string);
$response = curl_exec($curl);
echo '<pre>';
print_r($response);
die;
$err = curl_error($curl);
curl_close($curl);
But when I run above code it shows me below error message.
TIMESTAMP=2016%2d06%2d09T13%3a52%3a39Z&CORRELATIONID=77466c4ec86e5&ACK=Failure&VERSION=69%2e0&BUILD=22204133&L_ERRORCODE0=11586&L_SHORTMESSAGE0=DPRP is disabled&L_LONGMESSAGE0=DPRP is disabled for this merchant&L_SEVERITYCODE0=Error
I have searched all over the internet and only thing that they suggest is to enable Business Pro account that is already enabled and you can clearly see this in above screenshot.
I am now lost, would really appreciate if someone can tell me if there is some issue with above code or I am missing something?
Many Thanks!
Please submit a PayPal MTS ticket to help you grant the DPRP access.
Related
I am using below curl code which is based on #unificationengine API to access facebook graph api and post message on facebook:
$post_msg = json_encode(
array(
'message' =>
array(
'receivers' =>
array(
array(
'name' => 'Me',
'address' => 'https://graph.facebook.com/v2.5/7/feed?access_token='.$request->access_token,
'Connector' => 'facebook'
),
),
'sender' =>
array('address' => 'sender address'),
'subject' => 'Hello',
'parts' =>
array(
array(
'id' => '1',
'contentType' => 'text/plain',
'data' => 'Hi welcome to UE',
'size' => 100,
'sort' => 0
),
),
),
)
);
$ch = curl_init('https://apiv2.unificationengine.com/v2/message/send');
curl_setopt($ch, CURLOPT_USERPWD, "ab33333222b-acb5-49a6-a766-80d991daff41:43433232-33cb-49f0-3333-3fe6c46acb5f");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_msg);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
// do anything you want with your response
var_dump($response);
return ['label' =>$response];
I am getting invalid access token error with code 498. I referred various posts on this topic but couldn't figure out that what is missing.
How to check validity of facebook access token.
Referenced these questions:
SO question 1
SO question 2
The facebook access tokens have a lifetime of about two hours. For longer lived web apps, especially server side, need to generate long lived tokens. Long lived tokens generally lasts about 60 days.
UE has a capability to refresh facebook tokens. After adding connection using "apiv2.unificationengine.com/v2/connection/add"; api call, then you should call "apiv2.unificationengine.com/v2/connection/refresh"; api to make the short lived token to long lived.
<?
//Authentication rest API magento2.Please change url accordingly your url
$adminUrl='http://localhost/magento/index.php/rest/V1/integration/admin/token';
$ch = curl_init();
$data = array("username" => "", "password" => "");
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type=> application/json',
'Content-Length=> ' . strlen($data_string))
);
$token = curl_exec($ch);
$token= json_decode($token);
//Use above token into header
$headers = array('Authorization=> Bearer $token');
$requestUrl='http://127.0.0.1/magento/index.php/rest/V1/products';
//Please note 24-MB01 is sku
$ch = curl_init();
$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$post ='{
"product": {
"sku": "MY_SKU",
"name": "My Product",
"attributeSetId": "4",
"price": 20,
"status": 1,
"visibility": 4,
"typeId": "virtual",
"weight": 0,
"extensionAttributes": {
"stockItem": {
"stockId": 1,
"qty": 20,
"isInStock": true,
"isQtyDecimal": false,
"useConfigMinQty": true,
"minQty": 0,
"useConfigMinSaleQty": 0,
"minSaleQty": 0,
"useConfigMaxSaleQty": true,
"maxSaleQty": 0,
"useConfigBackorders": false,
"backorders": 0,
"useConfigNotifyStockQty": true,
"notifyStockQty": 20,
"useConfigQtyIncrements": false,
"qtyIncrements": 0,
"useConfigEnableQtyInc": false,
"enableQtyIncrements": false,
"useConfigManageStock": true,
"manageStock": true,
"lowStockDate": "string",
"isDecimalDivided": true,
"stockStatusChangedAuto": 0,
"extensionAttributes": {}
}
},
"options": [],
"tierPrices": [],
"customAttributes": [
]
},
"saveOptions": true
}';
$options = array(
CURLOPT_URL=>$toURL,
CURLOPT_HTTPHEADER=>array(
'Content-Type: application/json',
'Content-Length: ' . strlen($post)),
CURLOPT_VERBOSE=>0,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible;)",
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>$post,
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$result= json_decode($result);
print_r($result);
?>
the above code can not add product,i have try many method,still can not add product by rest api , anyone know how to add product by rest api?please help,Thanks.
the above code can not add product,i have try many method,still can not add product by rest api , anyone know how to add product by rest api?please help,Thanks.
<?
$url = domainname;
$token_url=$url."rest/V1/integration/admin/token";
$product_url=$url. "rest/V1/products";
$ch = curl_init();
$data = array("username" => username, "password" => password);
$data_string = json_encode($data);
$ch = curl_init($token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);
$adminToken= json_decode($token);
$sampleProductData = array(
'sku' => $isbn13,
'name' => $name,
'visibility' => 4,
'type_id' => 'simple',
'price' => $price,
'status' => 1,
'attribute_set_id' => 4,
'weight' => $product_weight,
'extension_attributes' => array(
"stock_item"=>array(
'qty' => $inventory_stock,'is_in_stock' => 1,'manage_stock' => 1,'use_config_manage_stock' => 1,'min_qty' => 0,'use_config_min_qty' => 1,'min_sale_qty' => 1,'use_config_min_sale_qty' => 1,'max_sale_qty ' => 10,'use_config_max_sale_qty' => 1,'is_qty_decimal' => 0,'backorders' => 0,'use_config_backorders' => 1,'notify_stock_qty' => 1,'use_config_notify_stock_qty' => 1
),
),
'custom_attributes' => array(
array( 'attribute_code' => 'category_ids', 'value' => ["43"] ),
array( 'attribute_code' => 'description', 'value' => $description ),
array( 'attribute_code' => 'short_description', 'value' => $short_description ),
array( 'attribute_code' => 'meta_title', 'value' => $meta_title),
array( 'attribute_code' => 'meta_keyword', 'value' => $meta_keyword),
array( 'attribute_code' => 'meta_description', 'value' => $meta_description),
),
);
$productData = json_encode(array('product' => $sampleProductData));
$setHaders = array('Content-Type:application/json','Authorization:Bearer '.$adminToken);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $product_url);
curl_setopt($ch,CURLOPT_POSTFIELDS, $productData);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $setHaders);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
This is for product upload on magento 2 thorugh rest api Description = only copy code and put code in one php file and chagne domainname to (https://--------.com/) and after you create user and roles in magento 2(https://www.youtube.com/watch?v=hMN-ZoeODlQ) and put that username in username field in this code and password also and run this code replace with all dynamic variable.(like $isbn13,$name...etc with your product detail ) see product is create or update in magento 2
$adminUrl = 'http://localhost/magento2.1.2/index.php/rest/V1/integration/admin/token/';
$ch = curl_init();
$data = array("username" => "", "password" => "");
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type=> application/json'));
$token = curl_exec($ch);
$token = json_decode($token);
use your magento admin username and password and get the token id.
Pass the $post json variable to this cURL call.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost/magento2.1.2/index.php/rest/V1/products",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $post,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer $token",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
In request URL $requestUrl='http://127.0.0.1/magento/index.php/rest/V1/products' change "products" to product and try.
I have code GetRecurringPaymentsProfileDetails...where it wrong?
//--------------------------------------------------------------------------------------------------------------------------------------------------------
public function callNVP($profileId) {
$api_request = '&USER=' . urlencode('bestlifeXXXXX.gmaill.com')
. '&PWD=' . urlencode('136XXXXXXX')
. '&SIGNATURE=' . urlencode('XXXXXXXXJJJ4qi4-ASVptjmiE8Sqp4tXXXXXXCa')
. '&VERSION=76.0'
. '&METHOD =GetRecurringPaymentsProfileDetails'
. '&PROFILEID=' . urlencode($profileId);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp'); // For live transactions, change to 'https://api-3t.paypal.com/nvp'
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//curl_setopt($ch, CURLOPT_HEADER, FALSE);
// Uncomment these to turn off server and peer verification
//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);
// Set the API parameters for this transaction
//curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $api_request);
// Request response from PayPal
$response = curl_exec($ch);
// If no response was received from PayPal there is no point parsing the response
if (!$response)
die('Calling PayPal to change_subscription_status failed: ' . curl_error($ch) . '(' . curl_errno($ch) . ')');
curl_close($ch);
// An associative array is more usable than a parameter string
parse_str($response, $parsed_response);
return $parsed_response;
}
But it's return result:
Array
(
[0] => Array
(
[TIMESTAMP] => 2015-12-10T03:49:09Z
[CORRELATIONID] => cb2489449e84c
[ACK] => Failure
[L_ERRORCODE0] => 10001
[L_SHORTMESSAGE0] => Internal Error
[L_LONGMESSAGE0] => Timeout processing request
)
)
What I want is:
(
[PROFILEID] => I-CL7Kxxx
[STATUS] => Active
[AUTOBILLOUTAMT] => AddToNextBilling
[DESC] => xxx
[MAXFAILEDPAYMENTS] => 2
[SUBSCRIBERNAME] => Dan
[PROFILESTARTDATE] => 2013-05-15T07:00:00Z
[PROFILEREFERENCE] => 31571
[NEXTBILLINGDATE] => 2013-05-16T10:00:00Z
[NUMCYCLESCOMPLETED] => 1
[NUMCYCLESREMAINING] => 18446744073709551615
[OUTSTANDINGBALANCE] => 0.00
[FAILEDPAYMENTCOUNT] => 0
[LASTPAYMENTDATE] => 2013-05-15T14:52:04Z
[LASTPAYMENTAMT] => 0.10
[TRIALAMTPAID] => 0.00
[REGULARAMTPAID] => 0.10
[AGGREGATEAMT] => 0.10
[AGGREGATEOPTIONALAMT] => 0.00
[FINALPAYMENTDUEDATE] => 1970-01-01T00:00:00Z
[TIMESTAMP] => 2013-05-15T14:55:58Z
[CORRELATIONID] => 225681xxx
[ACK] => Success
[VERSION] => 64
[BUILD] => 5908853
[SHIPTOSTREET] => xxx
[SHIPTOCITY] => xxx
[SHIPTOSTATE] => CA
[SHIPTOZIP] => xxx
[SHIPTOCOUNTRYCODE] => US
[SHIPTOCOUNTRY] => US
[SHIPTOCOUNTRYNAME] => United States
[SHIPADDRESSOWNER] => PayPal
[SHIPADDRESSSTATUS] => Unconfirmed
[BILLINGPERIOD] => Day
[BILLINGFREQUENCY] => 1
[TOTALBILLINGCYCLES] => 0
[CURRENCYCODE] => USD
[AMT] => 0.10
[SHIPPINGAMT] => 0.00
[TAXAMT] => 0.00
[REGULARBILLINGPERIOD] => Day
[REGULARBILLINGFREQUENCY] => 1
[REGULARTOTALBILLINGCYCLES] => 0
[REGULARCURRENCYCODE] => USD
[REGULARAMT] => 0.10
[REGULARSHIPPINGAMT] => 0.00
[REGULARTAXAMT] => 0.00
)
Who can help me? Please...
You've got this:
'&METHOD =GetRecurringPaymentsProfileDetails'
I think that space in there is causing an invalid request. Try this:
'&METHOD=GetRecurringPaymentsProfileDetails'
Its definitely because of your API request(I am guessing its Incorrect Profile ID)
Can you try(click) the following link in your browser(substitute API credentials,Profile ID)
https://api-3t.sandbox.paypal.com/nvp?&user=xxxxxxxxxx&pwd=xxxxxxxxxx&signature=xxxxxxxxxx&VERSION=109.0&METHOD=GetRecurringPaymentsProfileDetails&PROFILEID=I-XXXXXXXXXXXX
And see what response you get.
I get Internal Error, when I used "I-XXXXXXXXXXXX" as profile id.
following is my code to get result of account module from sugarcrm using rest api
i want to fetch all records including deleted one but it only throws either deleted or non-deleted accounts. but i need both type of record using one request please help
$url = "http://localhost/SugarCRM/service/v4/rest.php";
$username = "admin";
$password = "1234";
//function to make cURL request
function call($method, $parameters, $url)
{
ob_start();
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, $url);
curl_setopt($curl_request, CURLOPT_POST, 1);
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl_request, CURLOPT_HEADER, 1);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
$jsonEncodedData = json_encode($parameters);
$post = array(
"method" => $method,
"input_type" => "JSON",
"response_type" => "JSON",
"rest_data" => $jsonEncodedData
);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl_request);
curl_close($curl_request);
$result = explode("\r\n\r\n", $result, 2);
$response = json_decode($result[1]);
ob_end_flush();
return $response;
}
//login --------------------------------------------
$login_parameters = array(
"user_auth"=>array(
"user_name"=>$username,
"password"=>md5($password),
"version"=>"1"
),
"application_name"=>"RestTest",
"name_value_list"=>array(),
);
$login_result = call("login", $login_parameters, $url);
/*
echo "<pre>";
print_r($login_result);
echo "</pre>";
*/
//get session id
$session_id = $login_result->id;
$current_date='2014-06-30';//date('Y-m-d');
//get list of records --------------------------------
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//The SQL WHERE clause without the word "where".
'query' => "(accounts.deleted='0' or accounts.deleted='1') AND DATE(accounts.date_entered)='$current_date'",
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => '0',
//Optional. A list of fields to include in the results.
'select_fields' => array(
'id',
'name',
'billing_address_street',
'billing_address_city',
'billing_address_postalcode',
'billing_address_country',
'shipping_address_street',
'shipping_address_city',
'shipping_address_postalcode',
'shipping_address_country',
'website',
'deleted',
),
/*
A list of link names and the fields to be returned for each link name.
Example: 'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address')))
*/
'link_name_to_fields_array' => array(
),
//The maximum number of results to return.
'max_results' => '',
//To exclude deleted records
//'deleted' => false,
//If only records marked as favorites should be returned.
//'Favorites' => false,
);
$get_entry_list_result = call('get_entry_list', $get_entry_list_parameters, $url);
echo '<pre>';
print_r($get_entry_list_result);
echo '</pre>';
I would suggest not using the query section, just uncomment and set 'deleted' => true, I am using version 4_1 of the API and that works for me.
It's likely that the default is false and your query is being overridden by it.
Hope that helps
Sure it's just something I'm missing. Fairly new to the Paypal API, especially the classic one! Basically, I'm using the following code to generate a subscription to my site at £2.50 per month. I can get the subscription to appear in the Recurring Payments Dashboard on Paypal Sandbox, but it doesn't change the balance and seems to be missing things to do with the initial payment. I tried INITAMT too, which filled in some fields, but still doesn't change the Sandbox balance of my account. Any ideas guys? Here's the code:
<?php
// Set PayPal API version and credentials.
$api_version = '85.0';
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
$api_username = 'MY_SANDBOX_USERNAME';
$api_password = 'MY_SANDBOX_PASSWORD';
$api_signature = 'MY_SANDBOX_SIGNATURE';
$startdate = gmdate('Y-m-d')."T00:00:00Z";
$request_params = array
(
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => $api_version,
'METHOD' => 'CreateRecurringPaymentsProfile',
'PROFILESTARTDATE' => $startdate,
'DESC' => 'Membership',
'BILLINGPERIOD' => 'Month',
'BILLINGFREQUENCY' => '1',
'TOTALBILLINGCYCLES' => '0',
'AMT' => '2.50',
'MAXFAILEDPAYMENTS' => '12',
'ACCT' => '4641631486853053',
'CREDITCARDTYPE' => 'VISA',
'CVV2' => '123',
'FIRSTNAME' => 'James',
'LASTNAME' => 'Smith',
'STREET' => 'FirstStreet',
'CITY' => 'London',
'STATE' => 'G London',
'ZIP' => 'W2 1NE',
'COUNTRYCODE' => 'GB',
'CURRENCYCODE' => 'GBP',
'EXPDATE' => '052015'
);
// Loop through $request_params array to generate the NVP string.
$nvp_string = '';
foreach($request_params as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
// Send NVP string to PayPal and store response
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
$result = curl_exec($curl);
curl_close($curl);
$nvp_response_array = parse_str($result);
print_r($result);
?>
I took your code and used my own sandbox credentials. It seems to have worked just fine for me.
It came through as unclaimed since my account is USD, but you can see it did work just fine. Are you sure you're checking the correct sandbox account after you run it yourself?