Error #520009 - Account is restricted - php

I get a 520009 error (Account xx#xx.com is restricted) when trying to make a parallel payment. My code worked fine using the sandbox but I switched to the live endpoint and it began failing. The account in question is a valid paypal account and I am using "feespayer=SENDER". Am I missing something? Shouldn't the pay call go through even if the payee is a basic account? Why would this occur?
Here is my code for reference
function deposit($config) {
try {
if (isset($config['return_url']))
$this->return_url = $config['return_url'];
else
return 'Return URL should be set';
if (isset($config['return_url']))
$this->cancel_url = $config['cancel_url'];
else
return 'Cancel URL should be set';
if (isset($config['email']))
$this->sender_email = $config['email'];
else
return 'Email should be defined';
if (isset($config['amount']))
$this->amount = $config['amount'];
else
return 'Amount should be defined';
$returnURL = $this->return_url;
$cancelURL = $this->cancel_url;
$currencyCode = 'USD';
$memo = 'Deposit to ' . $this->ci->config->item('site_name');
$feesPayer = 'SENDER';
$payRequest = new PayRequest();
$payRequest->actionType = "PAY";
$payRequest->cancelUrl = $cancelURL;
$payRequest->returnUrl = $returnURL;
$payRequest->clientDetails = new ClientDetailsType();
$payRequest->clientDetails->applicationId = $this->ci->config->item('application_id');
$payRequest->clientDetails->deviceId = $this->ci->config->item('device_id');
$payRequest->clientDetails->ipAddress = $this->ci->input->ip_address();
$payRequest->currencyCode = $currencyCode;
//$payRequest->senderEmail = $this->sender_email;
$payRequest->requestEnvelope = new RequestEnvelope();
$payRequest->requestEnvelope->errorLanguage = "en_US";
$receivers = array();
$receiver = new receiver();
$receiver->email = $this->ci->config->item('moneyfan_account');
$receiver->amount = $this->amount;
$receiver->primary = 'false';
$receivers[] = $receiver;
$payRequest->receiverList = $receivers;
$payRequest->feesPayer = $feesPayer;
$payRequest->memo = $memo;
$ap = new AdaptivePayments();
$response = $ap->Pay($payRequest);
if (strtoupper($ap->isSuccess) == 'FAILURE') {
$this->ci->session->set_userdata('FAULTMSG', $ap->getLastError());
return json_encode(array('status' => 'false', 'msg' => $ap->getLastError()->error->errorId .' : '. $ap->getLastError()->error->message));
//redirect(site_url('home/api_error'));
} else {
$this->ci->session->set_userdata('payKey', $response->payKey);
if ($response->paymentExecStatus == "COMPLETED") {
redirect($returnURL);
} else {
$token = $response->payKey;
$payPalURL = PAYPAL_REDIRECT_URL . '_ap-payment&paykey=' . $token;
return json_encode(array('status' => 'true', 'msg' => $payPalURL));
//header("Location: " . $payPalURL);
}
}
} catch (Exception $ex) {
$fault = new FaultMessage();
$errorData = new ErrorData();
$errorData->errorId = $ex->getFile();
$errorData->message = $ex->getMessage();
$fault->error = $errorData;
$this->ci->session->set_userdata('FAULTMSG', $fault);
redirect(site_url('home/api_error'));
}
}

No! You cannot do that with a basic account.
For API to work you need to have a VERIFIED Business Account.
In their API it says:
NOTE:
The application owner must have a PayPal Business account.

There are two sources of reference for the PayPal API:
cms.paypal.com pages like the one referenced by Mihai Iorga, and
www.x.com pages like this one:
https://www.x.com/developers/paypal/documentation-tools/going-live-with-your-application
On x.com, it says you must have a verified business account, even though it is unclear from cms.paypal.com that this is the case.

Related

how to use dreamscape api in nodejs for check domain name

I have already work this in php. Here is my working code:
$request = array(
'DomainNames' => $domain_names
);
$response = dreamScapeAPI('DomainCheck', $request);
$available = false;
$alt_domains = array(); // Alternative to user's expected domain names
if (!is_soap_fault($response)) {
// Successfully checked the availability of the domains
if (isset($response->APIResponse->AvailabilityList)) {
$availabilityList = $response->APIResponse->AvailabilityList;
foreach ($availabilityList as $list) {
if ($list->Available){
if ($domain == $list->Item) {
$available = true; // user prefered domain found
}
else {
$alt_domains[] = $list->Item;
}
}
}
}
else {
$error = $response->APIResponse->Errors;
foreach ($error as $e) {
$api_error = $e->Message;
//echo $e->Item . ' - ' . $e->Message . '<br />';
}
}
}
function dreamScapeAPI($method, $data = null) {
$reseller_api_soap_client = "";
$soap_location = 'http://soap.secureapi.com.au/API-2.1';
$wsdl_location = 'http://soap.secureapi.com.au/wsdl/API-2.1.wsdl';
$authenticate = array();
$authenticate['AuthenticateRequest'] = array();
$authenticate['AuthenticateRequest']['ResellerID'] = '**';
$authenticate['AuthenticateRequest']['APIKey'] = '**';
//convert $authenticate to a soap variable
$authenticate['AuthenticateRequest'] = new SoapVar($authenticate['AuthenticateRequest'], SOAP_ENC_OBJECT);
$authenticate = new SoapVar($authenticate, SOAP_ENC_OBJECT);
$header = new SoapHeader($soap_location, 'Authenticate', $authenticate, false);
$reseller_api_soap_client = new SoapClient($wsdl_location, array('soap_version' => SOAP_1_2, 'cache_wsdl' => WSDL_CACHE_NONE));
$reseller_api_soap_client->__setSoapHeaders(array($header));
$prepared_data = $data != null ? array($data) : array();
try {
$response = $reseller_api_soap_client->__soapCall($method, $prepared_data);
} catch (SoapFault $response) { }
return $response;
}
I tried with this : https://github.com/dan-power/node-dreamscape
But domain search can not work properly. Mainly, I want it on nodejs using nodejs dreamscape api but this method is not available on nodejs.
Here is my working demo: click here

square payment form php check customer exists in directory and make payment

Am new to Square Payment Form using PHP and trying to do following steps
Check If customer Exists in Directory
If Customer Does not exist - create new customer and collect CUSTOMER_ID
MAKE PAYMENT & get Payment ID
Couple of time this script worked by started getting Maximum execution time of 30 seconds exceeded AND created multiple customer entries in directory and payment failed
PS : am using GOTO to loop and ENV file for credentials
Any help will be appreciated in advance
print_r($_POST);
$booknow = $_POST;
require 'vendor/autoload.php';
use Dotenv\Dotenv;
use Square\Models\Money;
use Square\Models\CreatePaymentRequest;
use Square\Exceptions\ApiException;
use Square\SquareClient;
use Square\Environment;
use SquareConnect\ApiClient;
use Square\Models\CreateCustomerRequest;
$idem = UUID::v4();
$sname = explode(' ', $_POST["cname"]);
$sname0 = $sname[0];
$sname1 = $sname[1];
$cphone = $_POST["cphone"];
//$cphone = '9848848450';
$cemailid = $_POST["cemailid"];
$ifare = ($_POST["ifare"] * 100);
$xnote = $_POST["note"];
//echo '<br><br>fare : ' . $ifare . '<br><br>';
$dotenv = Dotenv::create(__DIR__);
$dotenv->load();
$upper_case_environment = strtoupper(getenv('ENVIRONMENT'));
$access_token = getenv($upper_case_environment.'_ACCESS_TOKEN');
//print_r($access_token);
//echo '<br><br><br>';
$client = new SquareClient([
'accessToken' => $access_token,
'environment' => getenv('ENVIRONMENT')
]);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
error_log('Received a non-POST request');
echo 'Request not allowed';
http_response_code(405);
return;
}
$nonce = $_POST['nonce'];
if (is_null($nonce)) {
echo 'Invalid card data';
http_response_code(422);
return;
}
searchCustomers: ///search customers
$phone_number = new \Square\Models\CustomerTextFilter();
$phone_number->setFuzzy($cphone);
$filter = new \Square\Models\CustomerFilter();
$filter->setPhoneNumber($phone_number);
$query = new \Square\Models\CustomerQuery();
$query->setFilter($filter);
$body = new \Square\Models\SearchCustomersRequest();
$body->setQuery($query);
$api_response = $client->getCustomersApi()->searchCustomers($body);
if ($api_response->isSuccess()) {
$rmn = $api_response->getBody();
$stx = json_decode($rmn,true);
echo '<br><br>';
echo '# of arrays : ' . count($stx);
if(count($stx) != 0){
//echo '<br><br>';
$cust_id = $stx["customers"][0]["id"];
//echo "Customer ID : " . $cust_id;
goto makePayment;
//goto end;
} else {
//echo 'user do not exists';
/// new customer - start
$body1 = new \Square\Models\CreateCustomerRequest();
$body1->setIdempotencyKey($idem);
$body1->setGivenName($sname0);
$body1->setFamilyName($sname1);
$body1->setEmailAddress($cemailid);
$body1->setPhoneNumber($cphone);
$api_response = $client->getCustomersApi()->createCustomer($body1);
if ($api_response->isSuccess()) {
$result = $api_response->getResult();
goto searchCustomers;
} else {
$errors = $api_response->getErrors();
}
/// new customer - end
}
} else {
echo '<br><br>sorry not found!<bR><br>';
}
goto end;
makePayment:
$amount_money = new \Square\Models\Money();
$amount_money->setAmount($ifare);
$amount_money->setCurrency('USD');
$body = new \Square\Models\CreatePaymentRequest(
'cnon:card-nonce-ok',
$idem,
$amount_money
);
$body->setCustomerId($cust_id);
$body->setNote($xnote);
$api_response = $client->getPaymentsApi()->createPayment($body);
if ($api_response->isSuccess()) {
$result = $api_response->getResult();
$srt = json_encode($result);
echo '<br><br>';
echo "PAYEMNT SUCCESSUFLL <BR><br><br>";
//print_r($srt);
goto end;
} else {
$errors = $api_response->getErrors();
echo 'payment FAILEDDDDDDDDDD';
}
goto end;
end:

