Using PayPal Integration Wizard: Problems with empty variables - php

What I have to do:
Client defines a quite tricky product.
Price is calculated according to different Parameters via javascript.
Client states, that he wants to pay with PayPal and sends form.
When checking the content of the form, I want to react on his wish to pay via PayPal.
I used the integration wizard. I implemented paypals expresscheckout.php and paypalfunctions.php.
I set the variables at the start of paypalfunctions.php (sandbox). Made the rest of the code as given and tracked it until the paypal-call.
There is a call to PayPal in their own function "hash_call", where they use these variables.
But they are empty.
code in paypalfunctions.php
Defines all the global variables and the wrapper functions
********************************************/
$PROXY_HOST = '127.0.0.1';
$PROXY_PORT = '808';
$SandboxFlag = true;
//'------------------------------------
//' PayPal API Credentials
//' Replace <API_USERNAME> with your API Username
//' Replace <API_PASSWORD> with your API Password
//' Replace <API_SIGNATURE> with your Signature
//'------------------------------------
$API_UserName="myemail";
$API_Password="mypw";
$API_Signature="mysignature";
...
code in hash_call: The function hash_call ist part of paypalfunctions.php
function hash_call($methodName,$nvpStr)
{
...
//declaring of global variables
global $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature;
...
Whats going wrong?
There is a link zu the wizard: https://devtools-paypal.com/integrationwizard/ecpaypal/code.php
Piet

It is possible that you are using the wrong API Credentials.
I noticed in your example you put the following:
$API_UserName="myemail";
$API_Password="mypw";
$API_Signature="mysignature";
Just to be clear your API User name is not your Email address. Your API Password is not your PayPal Password.
Just in case you need it, here is an example of what API credentials look like and how to request them from your PayPal Account. You can use these same instructions on your Sandbox account as well:
API Credential Information
Also make certain of your endpoint. The endpoint is where you are pointing your customers. Are you pointing them at the live site or the sandbox site?
Just in case you need them, here is the API endpoint information:
PayPal API Endpoint Information
Make certain that if you are using Sandbox Credentials you are using Sandbox endpoints, and if you are using live credentials, make certain to use the live endpoint.

Related

Cannot Verify Shopify Webhook

I have setup a webhook in shopify via settings > notifications > webhooks and entered a heroku app URL. My heroku app is in php and I run the verification function found here: https://shopify.dev/tutorials/manage-webhooks and when I open my app I get a blank response. I am not sure if this is something I am doing wrong on my heroku app, or if I am missing something. The goal here is to grab the json data after the event I have selected is ran, then to send that data to via third party api. But to start I just want to be able to verify that my heroku app is receiving the payload. Is there more I need to add to my php file in order to verify? (php noob here). Below is the code I am running in my php file, and yes I am using my shared secret found in the webhooks section.
<?php
define('SHOPIFY_APP_SECRET', 'my_shared_secret');
function verify_webhook($data, $hmac_header)
{
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
return hash_equals($hmac_header, $calculated_hmac);
}
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$data = file_get_contents('php://input');
$verified = verify_webhook($data, $hmac_header);
error_log('Webhook verified: '.var_export($verified, true)); //check error.log to see the result
?>
If I am not mistaken you cannot test webhooks that way as the admin does not use your API key as it has no idea who you are when in the admin. So if you have a heroku App and it has an API key, use that API key to first off establish the webhook, verify you created it with the API, and then sit around and test your actual endpoint with Shopify Admin itself. That is how it works AFAIK.
The other verification in the admin is mickey mouse and meant to just throw data at any old endpoint with no validation.

PHP verify Paypal webhook signature

I'm having trouble trying to verify paypal webhook signatures with PHP. Using the new V2 of paypals APIs I am receiving the paypal webhook on my page.
However I can not seem to successfully validate the signature.
From the link HERE I got some sample webhook validation PHP code from paypal.
I can not get it working, I don't know where I am supposed to get bootstrap.php from in the paypal code. The paypal information seems incomplete or half baked. Paypal seems to be terrible to set-up compared to Stripe.
Has anyone got experience of validating paypal webhook signatures with PHP when using V2 of the paypal APIs ?
Well I have come to the conclusion that the Paypal developer information is rather poor, it is scatted all over the place, on multiple different pages and sites. The examples they give on the paypal developer website HERE are not a complete picture of what is required to validate a webhook signature. Stripe developer documentation is much better formatted and concise.
Installing Paypal Checkout V2 SDK does not give you the necessary development tools to validate paypal webhook signatures i.e. you can process payments and receive webhooks but you can not validate the webhook signatures....I know stupid. Tip do not download the SDK directly as you will not include the required autoload.php file. Use composer to install Paypal Checkout V2 SDK so that you get the autoload.php file.
Once you are to a point that you can process payments and receive webhooks form paypal you need to install the another SKD called Paypal Rest API SDK. Again use composer to install the SDK so that you get a autoload.php file which you will need.
When you install Paypal Rest API SDK amazingly you will still be missing files that are required to validate the payapl webhook signatures. I can find no mention of these anywhere on the paypal developer website.
bootstrap.php & common.php
Thanks to #Grumpy I got some samples provided on github HERE
Note you will probably need to modify the samples a bit in order to get them working with your website. Tip set the logger to false and save yourself some bother if you don't have the necessary access permissions to write.
Once you have bootstrap.php & common.php files created you can write the code for your webhook endpoint page i.e. the page that paypal sends the webhook to. I have included my PHP code below for how to validate and then process the paypal webhook. Tip in the below code you need to specify the webhook ID, each webhook that you create in paypal has a unique ID. Also when you are testing you can not use webhook simulator as this will fail validation, you can make manually a payment with your sandbox account details which will trigger a webhook payment event.
Paypal sure don't make it easy, their documentation is all over the place compared to Stripe. The Paypal webhooks can sometimes take several minutes to arrive after a payment is made, very frustrating when trying to debug. Also it's a bit ridiculous that they have a webhook simulator on the paypal developer website that can not be used to validate signatures...if stripe can do it why can't paypal.
<?php
//get the webhook payload
$requestBody = file_get_contents('php://input');
//check if webhook payload has data
if($requestBody) {
//request body is set
} else {
//request body is not set
exit();
}
use \PayPal\Api\VerifyWebhookSignature;
use \PayPal\Api\WebhookEvent;
$apiContext = require __DIR__ . '/bootstrap.php';
//Receive HTTP headers that you received from PayPal webhook.
$headers = getallheaders();
//need header keys to be UPPERCASE
$headers = array_change_key_case($headers, CASE_UPPER);
/*
example header paypal signature content for webhook, these values are recieved as an array, we then need to use this data to verify the payload
CONTENT-LENGTH : 1376
CORRELATION-ID : 6db85170269e7
USER-AGENT : PayPal/AUHD-214.0-54377828
CONTENT-TYPE: application/json
PAYPAL-AUTH-ALGO : SHA256withRSA
PAYPAL-CERT-URL : https://api.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a784-5edc0ebc
PAYPAL-AUTH-VERSION : v2
PAYPAL-TRANSMISSION-SIG : Hc2lsDedYdSjOM4/t3T/ioAVQqFPNVB/AY/EyPNlavXk5WYUfnAmt9dyEP6neAPOjFHiVkXMK+JlLODbr6dalw6i26aFQdsPXqGl38Mafuu9elPE74qgsqNferUFgHi9QFXL+UZCNYcb4mvlDePXZIIAPbB0gOuFGOdEv2uqNwTCSAa/D8aguv1/51FWb3RkytFuVwXK/XNfIEy2oJCpDs8dgtYAZeojH8qO6IAwchdSpttMods5YfNBzT7oCoxO80hncVorBtjj1zQrkoynEB9WNNN9ytepNCkT8l29fQ4Sx/WRndm/PESCqxqmRoYJoiSosxYU3bZP7QTtILDykQ==
PAYPAL-TRANSMISSION-TIME : 2020-04-05T14:40:43Z
PAYPAL-TRANSMISSION-ID : 6dec99b0-774b-11ea-b306-c3ed128f0c4b
*/
//if any of the relevant paypal signature headers are not set exit()
if(
(!array_key_exists('PAYPAL-AUTH-ALGO', $headers)) ||
(!array_key_exists('PAYPAL-TRANSMISSION-ID', $headers)) ||
(!array_key_exists('PAYPAL-CERT-URL', $headers)) ||
(!array_key_exists('PAYPAL-TRANSMISSION-SIG', $headers)) ||
(!array_key_exists('PAYPAL-TRANSMISSION-TIME', $headers))
)
{
exit();
}
//specify the ID for the webhook that you have set up on the paypal developer website, each web hook that you create has a unique ID
$webhookID = "ENTER_YOUR_WEBHOOK_ID_HERE";
//start paypal webhook signature validation
$signatureVerification = new VerifyWebhookSignature();
$signatureVerification->setAuthAlgo($headers['PAYPAL-AUTH-ALGO']);
$signatureVerification->setTransmissionId($headers['PAYPAL-TRANSMISSION-ID']);
$signatureVerification->setCertUrl($headers['PAYPAL-CERT-URL']);
$signatureVerification->setWebhookId($webhookID);
$signatureVerification->setTransmissionSig($headers['PAYPAL-TRANSMISSION-SIG']);
$signatureVerification->setTransmissionTime($headers['PAYPAL-TRANSMISSION-TIME']);
$signatureVerification->setRequestBody($requestBody);
$request = clone $signatureVerification;
try {
$output = $signatureVerification->post($apiContext);
} catch (Exception $ex) {
//error during signature validation, capture error and exit
ResultPrinter::printError("Validate Received Webhook Event", "WebhookEvent", null, $request->toJSON(), $ex);
exit(1);
}
$sigVerificationResult = $output->getVerificationStatus();
// $sigVerificationResult is a string and will either be "SUCCESS" or "FAILURE"
//if not webhook signature failed validation exit
if($sigVerificationResult != "SUCCESS"){
exit();
}
else if($sigVerificationResult == "SUCCESS"){
//paypay webhook signature is valid
//proceed to process webhook payload
//decode raw request body
$requestBodyDecode = json_decode($requestBody);
//pull whatever info required from decoded request body, some examples below
$paymentSystemID = $requestBodyDecode->id;
$eventType = $requestBodyDecode->event_type;
//do something with info captured from the webhook payload
}
This seems to work with php 8.1:
if (openssl_verify(
data: implode(separator: '|', array: [
$httpPayPalTransmissionId,
$httpPayPalTransmissionTime,
$webhookID,
crc32(string: $rawRequestBody),
]),
signature: base64_decode(string: $httpPayPalTransmissionSignature),
public_key: openssl_pkey_get_public(public_key: file_get_contents(filename: $cachedHttpPayPalCertUrl)),
algorithm: 'sha256WithRSAEncryption'
) === 1) {
die('OK');
} else {
die('FAILED');
}

How to enable instamojo sandbox (test mode) Mode

I have integrated instamojo payment gateway in Codeigniter. I want to enable sandbox mode in instamojo payment gateway, i can not see any option to change mode to sandbox or test mode.Can anyone tell me how to change that.
Thank You in Advance.
The Instamojo class initializer accepts a third argument that can be used to specify the API URL, it defaults to: https://www.instamojo.com/api/1.1/
Hence for the test environment you can do:
$api = new Instamojo\Instamojo(
'[API_KEY]',
'[AUTH_TOKEN]',
'https://test.instamojo.com/api/1.1/');
Note that for this to work you'll have to create an account on https://test.instamojo.com first and also make sure you're using the credentials from https://test.instamojo.com/developers/.

How to get the token from a request done with Paypal rest-api-sdk-php library

I am using rest-api-sdk-php to make requests to Paypal. When I execute a request it looks something like this:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-74C74934GB935960F"
I need to retrieve the token that is used to sign the request.
Is there a method in the library to get this token?
Here's the PayPal REST API SDK c# code, you'll need to translate it to PHP.
Dictionary<String, String> sdkConfig = new Dictionary<String, String>();
sdkConfig.Add("mode", "sandbox"); // when you're live, change "sandbox" to "live"
String oAuthAccessTokenForPayPal
= new PayPal.OAuthTokenCredential(yourClientID, yourSecret,
sdkConfig).GetAccessToken();
PayPal calls your password your "secret".
https://developer.paypal.com/ ... you'll need a PayPal merchant account, and a pair of id/secret for sandbox testing and a second pair for when you go live.
also, each part of your PayPal code must be wrapped with try/catch if you want your code to be robust.

EBS payment gateway integration using PHP

i need to integrate ebs payment gateway. i am searching lot but i could find the solution.
Response is provided using POST method to the URL defined under ReturnURL parameter in the payment request. $response['ResponseCode'] == 0 means transaction successfully completed. Other than 0 value transactions failed. I can't find $response['ResponseCode'] == 0.
here my code
if(isset($_GET['DR'])) {
require('Rc43.php');
$DR = preg_replace("/\s/","+",$_GET['DR']);
$rc4 = new Crypt_RC4($secret_key);
$QueryString = base64_decode($DR);
$rc4->decrypt($QueryString);
$QueryString = split('&',$QueryString);
$response = array();
foreach($QueryString as $param){
$param = split('=',$param);
$response[$param[0]] = urldecode($param[1]);
}
}
I would understand how exactly the integration to EBC is done and look at one of the existing Broadleaf Payment modules as a template.
For example:
- Does EBC provide an API for direct server to server communication? (i.e. the Credit Card information is passed to your server and then relayed to the gateway? If so, take a look at http://docs.broadleafcommerce.org/curre ... odule.html
- Does EBC provide a mechanism for a Transparent Redirect or Silent Post? (i.e. the Credit Card form is sent directly to EBC thereby bypassing the merchant servers? If so, take a look at http://docs.broadleafcommerce.org/curre ... e.net.html
- Does EBC provide a mechanism for a Hosted Order Page? (i.e. you get redirected to EBC's servers to enter your credit card information. If so, take a look at http://docs.broadleafcommerce.org/curre ... odule.html)
The many different integration options that the Payment Gateway provides will determine how Broadleaf should integrate with it.
Hope that helps.
Reference : http://www.fetchflow.com/blog/authorize-net-invoicing

Categories