PayPal & PHP - Set no shipping - php

I'm in the process of creating a payment with PayPal with their REST API.
I have everything set up and working but when I create a WebProfile and call setNoShipping(1), nothing changes:
My code:
$inputFields = new InputFields();
$inputFields->setNoShipping(1)
$webProfile = new WebProfile();
$webProfile->setName('test' . uniqid())->setInputFields($inputFields);
And according to this post on StackOverflow it's not possible, but is that still the case 1 year later?

I had the same problem but after some research and many try & error i got it to work.
You have to "create" the profile and add its id to the Payment.
[...]
$webProfileId = $webProfile->create($apiContext)->getId();
$payment = new Payment();
$payment->setExperienceProfileId($webProfileId);

Related

PHP PayPal integration - Cancel link in approval e-mail

I need some help with PayPal integration.
I use this library:
https://github.com/paypal/PayPal-PHP-SDK/wiki/Installation-Composer
and I use WebHooks to receive notifications of payments.
I create payment link like this:
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential($paypal_client_id, $paypal_client_secret)
);
$apiContext->setConfig([
'mode'=>$paypal_mode
]);
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$amount = new \PayPal\Api\Amount();
$amount->setTotal('1.00');
$amount->setCurrency(Config::get('paypal.currency'));
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl(Uri::create(Config::get('paypal.redirect_url')))
->setCancelUrl(Uri::create(Config::get('paypal.cancel_url')));
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
$payment->create($apiContext);
$payment_url = $payment->getApprovalLink();
Then, I run this link, log in to PayPal and make a payment.
Now, I receive WebHook with event PAYMENTS.PAYMENT.CREATED - so, OK, but after several minutes I get an e-mail:
"Would you like to complete your PayPal payment at xxx?
To finish, go back to xxx and give your final approval."
And text „give your final approval” is linked to my Cancel Page witch I entered into setCancelUrl() metod.
I don’t receive any more webhooks.
Do you have any ideas?
See https://developer.paypal.com/docs/integration/direct/payments/paypal-payments/
You have reached step 3, the payment was created and approved.
You are apparently missing step 4 to actually execute the payment and create a PayPal transaction.... so, no money has moved yet.
Moreover, all of the above and your work so far with the PayPal-PHP-SDK is for an old version of the PayPal REST API, v1/payments. I recommend setting all of those things aside and instead trying out the new v2/orders PHP SDK: https://github.com/paypal/Checkout-PHP-SDK
Here is a demo pattern of the best UI: https://developer.paypal.com/demo/checkout/#/pattern/server
Here is a reference for the server-side integration: https://developer.paypal.com/docs/checkout/reference/server-integration/

How to make an Invoice as paid using PHP code at quickbooks online sdk

I have created Invoice using this code : https://github.com/intuit/QuickBooks-V3-PHP-SDK/blob/master/src/_Samples/InvoiceCreate.php
But how can make this invoice as paid using PHP sdk?
Here I am getting payment using paper check ... so I am creating Invoice just for bookkeeping and not sending to client. ( not using QBO Payment )
so when I rec payment how to mark invoice as paid using php sdk ?
I try to update "Balance" as 0 but its not marking as paid.
Thanks
I'm not a 100% sure about this, but I think you have to create payments for that invoice amounting to the full sum of the invoice. To see the required contents of the payload, see https://developer.intuit.com/docs/api/accounting/payment.
First I'd really recommend you use The library written by Keith Palmer for this as the QBO documentation is garbage that's all over the place.
With that being said:
You need to return the transaction Id from the invoice:
return $resultingObj->TxnId;
And then create a payment using supplying that transaction id:
$invoiceId = CreateInvoice(); //returns txnId above
$qbLinkedInvoice = new IPPLinkedTxn();
$qbLinkedInvoice->TxnId = $invoiceId;
$qbLinkedInvoice->TxnType = 'Invoice';
$qbLine = new IPPLine();
$qbLine->Amount = "";//set amount;
$qbLine->LinkedTxn = $qbLinkedInvoice;
$qbPayment = new IPPPayment();
$qbPayment->CustomerRef = "";//customer id
$qbPayment->TotalAmt = "";//I think this must match amount above;
$qbPayment->Line = array($qbLine);
$createdQbPayment = $this->dataService->Add($qbPayment);