PHP create User in moodle via Webservice

I want so connect an external website with a moodle-system. I've already set up the webService and created a token to get access.
I've followed http://www.rumours.co.nz/manuals/using_moodle_web_services.htm set up but in contrast i wanted to realise the connection via REST as in https://github.com/moodlehq/sample-ws-clients/find/master
My approach is to have a moodle class which will handle the data exchange. In first place i just wanted to try to create some new hard coded Users via the webService but it fails with the Moodle-Response:
"invalidrecord Can not find data record in database table external_functions. "
Which seems to me as if i the call was successfully but moodle has a problem to find the "core_user_create_users" function. I've checked the local moodle Database and in the table external_functions is an entry for "core_user_create_users" so i'm kind of confused where moodle doesn't know what to do.
Thats my class:
require_once (DOCUMENT_ROOT.'/tcm/api/moodle/curl.php');
class Moodle {
private $token;
private $domainName; // 'local.moodle.dev';
private $serverUrl;
public function __construct($token, $domainName) {
$this->token = $token;
$this->domainName = $domainName;
$this->serverUrl = $this->domainName . '/webservice/rest/server.php' . '?wstoken=' . $this->token;
echo "initialize Service: $this->serverUrl </br>";
}
public function createUser() {
$functionName = 'core_user_create_users';
/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION
$user1 = new stdClass();
$user1->username = 'testusername1';
$user1->password = 'testpassword1';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = 'testidnumber1';
$user1->lang = 'en';
$user1->theme = 'standard';
$user1->timezone = '-12.5';
$user1->mailformat = 0;
$user1->description = 'Hello World!';
$user1->city = 'testcity1';
$user1->country = 'au';
$preferencename1 = 'preference1';
$preferencename2 = 'preference2';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'preferencevalue1'),
array('type' => $preferencename2, 'value' => 'preferencevalue2'));
$user2 = new stdClass();
$user2->username = 'testusername2';
$user2->password = 'testpassword2';
$user2->firstname = 'testfirstname2';
$user2->lastname = 'testlastname2';
$user2->email = 'testemail2#moodle.com';
$user2->timezone = 'Pacific/Port_Moresby';
$users = array($user1, $user2);
$params = array('users' => $users);
/// REST CALL
$serverurl = $this->serverUrl . '&wsfunction=' . $functionName;
require_once (DOCUMENT_ROOT.'/tcm/api/moodle/curl.php');
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = "json";
$resp = $curl->post($serverurl . $restformat, $params);
//print_r($resp);
echo '</br>*************Server Response*************</br>';
var_dump($resp);
}
}
I'm using the curl class from the same github-project which i posted above - moodle is linkng to it in their Documentation..
docs.moodle.org/dev/Creating_a_web_service_client
The entry point of my call is hardcoded right now:
<?php
include_once (DOCUMENT_ROOT.'/tcm/api/moodle/moodle.php');
//entry point of code
if (isset($_POST)){
//token and domain would be in $_POST
$bla = new Moodle('0b5a1e98061c5f7fb70fc3b42af6bfc4', 'local.moodle.dev');
$bla->createUser();
}
Does anyone know how to solve the "invalidrecord Can not find data record in database table external_functions" error or has a different approach/suggestion how i can create my users remotely??
Thanks in advance
I got it finally working with the following code:
class Moodle {
private $token; //'0b5a1e98061c5f7fb70fc3b42af6bfc4';
private $domainName; // 'http://local.moodle.dev';
private $serverUrl;
public $error;
public function __construct($token, $domainName) {
$this->token = $token;
$this->domainName = $domainName;
$this->serverUrl = $this->domainName . '/webservice/rest/server.php' . '?wstoken=' . $this->token;
echo "initialize Service: $this->serverUrl </br>";
}
public function createUser() {
$functionName = 'core_user_create_users';
$user1 = new stdClass();
$user1->username = 'testusername1';
$user1->password = 'Uk3#0d5w';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = '';
$user1->lang = 'en';
$user1->timezone = 'Australia/Sydney';
$user1->mailformat = 0;
$user1->description = '';
$user1->city = '';
$user1->country = 'AU'; //list of abrevations is in yourmoodle/lang/en/countries
$preferencename1 = 'auth_forcepasswordchange';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'true')
);
$users = array($user1);
$params = array('users' => $users);
/// REST CALL
$restformat = "json";
$serverurl = $this->serverUrl . '&wsfunction=' . $functionName. '&moodlewsrestformat=' . $restformat;
require_once (DOCUMENT_ROOT . '/tcm/api/moodle/curl.php');
$curl = new curl();
$resp = $curl->post($serverurl, $params);
echo '</br>************************** Server Response createUser()**************************</br></br>';
echo $serverurl . '</br></br>';
var_dump($resp);
}
}
Info:
For all moodle beginners.. Activating the moodle Debug messages helps a bit. You'll receive an additional error information in the response returned form the server.
Moodle -> Site Administration -> Development -> Debugging -> Debug Messages
Select: DEVELOPER:extra Moodle debug messages for developers

