How to integrate Paypal with SOAP API? - soap

I have some problem when i integrate PayPal with SOAP API.
Now, This my code
// Set paypal
// Include NuSOAP
$url_nusoap = "xxx/nusoap/nusoap.php";
include($url_nusoap);
$wsdl_URL = "https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl";
$s_URL = "https://api-3t.sandbox.paypal.com/2.0/";
$s_Ver = "94.0";
$header = "";
$header .= "<RequesterCredentials xmlns='urn:ebay:api:PayPalAPI' xsi:type='ebl:CustomSecurityHeaderType'>";
$header .= "<Credentials xmlns='urn:ebay:apis:eBLBaseComponents' xsi:type='ebl:UserIdPasswordType'>";
$header .= "<Username>#api_username#</Username>";
$header .= "<Password>#api_password#</Password>";
$header .= "<Signature>#api_signature#</Signature>";
$header .= "</Credentials>";
$header .= "</RequesterCredentials>";
$s = new soap_client($wsdl_URL, true);
$err = $s->getError();
if ($err) die("Soap client constructor err.. check wsdl url");
//set end point
$s->setEndpoint($s_URL);
$s->setHeaders($header);
$bodyReq = "?"
$result = $s->call("?", $bodyReq);
And my problem is i don't know what should i call API in "$bodyReq" and $s->call(); ?
This my situation :
In my site can select pay method
Paypal
xxx
xxx
When i choose "1 Paypal" and submit - Redirect to "pay_checker" if pay_method == "Paypal" redirect to "PAYPAL SOAP API Page" (if pay_method == "xxx" redirect it to some API in other pay services)
I need if i select "PayPal method" and redirect to "PAYPAL SOAP API" page it's call some API to pass $amount ,$product_name and redirect to PAYPAL Billing page
somebody help me please
Thank you.
Edit ------ Now i learn "ExpressCheckout" but i don't know where point to learn it

What you currently have is building your credentials only, which would then get included in your actual XML request, which is where $bodyReq would come into play.
PayPal provides plenty of documentation for Express Checkout, including this document specific to the SOAP API. Chapter 6 covers Express Checkout.

Related

PayPal Smart Payment Buttons integration with server-side REST API