PayPal guest checkout stopped working on mobile

How and where can I start debugging Guest Checkout with PayPal?
I had the site running fine for over a year and now suddenly the Guest Checkout on the mobile website stopped working. I'm using PayPal PHP SDK and nothing have been changed in the code. The guest checkout it's just not showing on mobile devices but works fine on desktop.
I have searched the documentation and the forum I saw couple of similar questions but no answer to them.
Things mentioned:
Clear browser cache, not the case random users complaining, but have tried it myself and still no joy.
Your business needs to be set up to accept credit/debit cards, it is as said it worked smoothly over a year, now all of the sudden it doesn't work.
Checked logs on server but there is no error log at all.
I tried to see developers support on PayPal but more or less it only points to "Ask the community" and no real way of contacting technical support.
Update relevant part of code used:
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Api\ShippingAddress;
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'XXX', // ClientID
'YYY' // ClientSecret
)
);
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// ### Itemized information
// (Optional) Lets you specify item wise
// information
$item1 = new Item();
$item1->setName($name)
->setCurrency($currency)
->setQuantity($quantity)
->setPrice($price)
->setDescription($description)
->setSku($productid);
$myitem=array($item1);
$itemList->setItems($myitem);
$details = new Details();
$details->setShipping($shipping)
->setTax($tax)
->setSubtotal($subtotal);
$amount = new Amount();
$amount->setCurrency($currency)
->setTotal($totalprice)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription($description);
$baseUrl = "https://........";
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/execute.php")
->setCancelUrl("$baseUrl/cancel_execute.php?id=$productid");
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
try {
$payment->create($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
//echo "<pre>";
//var_dump($ex->getData());
exit(1);
}
foreach($payment->getLinks() as $link) {
if($link->getRel() == 'approval_url') {
$redirectUrl = $link->getHref();
break;
}
}
$payment_id = $payment->getId();
Ok so here is the update, after 2 days of hell and countless backward and forward with PayPal, I spoke with different persons on different channels and I got the following answers:
1) This never worked on mobile because it is insecure, it does work on iPad. - What a joke, it worked for over a year and actually it doesn't work on iPad at the moment.
2) Your account is not set up to accept Credit Card payment. - GGGRRRRR I know it isn't I was doing PayPal type sale, which should allow a guest checkout!
3) This is from their ticketing system (Sorry what in English please??? )
I have enabled this option for you. Please note that direct payments
by credit card will not work 100% of the cases, and if you do some
tests maybe does not work.
The process that allows or not to pay as a guest is a process is
beyond our control, we can only Maximize the allowance.
4) If a customer tried to use the card to many times it won't allow it to use it. - But they had NO CHANCE of even trying to use it because they are only presented with a sign up page
5) There is no guest option - LOL!!!!!!!!!
6) Try clearing the cache - LOL!!!!!!!
Solution?
I ended up paying for "PayPal Pro" rewriting my checkout process and now I'm processing Credit Cards directly, currently in Sandbox and waiting for PayPal to vet my webpage that it does satisfy their needs and give me the green light for the pro account (which should be no later than Monday).
Did the problem actually got sorted? - NO
If anybody stumbles across this post and know a way on how to get Guest checkout to work, please do not hesitate to share, other than that my personal conclusion is that after this weekend I will seek to use another (possibly cheaper) payment processing gateway and only keep PayPal as a secondary option is somebody wants to sign out using PayPal Express.

How add notify url to REST API paypal?