Session data changed in php

This is my code
class WcfClient {
public $wcfClient = null;
public $user = null;
public function __construct(){
if(isset($_SESSION['APIClient']) && $_SESSION['APIClient'] != null){
$this->wcfClient = $_SESSION['APIClient'];
}
}
public function __destruct(){
}
// Authanticate
private function Authenticate(){
global $_sogh_soapUrl, $_isDebug, $_sogh_header;
$wcargs = array();
$consumerAuthTicket = null;
if($this->wcfClient == null){
$args = array(
'clubname'=>'Wellness Institute at Seven Oaks',
'consumerName'=>'api',
'consumerPassword'=>'api'
);
try{
$wcargs = array(
'soap_version'=>SOAP_1_2
);
if($_isDebug){
$wcargs = array(
'soap_version'=>SOAP_1_2,
'proxy_host'=>"192.168.0.1",
'proxy_port'=>8080
);
}
// Connect to the API with soapclient
$soapAPIClient = new SoapClient($_sogh_soapUrl, $wcargs);
$response = $soapAPIClient->AuthenticateClubConsumer($args);
if(isset($response->AuthenticateClubConsumerResult)){
if(isset($response->AuthenticateClubConsumerResult->IsException) && $response->AuthenticateClubConsumerResult->IsException == true){
// some error occur
$this->wcfClient = null;
$_SESSION['APIClient'] = $this->wcfClient;
} else{
// set consumer ticket
$consumerAuthTicket = $response->AuthenticateClubConsumerResult->Value->AuthTicket;
// $loginData = $responseCode->ReturnValueOfConsumerLoginData;
$headers = array();
$headers[] = new SoapHeader($_sogh_header, "ConsumerAuthTicket", $consumerAuthTicket);
$soapAPIClient->__setSoapHeaders($headers);
// add to session
$this->wcfClient = $soapAPIClient;
$_SESSION['APIClient'] = $this->wcfClient;
}
}
} catch(SoapFault $fault){
$this->error('Fault: ' . $fault->faultcode . ' - ' . $fault->faultstring);
} catch(Exception $e){
$this->error('Error: ' . $e->getMessage());
}
}
return $this->wcfClient;
}
I store the soap client object in $_SESSION['APIClient'], but second times when run some data has been changed in session, I am use this class in drupal 7, I want to save the time using session, because authenticating takes long time.
Please help
Thank in advance

Prestashop payment module

I am currently writing a Prestashop Payment module which uses the Paypal Adaptive Payments SDK.
When I try to install my module, I get the following error:
[PrestaShop] Fatal error in module Configuration:
Cannot redeclare class Configuration
here is my code.
the paypal sdk is installed correctly and working.
config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>MyPayments</name>
<displayName><![CDATA[My module]]></displayName>
<version><![CDATA[1.0]]></version>
<description><![CDATA[Description of my module.]]></description>
<author></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall>Are you sure you want to uninstall? You will lose all your settings!</confirmUninstall>
<is_configurable>0</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>
mypayments.php
<?php
if (!defined('_PS_VERSION_'))
exit;
//include paypal adaptive payments sdk lib
require(_PS_MODULE_DIR_.'/mypayments/samples/PPBootStrap.php');
class MyPayments extends PaymentModule {
public function __construct() {
$this->name = 'mypayments';
$this->tab = 'payments_gateways';
$this->version = '0.1';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
$this->bootstrap = true;
parent::__construct();
#$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Adaptive Payments');
$this->description = $this->l('Paypal Adaptive Payments');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get('MYMODULE_NAME'))
$this->warning = $this->l('No name provided');
}
public function install() {
if (!parent::install()
OR !$this->registerHook('payment')
OR !Configuration::updateValue('MYMODULE_NAME', 'My Payments')
)
return false;
return true;
}
public function uninstall() {
if (!parent::uninstall() ||
!Configuration::deleteByName('MYMODULE_NAME')
)
return false;
return true;
}
//output the current payment method to the choice list of available methods on the checkout pages
function hookPayment($params){
if(!$this->active) return;
global $smarty;
//checks if all products in cart are valid
foreach ($params['cart']->getProducts() AS $product)
if (Validate::isUnsignedInt(ProductDownload::getIdFromIdProduct(intval($product['id_product']))))
return false;
//assign smarty paths
$smarty->assign(array(
'this_path' => $this->_path,
'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' :'http://').htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/'.$this->name.'/'
));
//return the template file to render the payment option
return $this->display(__FILE__, 'payment.tpl');
}
public function paypalPayCall($Email1, $Email2, $totalAmount){
$Email3;
$Payment1 = $totalAmount/2;
$Payment2 = $totalAmount/4;
$Payment3 = $totalAmount/4;
$payRequest = new PayRequest();
$receiver = array();
$receiver[0] = new Receiver();
$receiver[0]->amount = $Payment1;
$receiver[0]->email = $Email1;
$receiver[0]->primary = "true";
$receiver[1] = new Receiver();
$receiver[1]->amount = $Payment2;
$receiver[1]->email = $Email2;
$receiver[2] = new Receiver();
$receiver[2]->amount = $Payment3;
$receiver[2]->email = $Email3;
$receiverList = new ReceiverList($receiver);
$payRequest->receiverList = $receiverList;
$requestEnvelope = new RequestEnvelope("en_US");
$payRequest->requestEnvelope = $requestEnvelope;
$payRequest->actionType = "PAY";
$payRequest->cancelUrl = "http://www.google.at/";
$payRequest->returnUrl = dirname(__FILE__)."validation.php";
$payRequest->currencyCode = "EUR";
//CONFIGURATION - now sandbox
$sdkConfig = array(
"mode" => "sandbox",
"acct1.UserName" => "xxx",
"acct1.Password" => "xxx",
"acct1.Signature" => "xxx",
"acct1.AppId" => "xxx"
);
/* the payment call */
$adaptivePaymentsService = new AdaptivePaymentsService($sdkConfig);
$payResponse = $adaptivePaymentsService->Pay($payRequest);
//read response
$response = json_decode($payResponse);
$payKey = $response->payKey;
//check if acknowledged
if (strtoupper($response->responseEnvelope->ack) == 'SUCCESS')
{
$payUrl = "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" . $payKey;
return $payUrl;
}
else
{
return false;
}
}
}
?>
payment.php
<?php
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../header.php');
include(dirname(__FILE__).'/mypayments.php');
if (!$cookie->isLogged())
Tools::redirect('authentication.php?back=order.php');
$paypalImgUrl = dirname(__FILE__).'/img/default_logos/default_logo.gif';
//create new instance of my payment class
$myPayments = new MyPayments();
//get cart total
$total = floatval(number_format($cart->getOrderTotal(true, 3), 2, '.', ''));
$Email1;
$Email2;
//call method from my payment class
$payUrl = $myPayments->paypalPayCall($Email1, $Email2, $total);
if ($payUrl == false)
{
echo "<center>Error generating payment link</center>";
}
else
{
//show link to buy with paypal
echo '<center><img src="'.$paypalImgUrl.'" alt="Pay with Paypal"/></center>';
}
include_once(dirname(__FILE__).'/../../footer.php');
?>
validation.php
<?php
//PAYPALS RETURN URL REDIRECTS HERE TO VALIDATE AND PLACE THE ORDER
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../header.php');
include(dirname(__FILE__).'/mypayments.php');
$total = floatval(number_format($cart->getOrderTotal(true, 3), 2, '.', ''));
$myPayments->validateOrder(intval($cart->id), _PS_OS_PREPARATION_, $total, $myPayments->displayName);
$order = new Order(intval($myPayments->currentOrder));
echo "<center> Thank you! Your order is being processed </center>";
include(dirname(__FILE__).'/../../footer.php');
?>
payment.tpl
<p class="payment_module">
<a href="{$this_path}payment.php" title="{l s='Pay with Paypal' mod='mypayments'}">
<img src="{$this_path}paypal.png" alt="{l s='Pay with Paypal' mod='mypayments'}" />
{l s='Pay with Paypal' mod='mypayments'}
</a>
</p>
Any help is much appreciated!
...the Paypal SDK had its own Configuration class
very trivial mistake after all -.-

Categories