I'm struggling with a simple storage script that should be called via PayPal IPN to save the current payment.
I'm using
$input = json_encode($request->all());
$paylog = Paylog::create([
'data' => $input,
]);
and the result from any incoming POST is always "0".
Where is my fault?
Perhaps you mean to access $_POST
IPN messages should be verified with a postback to ipnpb.paypal.com before doing anything with their contents
IPN is a very old and clunky technology, why are you using it?
To obtain details on a 'current' payment, you should be using an API like v2/checkout/orders to facilitate the checkout. For this you need two routes on your server, one for 'Set Up Transaction' and one for 'Capture Transaction', documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/
The best approval flow to pair with your two routes is https://developer.paypal.com/demo/checkout/#/pattern/server
Solution:
//Make sure encode values to UTF8
$input = json_encode(array_map('utf8_encode',$request->all()));
//And store
$paylog = Paylog::create([
'data' => $input,
]);
Or to make things a little more efficient:
$paylog = Paylog::create([
'data' => $json_encode(array_map('utf8_encode',$request->all())),
]);
Related
I tried use checkout api in Paypal to send funds from one personal account to another, But after clicking the continue button, refreshed checkout page and didnt transfer the funds.
Here is the PHP code what I did:
private function sendDirectlyPayment(float $amount, string $currency, string $address, string $backUrl): array
{
$params = [
'intent' => 'CAPTURE',
'purchase_units' => [
[
'amount' => [
'currency_code' => $currency,
'value' => (string) $amount
],
'payee' => [
'email_address' => $address
]
]
]
];
$data = $this->encodeData($params);
$headers = $this->getAuthHeaders($data);
$res = $this->execute(self::POST, '/v2/checkout/orders', $data, $headers);
return $res;
}
Not sure how to make to work api properly.
You set up the payment correctly, and the payer is approving the payment. But you are missing the final 'capture' API step, so no transaction is created. You need to implement the v2/checkout/orders/.../capture API call after approval.
The best way is to make two callable routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). The latter one should (on success) store the payment details in your database before it does the return (particularly purchase_units[0].payments.captures[0].id, the PayPal transaction ID)
Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
----
The smart button gives the best user experience -- however, if for some reason your use case is better without it, then what you need to do is specify a return_url in the create order call. When the payer clicks continue and reaches the return_url, it is there when you would display an order review page and have a button that triggers the capture API call for the final action.
If you want to skip having a review page and do the capture immediately, this is also possible to do, but you need to set the application_context object's user_action parameter to PAY_NOW, so that the last button has appropriate text instead of 'Continue'.
I am integrating Orange Money Payment gateway with my Yii2 basic Application to be able to receive local payments on this application.
In this API, when the user initiates a transaction, I receive some data after sending a curl request to the Orange money API. I store this data in my Database with a key call notif_token. The user is then redirected to orange payment portal where the payment is done. when the User completes a payment process on their portal, they send me json response to a particular url call Notifcation URL. I am suppose to receive this data, update my Database and grant access to this user to some resources.
Everything works well till the level of receiving the feedback in from them through the notification URL.
I have tried all I know to receive this information but to no avail since this action is not an api url. I have written my action as shown below but I do not know what I am missing.( might be a configuration for this action or something).
public function actionOnotification(){
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$request = \yii::$app->request->post();
$transaction =OrangeFeedback::findOne(['notif_token'=>$request['notif_token']]);
$transaction->status = $request['status'];
$transaction->txnid = $request['txnid'];
$transaction->save();
//do some processing here
}
I do not know how to solve this problem as I feel I am missing a fundamental concept here( might be on how to configure a Yii2 basic application action to receive json data, might be how to convert that action into an API call URL or something which I can not yet figure out). Any help on this will be greatly appreciated as I can't find any resources online to help me.
To receive JSON data you need to configure your request component in the config:
'components' => [
...
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
...
]
See the docs for more information
I have the following code and it sends SMS notifications to my phone:
$notification = $twilio->notify->services($serviceSid)
->notifications->create([
'toBinding' => $batch,
'body' => $txt,
'statusCallback' => 'http://postb.in/b/jarblegarble' // <-- this doesn't work
]);
However, even though the sending works, I can't seem to figure out their callbacks.
I'm scouring through their docs and I can't find how to set the callback URL. I see some of their resources use "url" while others use "statusCallback" (heck, one seems to use "redirect"). That being said, I can't seem to post to postb.in using them -- there must be a way to check the status of my notification.
So it turns out I was wrong on two fronts.
1) The callback URL needs to be passed to your messaging service this way:
$notification = $twilio->notify->services($serviceSid)
->notifications->create([
'toBinding' => $bindings,
'body' => $txt,
'sms' => ['status_callback' => 'http://your_callback_url' ]
]);
2) postb.in wasn't working! I was testing the code above, after being assured by twilio support that it was valid, I decided to try and post to my own server and just capture the POSTed content. Sure enough, it was working as they suggested.
Edit: It wasn't clear to me at the time but the callback URL will be called for each SMS sent out for each status update. So that means queued, sent, and delivered. I initially thought that I'd just get a status update for the batch itself as I don't necessarily care for the status of up to 10,000 txt messages.
Your example passes the statusCallback parameter of the individual SMS service API to the universal notify API. This mixing won't work. The individual SMS service sets up a callback for that one particular message, which isn't efficient for batch sends. The universal notify API, in contrast, relies on web hooks, which are globally configured per service.
The simplest thing to do, in your case, is to use the individual SMS service API:
$message = $twilio->messages->create('+15551234567', [ 'body' => 'Hi',
'from' => '+15559876543',
'statusCallback' => 'http://postb.in/b/jarblegarble' ]);
To use the universal notify API, you'll need to set the PostWebhookUrl to the target URL when creating the notification service, and arrange for the code at that URL to handle onMessageSent messages. More at the "web hooks" URL above.
Caveat emptor: haven't tried any of this, and I haven't used Twilio in literally eight years, but the above is my theoretical understanding.
I am using laravel 5.5 and trying to do integrate a payment processor (local one) into the solution I am building. The issue : The processor is giving data needed on requests as data that needs to posted, and the problem is that some of that data are confidential !
So if I integrate them as hidden inputs in the form and post them using JS or even as a normal form, any user could access that data.
The solution for me is to handle the request of the user (his choice of paying online) and from there, I redirect him to the payment gateway with a POST method that contains all the data needed by the procesor.
What I've tried so far is using Guzzle, but guzzle is somehow acting like an ajax request, actualy even like an API request, it waits for data to return, while I don't need it, in fact, I have to redirect the user so that he can enter his payment details and authorize the payment.
$user = Auth::user();
$processorData = [
'NumSite' => 'XXXXXX',
'Password' => 'XXXXXXX',
'Amount' => $invoice->total,
'Devise' => 'TND',
'orderId' => $id,
'PayementType' => 1,
'EMAIL' => $user->email,
'signture' => sha1('XXXXXX'.'XXXXXXX'.$id.$invoice->total.'TND')
];
$client = new Client();
$request = $client->post('https://preprod.gpgcheckout.com/Paiement_test/Validation_paiement.php',
['paiment' => $processorData]);
I also tried a redirect, a curl .. same thing.
What I'm looking to achieve is like posting some data on behalf of user choice but without letting anyone see the hidden fields in my source code (html page)
Thank you
Quetion:
How would I cancel a pre-approved payment using PayPal's API operations? I have the Pre-approval key of the payment to be cancelled but I can't find a way to do it.
I did some digging over the internet and found this CancelPreapproval API Operation but that document is not very helping for a starter like me. Few things are missing like what would be the link where I'd send the cancel request? Can't find any example. Need help.
I did tried cancelling the payment by using this code but it fails.
$security_user_id = $neworder->security_user_id;
$security_password = $neworder->security_password;
$security_signature = $neworder->security_signature;
$security_application_id = $neworder->security_application_id;
$headers_array = array("X-PAYPAL-SECURITY-USERID" => $security_user_id,
"X-PAYPAL-SECURITY-PASSWORD" => $security_password,
"X-PAYPAL-SECURITY-SIGNATURE" => $security_signature,
"X-PAYPAL-APPLICATION-ID" => $security_application_id,
"X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON",
);
$pay_result = wp_remote_request('https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval', array('method' => 'POST', 'timeout' => 20, 'headers' => $headers_array, 'body' => $maincode));
This PayPal PHP SDK will make it very quick and easy for you. Just extract it into your project structure as you would any other class, and make sure to setup the config file correctly with your own sandbox and/or live PayPal credentials.
Then you can look in the /templates and you'll see a CancelPreapproval.php setup and ready to go. It'll be fully functional. All you'll have to do is plug in your preapproval key and it'll handle the rest for you successfully.
There are lots of /samples and there is a file in /templates for pretty much every API call PayPal has.
You can get this done within minutes using that class. Let me know if you have any specific questions about it.