I created simple payment in paypal
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$item1 = new Item();
$item1->setName('some name')
->setCurrency('USD')
->setQuantity(1)
->setSku("my id product")
->setPrice(11);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(11);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
$baseUrl = "https://my_site_address.com";
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment/?success=true")
->setCancelUrl("$baseUrl/ExecutePayment/?success=false");
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($apiContext);
} catch (Exception $ex) {
print_r($ex);
exit(1);
}
$approvalUrl = $payment->getApprovalLink();
print_r($approvalUrl);
After execute this code everything is alright, I am redirected to Paypal sandbox and after log in i can make a pay. But I don't know how, where i can set my notify_url?
Anyone can help ?
the direct and short answer to your question is yes you can set a "notifyUrl" via REST API:
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription(" ...... ")
->setNotifyUrl("your notifyUrl here")
->setInvoiceNumber($invoiceNo);
BUT this is not the correct way receiving REST Notifications. Use "Webhooks" instead (though Webhooks using PHP is soo hacky, but at the end you find a solution. if you need more details on how to do it, just comment this answer).
Back to NotofyUrl:
for testing i was able to receive notifications via notifyUrl, BUT after implementing a webhook, PayPal still sending notifications to my old already removed NotifyUrl for every new Payment. i deleted it from the code, i deactivated IPN in my PayPal account. I tried many things, but PayPal still sending IPNs for every Payment. Now i receive 2 Notofications, one via NofityUrl and the second via WebhookEvent Listener. no idea whats going wrong here. So i wouldn't recommend the usage of notifyUrl, instead just implement a webhookEvent listener.
The parameter for notify url can't be used in REST API calls. If you want to set up the IPN url, you have to set it within your Paypal account:
Here is the steps:
1. Login paypal account
2. Click profile and under Selling preferences, choose Instant Payment Notification preferences
3. Click Choose IPN setting
4. Type the URL that you receive IPN message and choose Enabled

Paypal Checkout Express doesn't show the order details

I'm using the lib PayPal-PHP-SDK on Laravel 4
and I have a problem with showing the order details.
I followed the steps from Paypal Web Checkout
and it doesn't showing me the order details.
it says "You'll be able to see your order details before you pay."
- Image Link
This is the method when I get the link to the payment:
public function checkout()
{
$apiContext = new ApiContext($this->cred, 'Request' . time());
$apiContext->setConfig($this->sdkConfig);
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$amount = new Amount();
$amount->setCurrency("EUR");
$amount->setTotal("10");
$transaction = new Transaction();
$transaction->setDescription("Example");
$transaction->setCustom('abv');
$transaction->setAmount($amount);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(URL::to('/') . '/payment/success/');
$redirectUrls->setCancelUrl(URL::to('/') . '/payment/cancel/');
$payment = new Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
$payment->create($apiContext);
print $payment->getApprovalLink();
}
I don't see any itemized details in your request. It would help to see a sample of the raw request getting sent to PayPal, but from what I can see those parameters are simply not getting included.
On a side note, you may be interested in checking out my PHP class library for PayPal. It's available on GitHub and Packagist and works with Composer, so it works very nicely with Laravel, and it's a lot easier to use than PayPal's SDK. It sets up all the parameters you might want to use, including itemized details, so all you have to do is fill in the parameters and you're done.
As Andrew mentioned, you are missing itemized details in your request. This is how you could do it. http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/CreatePaymentUsingPayPal.html
As you can see the create payment has an array of transactions that has an item_list attribute, that needs to be set. You can see how to do so, using our SDK in above link.
We attach a lot of samples in our SDK now, that could be ran in your local machine with just one command. Please follow the instructions here
The command you need to run is:
php -f <paypal SDK Directory>/paypal/rest-api-sdk-php/sample/index.php
This will host a local server at localhost:5000, that would allow you to run the samples located in samples directory.
PayPal-PHP-SDK is getting developed strongly, and we are adding more and more features to it. Please visit our SDK page to view all the supporting documentations, API specs, Samples, etc.

Categories