PayPalAPIInterfaceServiceService::SetExpressCheckout() returns null response object - paypal

I'm using Yii to build an application that requires payments through PayPal. After a lot of digging, I found that ExpressCheckout is the method to use. The code below worked fine some time ago (some (?) weeks ago, I suppose before PayPal rolling out their new developer platform), using version 1.2.95 of the PHP SDK. Now, using the latest version v.2.2.98, the code fails.
require_once(Yii::getPathOfAlias('application.libraries.paypal') . '/PPBootStrap.php');
$logger = new PPLoggingManager('SetExpressCheckout');
$PaymentDetails = new PaymentDetailsType();
$PaymentDetails->OrderTotal = $PaymentDetails->ItemTotal =
new BasicAmountType('USD', $subscription->price);
$PaymentDetails->PaymentAction = "Sale";
$PaymentDetails->OrderDescription = $subscription->description;
$setECReqDetails = new SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[0] = $PaymentDetails;
$setECReqDetails->CancelURL = 'someCancelUrl';
$setECReqDetails->ReturnURL = 'someReturnUrl';
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$paypalService = new PayPalAPIInterfaceServiceService();
$ok = TRUE;
try {
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
if($setECResponse && strtoupper($setECResponse->Ack) =='SUCCESS') {
$token = $setECResponse->Token;
// Redirect to paypal.com here
$this->redirect(
'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . $token);
}
}
catch (Exception $ex) {
Yii::trace(__METHOD__ . ': Exception while interacting with PayPal API, error: '
. $ex->getMessage());
$ok = FALSE;
}
The offending line is:
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
In PayPalAPIInterfaceServiceService::SetExpressCheckout(), these two lines:
$resp = $this->call('PayPalAPIAA', 'SetExpressCheckout', $setExpressCheckoutReq, $apiCredential);
$ret->init(PPUtils::xmlToArray($resp));
are the issue. $resp is null, so the next line fails at the PPUtils::xmlToArray($resp) method call.
Obviously, either I'm missing something here, or PayPal does something wrong.
Any help?

After a lot of debugging, the cause of the issue was that the service.EndPoint.PayPalAPI parameter was not defined in sdk_config.ini. For some reason that I don't recall, this parameter was deleted from the working config file from the previous version.
Now, the express checkout method works fine, even with the latest 2.3.100 version of the API.

Related

Test a Symfony REST API using Behat / Mink : prb with POST request

My challenge here is to find the best way to test a Symfony (3.4) API application using Behat/Mink for functionnal test, in my CICD platform.
Because my testing processes must be called in a shell script, all the tests must be very linear. I have no way to start a standalone webserver like Apache or the PHP/Symfony webserver. Also, Docker is not an option.
For the moment, I can successfully test the GET verbs of the API using the Mink syntax :
-- file test.feature
#function1
Scenario Outline: Test my api
When I go to "/api/v1/hello"
Then the response is JSON
The "I go to" instruction is implemented by Mink (http://docs.behat.org/en/v2.5/cookbook/behat_and_mink.html) and it emulates a GET request only. When this instruction is called by BeHat, the app Symfony kernel is "spawned" and the "api/v1/hello" method is called internally : there is no network trafic, no TCP connection, there is no need for a dedicated webserver (apache, or the symfony standalone server). It looks like Behat is emulating a webserver and start by itself the Symfony app it its own user space.
Now I want to test the POST verbs of my API, with a json payload, but unfortunally Mink do not have other verbs than GET.
I have read some articles over the web (keyword : behat test post api) but all I have seen is based on a Guzzl/Curl client. So a real client-to-server connection is made to http://localhost and a real webserver have to respond to the request.
I want the Symfony API to be called internally without using an other webserver.
Is there a way to do that ? How to test a Symfony REST API and specially the POST verb without needing a standalone server to reply ?
Thank you.
Here is how I do a functional test of a POST API, with BeHat, without a local running webserver :
test.feature :
#function1
Scenario Outline: Test my api
Given I have the payload
"""
{ "data":"object"}
"""
When I request "POST /api/v1/post"
Then the response is JSON
The featureContext file implement two functions :
"I Have The Payload" : See here https://github.com/philsturgeon/build-apis-you-wont-hate/blob/master/chapter8/app/tests/behat/features/bootstrap/FeatureContext.php
"I request" : based on code provided by philsturgeon just above, I modify it to have something like that :
/**
* #When /^I request "(GET|PUT|POST|DELETE|PATCH) ([^"]*)"$/
*/
public function iRequest($httpMethod, $resource)
{
$this->lastResponse = $this->lastRequest = null;
$this->iAmOnHomepage();
$method = strtoupper($httpMethod);
$components = parse_url($this->getSession()->getCurrentUrl());
$baseUrl = $components['scheme'].'://'.$components['host'];
$this->requestUrl = $baseUrl.$resource;
$formParams = json_decode($this->requestPayload, true);
$formParamsList = [];
foreach($formParams as $param => $value) {
$formParamsList[$param] = json_encode($value);
}
// Construct request
$headers = [
'Accept'=>'application/json',
'Content-Type'=>'application/x-www-form-urlencoded'
];
try {
// Magic is here : allow to simulate any HTTP verb
$client = $this->getSession()->getDriver()->getClient();
$client->request(
$method,
$this->requestUrl,
$formParamsList,
[],
$headers,
null);
} catch (BadResponseException $e) {
$response = $e->getResponse();
// Sometimes the request will fail, at which point we have
// no response at all. Let Guzzle give an error here, it's
// pretty self-explanatory.
if (null === $response) {
throw $e;
}
$this->lastResponse = $e->getResponse();
throw new \Exception('Bad response.');
}
}
If you use Mink then it is quite easy
class FeatureContext extends RawMinkContext
{
/**
* #When make POST request to some Uri
*/
public function makePostRequestToSomeUri(): void
{
$uri = '/some-end-point';
/** #var \Symfony\Component\BrowserKit\Client $client */
$client = $this->getSession()->getDriver()->getClient();
$postParams = [];
$files = [];
$serverParams = [];
$rawContent = '';
$client->request(
\Symfony\Component\HttpFoundation\Request::METHOD_POST,
$uri,
$postParams,
$files,
$serverParams,
$rawContent
);
/** #var \Symfony\Component\HttpFoundation\Response $response */
$response = $client->getResponse();
//...
}
}

RubyMotion: Objective-C stub for message `logInWithPermissions:block:' type `v#:##?' not precompiled

I tried to implement a Facebook login via Parse.com iOS SDK.
When I try to use the PFFacebookUtils.loginWithPermissions:block: method, I got the error.
Objective-C stub for message `logInWithPermissions:block:' type `v#:##?' not precompiled. Make sure you properly link with the framework or library that defines this message.
Anyone experienced this?
I use
rubymotion 2.31
Parse-iOS-SDK 1.2.19 (using cocoapods)
This is my Rakefile:
$:.unshift('/Library/RubyMotion/lib')
require 'motion/project/template/ios'
require 'bundler'
Bundler.require
Motion::Project::App.setup do |app|
app.name = 'myapp'
app.identifier = 'com.your_domain_here.myapp'
app.short_version = '0.1.0'
app.version = app.short_version
app.sdk_version = '7.1'
app.deployment_target = '7.0'
app.icons = ["icon#2x.png", "icon-29#2x.png", "icon-40#2x.png", "icon-60#2x.png", "icon-76#2x.png", "icon-512#2x.png"]
app.device_family = [:iphone]
app.interface_orientations = [:portrait]
app.files += Dir.glob(File.join(app.project_dir, 'lib/**/*.rb'))
app.frameworks += [
'Accounts',
'AudioToolbox',
'CFNetwork',
'CoreGraphics',
'CoreLocation',
'MobileCoreServices',
'QuartzCore',
'Security',
'Social',
'StoreKit',
'SystemConfiguration']
app.libs += [
'/usr/lib/libz.dylib',
'/usr/lib/libsqlite3.dylib']
app.pods do
pod 'SVProgressHUD'
pod 'Parse-iOS-SDK'
end
FB_APP_ID = '<my facebookAppId>'
app.info_plist['FacebookAppID'] = FB_APP_ID
app.info_plist['CFBundleURLTypes'] = [{ CFBundleURLSchemes: ["fb#{FB_APP_ID}"] }]
end
Related code:
def login_with_facebook
PFFacebookUtils.logInWithPermissions(['email'],
block: lambda do |user, error|
if !user
puts 'failed!'
elsif user.isNew
puts 'User signed up and logged in through Facebook!'
else
puts 'User logged in through Facebook!'
end
end
)
end
This is a known bug in the way the Parse SDK bridge files are generated:
http://hipbyte.myjetbrains.com/youtrack/issue/RM-119
Workaround here (for me, I had to do the replacement in the vendor/Pods/build-iPhoneSimulator/Pods.bridgesupport file)
https://groups.google.com/forum/#!msg/rubymotion/36WCWPPkPdc/kBCDS-DOSjsJ

PHP SDK v3 reporting issues

I have downloaded the IPP PHP SDK and am wondering how to make the REST calls for reporting. I am trying to make any REST call and it doesn't seem to work..
I have used the AccountFindAll.php as an example for calling the REST API. I either get nothing back, which makes me think if I am even calling it right, or there is no data returned. I have received an error though for the AgedPayables report saying permission denied. The AccountsFindAll.php example does work and brings me back what I want but it is using some kind of query format.
I would like to use the REST API but I can't get it to work. If anyone can point me in the right direction it would be so appreciated.
Here is my code:
<?php
require_once('config.php');
require_once(PATH_SDK_ROOT . 'Core/ServiceContext.php');
require_once(PATH_SDK_ROOT . 'DataService/DataService.php');
require_once(PATH_SDK_ROOT . 'PlatformService/PlatformService.php');
require_once(PATH_SDK_ROOT . 'Utility/Configuration/ConfigurationManager.php');
//Specify QBO or QBD
$serviceType = IntuitServicesType::QBO;
// Get App Config
$realmId = ConfigurationManager::AppSettings('RealmID');
if (!$realmId)
exit("Please add realm to App.Config before running this sample.\n");
/*
$accessToken = $_REQUEST['accessToken'];
$tokenSecret = $_REQUEST['tokenSecret'];
$realmId = $_REQUEST['realmId'];
*/
$realmId = ConfigurationManager::AppSettings('RealmID');
// Prep Service Context
$requestValidator = new OAuthRequestValidator(ConfigurationManager::AppSettings('AccessToken'),
ConfigurationManager::AppSettings('AccessTokenSecret'),
ConfigurationManager::AppSettings('ConsumerKey'),
ConfigurationManager::AppSettings('ConsumerSecret'));
$serviceContext = new ServiceContext($realmId, $serviceType, $requestValidator);
if (!$serviceContext)
exit("Problem while initializing ServiceContext.\n");
//$httpsUri = "company/".$realmId."/reports/AgedPayables"; //?date_macro=Today
$httpsUri = 'company/'.$realmId.'/companyinfo/'.$realmId;
//$httpsUri = 'company/'.$realmId.'/query';
//$httpsPostBody = 'select * from CompanyInfo startPosition 0 maxResults 500';
$httpsPostBody = NULL;
$httpsContentType = CoreConstants::CONTENTTYPE_APPLICATIONTEXT;
$requestParameters = new RequestParameters($httpsUri, 'GET', $httpsContentType, NULL);
$restRequestHandler = new SyncRestHandler($serviceContext);
list($responseCode, $responseBody) = $restRequestHandler->GetResponse($requestParameters, $httpsPostBody, NULL);
$parsedResponseBody = NULL;
try {
$responseXmlObj = simplexml_load_string($responseBody);
if ($responseXmlObj && $responseXmlObj->QueryResponse)
{
$responseSerializer = CoreHelper::GetSerializer($serviceContext, false);
$parsedResponseBody = $responseSerializer->Deserialize($responseXmlObj->QueryResponse->asXML(), FALSE);
}
}
catch (Exception $e) {
echo $e->getMessage();
IdsExceptionManager::HandleException($e);
}
print_r($parsedResponseBody);
?>
I get an XML response to report queries.
Please refer:
https://developer.intuit.com/blog/2014/03/25/the-quickbooks-online-reports-api-has-arrived
PHP SDK does not support Reports at this time.

Share an app with Friends with Corona sdk free version

I am trying to share my app created in corona sdk free version in facebook. But no working example found on internet. It seems there is a change in facebook api or policy. Does any one have created app in corona sdk with facebook integration recently ? Can any one provide me referece to the way we can integrate the facebook.
I found another question sharing my app through facebook in corona Sdk but the link provided in answer is down. It would be greate= help.
Is there any update in facebook API ? as I am getting response null every time. can any one provide working example reference created recently ?
I tried the example provided by krs in following answer but it is not working for me.
https://developer.coronalabs.com/content/facebook
when I click on any of the feature like post Msg it goes to facebook page and after some processing it directly comes to the home page again nothing gets done. In log I ma getting response null.
following is screenshot of error.
any help will be great help to me.
EDIT
I had tried a lot but the same issue is there. I think facebook app configuration problem is there.
Can anyone provide detailed step by step information to configure an app and generate build in corona ? I am giving another 100 point bounty for this.
I hope this helps make a lua file and copy this code name it whatever you want
local facebook = require "facebook"
local json = require "json"
local _M = {}
local appId = "" -- put your app id string here
local message = ""
local access_token = ""
local fbCommand = ""
local LOGOUT = 1
local SHOW_DIALOG = 2
local POST_MSG = 3
local POST_PHOTO = 4
local GET_USER_INFO = 5
local GET_PLATFORM_INFO = 6
function showPopup(popupTitle,popupMessage)
native.showAlert( popupTitle, popupMessage, {"OK"} )
end
function listener( event )
if ( "session" == event.type ) then
if ( "login" ~= event.phase ) then
showPopup("Facebook share score failed!", "Please try again")
return
end
print(access_token)
access_token = event.token
if fbCommand == GET_USER_INFO then
facebook.request("me")
elseif fbCommand == POST_MSG then
facebook.request("me/feed", "POST" , {message = message} )
end
elseif ( "request" == event.type ) then
local response = event.response
print("Response: ",response)
if ( not event.isError ) then
if fbCommand == GET_USER_INFO then
response = json.decode( event.response )
elseif fbCommand == POST_MSG then
showPopup("Facebook share score", "You've successfully shared your score!")
end
else
showPopup("Facebook share score failed!", "Please try again")
end
end
end
function _M:postToWall(msg)
message = msg
fbCommand = POST_MSG
facebook.login( appId, listener, {"publish_stream"} )
end
function _M:shareGame()
message = "Juggler http://google.com/"
fbCommand = POST_MSG
facebook.login( appId, listener, {"publish_stream"} )
end
return _M
and when you want to share on use this function
local function FacebookShare(event)
if event.phase == "began" then
local FBManager
local message
FBManager = require( "Facebook" )
message = "" -- your message
FBManager:postToWall(message)
end
end
if user is not login it will call login facebook.
this works for me hope it solve your problem
There is facebook sample app from ansca labs. See that from the link below:
https://developer.coronalabs.com/content/facebook
And there is an integration in the app Ghosts-vs.-Monsters
https://github.com/ansca/Ghosts-vs.-Monsters
Keep coding......... :)

The request was aborted: Could not create SSL/TLS secure channel.

I want to implement Paypal dodirect method for user can do payment directly on my website instead of redirecting to user
so for that i have added this URL as https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl
and i am using following code
PayPalAPIAAInterfaceClient objpaypalapiaainterfaceclient = new PayPalAPIAAInterfaceClient("paypalapiaa");
CustomSecurityHeaderType objcustomsecurityheadertype = new CustomSecurityHeaderType();
objcustomsecurityheadertype.Credentials = new UserIdPasswordType();
objcustomsecurityheadertype.Credentials.Signature = "a8ft-8ji.2tzocnfshfjj4ahgxn4avlxzply8bmsbupxafkbty2--c6p";
objcustomsecurityheadertype.Credentials.Username = "fred_1350925179_biz_api1.gmail.com";
objcustomsecurityheadertype.Credentials.Password = "1350925199";
DoDirectPaymentReq objdodirectpaymentreq = new DoDirectPaymentReq();
objdodirectpaymentreq.DoDirectPaymentRequest = new DoDirectPaymentRequestType();
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentAction = new PaymentActionCodeType();
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Sale;
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType();
//objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.InvoiceID = "1";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.IPAddress = Request.ServerVariables["remote_addr"].ToString();
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.MasterCard;
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType();
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType();
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD;
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = new AddressType();
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = "120";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber ="1111222233334444";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CVV2 = "258";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = 9;
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.ExpYear = 2013;
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Payer = "rahularyansharma#gmail.com";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = "Shakti";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = "Kapoor";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 ="test address";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = "Atlanta";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince = "ga";
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = CountryCodeType.US;
objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = "12345";
DoDirectPaymentResponseType objdodirectpaymentresponsetype = objpaypalapiaainterfaceclient.DoDirectPayment(ref objcustomsecurityheadertype, objdodirectpaymentreq);
now when i am run this code throwing followin exception
'
The request was aborted: Could not create SSL/TLS secure channel.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
You can confirm the SSL protocol for https://www.sandbox.paypal.com, using https://www.ssllabs.com/ssltest. The screenshot shows that it supports TLS 1.2 You will need to add the following two lines to your code at the point of making httpclient call:
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Sample:
The implementation should solve the problem.
Sorry, i cannot add this as a comment/question.
It seems like one of certificates for paypal is not in the trusted list.
Can you try download paypal root certificate and install it as trusted CA?
I think this two links can help you:
https://www.sslshopper.com/ssl-certificate-not-trusted-error.html
and
http://raysilvadotnet.wordpress.com/2014/02/13/problema-system-net-webexception-the-request-was-aborted-could-not-create-ssltls-secure-channel/
(sorry, cannot insert more than 2 links as normal links)
Also, please make sure you authenticating via login/password not certificate. If you are using certificate for API, you should follow last paragraph of this link