I know there are a few questions regarding PayPal Integration but I'm trying to implement PayPal Express Checkout with Smart Buttons and REST API and no success.
What I want to do is:
Create a Payment Authorization (with payidand orderid)
Send this payid to the client (javascript) to be approved.
Redirect after payment to a confirmation page.
I have already created a Payment Authorization with the code bellow:
<?php
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
// Used for composer based installation
require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
// Use below for direct download installation
// require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
// After Step 1
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'client id', // ClientID
'cliente secret' // ClientSecret
)
);
// After Step 2
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$amount = new \PayPal\Api\Amount();
$amount->setTotal('1.00');
$amount->setCurrency('USD');
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("https://example.com/your_redirect_url.html")
->setCancelUrl("https://example.com/your_cancel_url.html");
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
// After Step 3
try {
$payment->create($apiContext);
echo $payment;
echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
echo $data= json_encode($payment->id, JSON_PRETTY_PRINT), "\n";
echo "</br>";echo "</br>";
echo $data= $payment->id;
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
// This will print the detailed information on the exception.
//REALLY HELPFUL FOR DEBUGGING
echo json_encode($ex->getData()->id, JSON_PRETTY_PRINT), "\n";
echo "</br>";echo "</br>";
echo $ex->getData()->id;
}
?>
My setup is as following (Please, correct if it's wrong):
User chooses the item and submits the form.
User is redirected to a new page with a new form and then fills the form with his name and other personal informations and then submits the form to be saved in the database and generate the Payment Authorization.
User should be redirected to a final page with Smart Buttons to complete the payment.
User should be redirected to a confirmation page, confirming his payment was successfully made.
The problem is that I'm stuck in the step 2 because once I generate the Payment Authorization, I don't know how to pass this id (and other required parameters) to the client, in this new page that is supposed to show the Smart Payment Buttons to complete the transaction.
I'm following along with the tutorial in PayPal documentation but I'm not able to understand.
The JavaScript makes calls to my server to get the payid, it works, but it generates a new payid and a new Payment Order, i want to use the one that was previously created when the user submitted the form and then, somehow, pass it to the final page with the Smart Buttons to complete the transaction and redirect to a confirmation page.
My Javascript:
<script>
paypal.Button.render({
onApprove: function(data) {
return fetch('/my-server/get-paypal-transaction', {
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
}).then(function(res) {
return res.json();
}).then(function(details) {
alert('Transaction approved by ' + details.payer_given_name);
}, '#paypal-button');
</script>
The problem is that it generates a new orderID, a new transaction, and I want to retrieve the transaction that was generated when the user submitted the form in the step 2 but I don't know what I should do.
Ultimately what I need is:
Get the Payment Authorization and pass it to the Client (final page with the buttons)
Redirect the users after payment complete.
You are looking for this front-end: https://developer.paypal.com/demo/checkout/#/pattern/server
For your backend, you should use the latest v2/orders SDK: https://github.com/paypal/Checkout-PHP-SDK
(Your v1/payments backend will work, but that SDK is deprecated and there is no reason to use it for a new integration)

PayPal SDK: No Server Response when Paying with PayPal Account

I have scoured the docs and this tutorial about 100 times but can't figure out how to go through the payment process using a PayPal account as opposed to a credit card. I have gotten the credit card payment to go through just fine.
In the aforementioned tutorial, it is stated that I am supposed to expect a JSON response from the server after making an OAuth credential:
$sdkConfig = array(
"mode" => "sandbox"
);
$cred = new OAuthTokenCredential("clientID","clientSecret", $sdkConfig);
I get absolutely no server response despite geting a '200 OK' status from the server.
Initially I had my code set up like a bunch of other tutorials:
$apiContext = new ApiContext(
new OAuthTokenCredential(
'clientID', // ClientID
'clientSecret' // ClientSecret
)
);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item1 = new Item();
$item1->setName("Donation squares.");
$item1->setCurrency('USD');
$item1->setQuantity(1);
$item1->setPrice(1);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$amountDetails = new Details();
$amountDetails->setSubtotal('7.41');
$amountDetails->setTax('0.03');
$amountDetails->setShipping('0.03');
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('7.47');
$amount->setDetails($amountDetails);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('This is the payment transaction description.');
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("https://devtools-paypal.com/guide/pay_paypal/php?success=true");
$redirectUrls->setCancelUrl("https://devtools-paypal.com/guide/pay_paypal/php?cancel=true");
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
try{
$payment->create($apiContext);
} catch(Exception $e){
echo $e
exit(1);
}
None of this works either - no response from the server whatsoever.
ANSWER / COMMENT
You're not supposed to be looking for a JSON response after all. If the payment is successfully created, an approval URL should be generated by running
$payment->getApprovalLink();
The user then follows this link to finalize his/her payment.
You might be interested in following a very simple instruction here at PayPal-PHP-SDK, that explains how to make calls using PayPal PHP SDK. I know you have already gone through that, and are looking for how to create a payment using PayPal.
I am not sure you are aware of this, but PayPal-PHP-SDK comes along with a lot of samples, that you could run by just one simple command (if you have PHP 5.4 or higher). One of the first sample have the instructions and code to make PayPal Call.
There are two steps involved in that.
Create a Payment. Receive a approval_url link to be used to ask the user to complete Paypal flow over any browser.
Once the user accepts the payment on paypal website, it will be redirected back to your website, where you execute the payment.
Both the code samples are provided here and here.
Let me know if this helps, and you have any more questions. I would be more than happy to help.

Contact Form PHP Include

I'm not sure how to ask my question, but I have a contact form that is include on every page of my website: http://assistedlivingbridgeton.com/ (the "schedule your tour" form).
Currently, this is the form processing code:
<?php
// if the url field is empty
if(isset($_POST['url']) && $_POST['url'] == ''){
// then send the form to your email
$email = "knunn#standrews1.com, eechols#standrews1.com";
$message = "The following information was submitted from the Schedule Your Tour form on your website:\n
";
$message .= "Name: ".$_REQUEST["Name__1"]."\n\n";
$message .= "Email: ".$_REQUEST["Email__2"]."\n\n";
$message .= "Phone: ".$_REQUEST["Phone__3"]."\n\n";
$message .= "Best date/time: ".$_REQUEST["Best_datetime__4"]."\n\n";
mail( $email, "Bridgeton Assisted Living Tour Form", $message, "From: $email
X-Priority: 1 (Highest)" );
header("Location: http://www.assistedlivingbridgeton.com/thanks.php");
}
// otherwise, let the spammer think that they got their message through
?>
<h1>Thanks</h1>
We'll get back to you as soon as possible
?>
What I would like to do is have one form processing script that pops in a "thank you" message kinda like a php include where that Tour Form is on the sidebar. The way I have it set up now, I have to have a process script and a thankyou page for each landing page on my site that has that form. I want one script, that will pop in the thank you message to whatever page the form was filled out from. Does that make sense? Help please! I know its possible because if you use Foxy Form or something similar, that's exactly what it does.
You can use <iframe> to do that.
You create a file : form.php, write all your code including the thank you and the form itself and then just call this page where ever you want using iframe. Thus you add this code to all pages where you want the form to appear and the result thank you will appear in the same page:
<iframe src="form.php" width="150px" height="250px" border="0">
more information about iframe you can get here: w3schools iframe

PSGI, LWP::UserAgent & PayPal IPN

I have been trying for some time to get a simple PayPal IPN module working but keep getting a 400 Bad Request error from LWP::UserAgent. I am not sure why this is happening. PayPal pings me fine (I'm using the IPN simulator) and I can see the process in my app logs. I can call the PayPal validation URL via LWP::UserAgent without form content and that works fine, but once I include the request content for validation I get error 400. If anyone knows about this please let me know.
-$self->{'_req'} is of type Plack::Request
my $url = $test ? $VERIFY_URL_DEV : $VERIFY_URL;
my $ua = new LWP::UserAgent();
my $req = new HTTP::Request('POST', $url);
my $query = 'cmd=_notify-validate&' . $self->{'_req'}->raw_body;
$req->content_type('application/x-www-form-urlencoded');
$req->content( $query );
my $res = $ua->request($req);
if ($res->is_error)
{
# HTTP error, indicate an invalid notification.
warn "There was an error validating this IPN.";
warn $res->message;
warn $res->error_as_HTML;
return 0;
}
The problem was on the PayPal side. When I tested in sandbox, not the IPN simulator, it worked fine. That was very frustrating.

Paypal IPN listener issue

I currently have a problem with my Paypal IPN listener and have been receiving the following email from paypal each day:
"Please check your server that handles PayPal Instant Payment Notifications (IPN). IPNs sent to the following URL(s) are failing:
http://www.mysales.ie/create_promo_listener.php"
I have a demo site which enables users to create ads and works perfectly (no problems with IPN), however the proper site that I am developing has this issue (It is on a different host).
I have contacted the host provider and they have said it is not an issue on their side. I have tried php error logs but cant find any issues. I have the exact same code on both sites so I cant understand what the problem is.
<?php include 'ipn_handler.class.php';
/**
* Logs IPN messages to a file.
*/
class Logging_Ipn_Handler extends IPN_Handler
{
public function process(array $post_data)
{
$data = parent::process($post_data);
if($data === FALSE)
{
header('HTTP/1.0 400 Bad Request', true, 400);
exit;
}
$random_number = $_POST['custom'];
file_put_contents( 'logs/listenerTest.txt', "listener = " . $random_number, FILE_APPEND);
header("location:create_promo_creator.php?random_number=" . $random_number);
}
}
date_default_timezone_set('Europe/Oslo');
$handler = new Logging_Ipn_Handler();
$handler->process($_POST);
I have been trying to find the root of the problem for a long time but cant figure it out.
Seems that your $data = parent::process($post_data);
method is returning FALSE.
Do you have any logging instrumentation in your code to verify this?
The easy workaround is to return a 200 response to keep PayPal's IPN system happy, and to log the error for further review.