When I integrate Paytm payment gateway I downloaded Paytmkit. When I copied form code(TxnTest.php) and paste it on my coding page, then form code work perfectly but if I use some my input fields and then POST the value to (pgRedirect.php) and created Array as well then error is shown:
Checksum Mismatch Error.
under the <form> tag
<input type="text" title1="PRODUCT" name="PRODUCT" value="<?php echo $_POST['hidden_product'];?>">pro.PNG 3
Then I POST the value to (pgRedirect.php) -> $PRODUCT = $_POST['PRODUCT']; After that I create an Array to (pgRedirect.php) -> $paramList["PRODUCT"] = $PRODUCT;
Almost all payment providers require a checksum, created with the aid of a key they provide.
This checksum is usually simply a concatted string of all fields and their values, then pulled through the checksum hasher.
In the paytm documentation you can see the example here of the php implementation(Click the php tab)
https://developer.paytm.com/docs/checksum/#ValidateChecksum
In form post, create the checksumhash using your account's merchant key and all of the API request parameters.
* import checksum generation utility */
require_once("./PaytmChecksum.php");
/* initialize an array */
$paytmParams = array();
/* add parameters in Array */
$paytmParams["MID"] = "YOUR_MID_HERE";
$paytmParams["ORDERID"] = "YOUR_ORDERID_HERE";
/**
* Generate checksum by parameters we have
* Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
*/
$paytmChecksum = PaytmChecksum::generateSignature($paytmParams, 'YOUR_MERCHANT_KEY');
echo sprintf("generateSignature Returns: %s\n", $paytmChecksum);
So in short, make sure that all your $paytmParams are put in the correct array for the checksum computation. If you have extra fields that you submit, you need to add them to the array before computing the checksum.
Related
I am using wordpress to build a website that uses Stripe as its payment gateway.
Through the Paid Membership Pro plugin I have configured my Stripe connection.
The issue I am faced with is that I need to append a custom field, in this case a unique identifier for the customer, to the payment information for it to be available to send via my webhook to my server for processing.
I have come across a load of answers but none seem to be doing exactly what I am looking for.
I noticed in the PMPro plugin it allows you to add User Fields which I presumed would be a way to add custom data to the information but after checking the JSON payloads in Stripe none of the user field information is available.
I then tried adding the code from this answer to my functions.php file in word press just using a test meta key but again this information was not available in the payloads.
I am not using woocommerce.
How can I achieve this?
So I was able to crack this using a php script that intercepts the Stripe checkout event.
I added this as a snippet to my Wordpress site and to read in a custom field from the post submit.
Stripe allows you to add custom filed data to the metadata block and once populated this was successfully sent to my webhook.
function my_pmpro_stripe_params_send_user_id( $params, $order = null ) {
global $my_pmpro_checkout_order;
if ( empty( $params['metadata'] ) ) {
$params['metadata'] = array();
}
if ( empty ( $order ) ) {
// Save order while creating payment intent.
$order = $my_pmpro_checkout_order;
} else {
// Use saved order while creating subscription.
$my_pmpro_checkout_order = $order;
}
$params['metadata']['my_custom_field'] = $_POST['my_custom_value'];
return $params;
}
add_filter( 'pmpro_stripe_payment_intent_params', 'my_pmpro_stripe_params_send_user_id', 10, 2 );
add_filter( 'pmpro_stripe_create_subscription_array', 'my_pmpro_stripe_params_send_user_id', 10, 1 );
Here is theSDK of youcanpay payment gateway https://github.com/NextmediaMa/youcan-payment-php-sdk
I have followed the documentation described in the above link. And the payment form is displaying fine but I need to generate a token to proceed with the payments. But in the token generating step php not able to find youcanpay class intances which is used as static method
YouCanPay::setIsSandboxMode(true);. I simply want to be sure I didn't do anything wrong. May be there was an issue with my folder structure here it's screenshot https://i.imgur.com/uqdXgmr.png. Or I have to change php namcspace? use YouCan\Pay\YouCanPay;
Form display HTML
<div id="error-container"></div>
<div id="payment-card"></div>
<button id="pay">Pay</button>
** php **
use YouCan\Pay\YouCanPay;
class ExamplePayment
{
/**
* Return a token to make payment for an order, this token is required to make payment with JS script.
*
* #return string
*/
public function createToken()
{
// Enable sandbox mode, otherwise delete this line.
YouCanPay::setIsSandboxMode(true);
// Create a YouCan Pay instance, to retrieve your private and public keys login to your YouCan Pay account
// and go to Settings and open API Keys.
$youCanPay = YouCanPay::instance()->useKeys('pri_sandbox_56cfe571-f671-42a6-a231-d58ec', 'pub_sandbox_a62be70f-d585-4e88-9c5b-563f2');
// $youCanPay = YouCanPay::instance()->useKeys('pri_sandbox_56cfe571-f671-42a6-a231-d58ec', 'pub_sandbox_a62be70f-d585-4e88-9c5b-563f2');
// Data of the customer who wishes to make this purchase.
// Please keep these keys.
// Create the order you want to be paid
$token = $youCanPay->token->create(
// String orderId (required): Identifier of the order you want to be paid.
"order-id",
// Integer amount (required): The amount, Example: 25 USD is 2500.
"2000",
// String currency (required): Uppercase currency.
"USD",
// String customerIP (required): Customer Address IP.
"175.107.236.174",
// String successUrl (required): This URL is returned when the payment is successfully processed.
"https://smmpanelauto.com/orders-status/success",
// String errorUrl (required): This URL is returned when payment is invalid.
"https://smmpanelauto.com/orders-status/error"
);
echo $token->getId();
}
}
********** JS Code **********
<script type="text/javascript">
// Create a YouCan Pay instance.
const ycPay = new YCPay('pub_sandbox_a62be70f-d585-4e88-9c5b-563f2', {
formContainer: '#payment-card',
locale: 'en',
isSandbox: true,
errorContainer: '#error-container',
// token: 'token_x6gf0_....'
});
// render the form
ycPay.renderCreditCardForm();
// start the payment on button click
var el = document.getElementById('pay');
if(el){
<?php
$a = new ExamplePayment;
?>
el.addEventListener('click', function(){
// execute the payment
ycPay.pay("<?php $a->createToken(); ?>") //using token
.then(successCallback)
.catch(errorCallback);
});
}
function successCallback(response) {
console.log(rsponse);
}
function errorCallback(response) {
console.log(rsponse);
}
</script>
When I use <?php $a->createToken(); ?> the form is not showing. otherwise. it's shows the following error There are invalid fields in your request, please verify your inputs and try again But all inputs are filled.
When you call the createToken() method it causes the PHP fatal error, and the server responds with 500 HTTP status or the blank page. To see the exact error you may check the logs, of for the dev environment just add these lines in the beginning of the PHP code:
error_reporting(E_ALL);
ini_set('display_errors', 1)
So that all the PHP errors are sent to the output and displayed ob the page.
Looking into the file structure I assume all the PHP/HTML/JS code is located in the single index.php file. So make sure the YouCanPay SDK's file are included, i.e. you should have the line like this in the beginning if the file (or anywhere before teh actual usage of the YouCanPay class):
require_once 'vendor/autoload.php';
I want to send {contactfield=id} (one of the variable of the mautic) into custom headers for a mail that is to be used for a campaign. I am not sure of the right way to send it. I am keeping this variable into custom headers under Channels > Emails and selecting a particular email's advanced settings and into custom headers. This sets the id value of the first contact in the contact list of the segment selected for the campaign into all the remaining contacts. I want to get the dynamic value of each contact's id respectively. How can I get this appropriate result? Thanks in advance.
Last time I checked, not all of the fields in the Email builder can contain tokens. I remember that the Body and Subject allow it, but there were some other fields that did not allow it.
You seem to be getting the correct token, so if it's not returning in the header based on your testing, that field may not get parsed for tokenization on processing.
As pointed out by Jordan Ryan, not all tokens are available under email, however the email object can be tapped by creating a custom plugin.
https://developer.mautic.org/#extending-emails
check out this section, it may help.
The second example on code block shows that you can place your custom placeholder and then replace it programmatically.
/**
* Search and replace tokens with content
*
* #param EmailSendEvent $event
*/
public function onEmailGenerate(EmailSendEvent $event)
{
// Get content
$content = $event->getContent();
// Search and replace tokens
$content = str_replace('{hello}', 'world!', $content);
// Set updated content
$event->setContent($content);
}
I am currently building an ecommerce website that is used for 5 separate companies using woocommerce and authorize.net for the payment.
So far the authorization is working great for a single vendor, the issue comes in that once I have selected the vendor by location, I need to change the api_transaction_key and api_login_id to the correct vendor before payment is processed.
I have been searching the files for hours now and cannot find where the key and id are set.
Can someone help me find where I can overwrite the key and id values to what I need?
or would it be better to create a new payment gateway for each of the vendors and copy all of the authorize.net gateway information except the key and id?
This answer is here for if anyone is curious on how I was able to make this work.in the Authorize.net woocommerce payment gateway you'll find a file called
class-wc-authorize-net-cim-api.php
and it is in this file's contruct function that your hook needs to be placed.
public function __construct( $api_user_id, $api_transaction_key, $environment ) {
// File default code
}
This needs the follow three lines of code to be placed BEFORE the default file code
$custom_auth_info = apply_filters('get_custom_auth', $custom_auth_info );
$api_user_id = $custom_auth_info['api_user_id'];
$api_transaction_key = $custom_auth_info['api_transaction_key'];
The apply_filters refers to the following function that is placed in my plugin
add_filter('get_custom_auth', 'select_distributor_by_state');
function select_distributor_by_state($custom_auth_info = []) {
global $wpdb;
//Your Query is here to select the proper distributor from the DB
//and retrieve their custom Authorize.net ID and Transaction Key
$custom_auth_info['api_user_id'] = $your_query[0]['api_loginid'];
$custom_auth_info['api_transaction_key'] = $your_query[0]['api_transactionkey'];
$_SESSION['dealer'] = $vendor[0]['id'];
return $custom_auth_info;
}
This filter allows you to hook in, grab the data you need, then return it and apply it directly into the code before the payment is processed.
I'm using Stripe for a payment gateway. I can successfully obtain a card's "token" as Stripe calls it, which is explained here: https://stripe.com/docs/checkout#api
Good to go with that. I successfully receive the token in my stripe dashboard. Now what I need to do is actually charge that card(token). Here is how they put it: "You've got your user's credit card details, now what? Now you charge them money. This happens on your server, and the fastest way to do it is by using one of our client libraries." Well they supply the php needed right on that page:
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://manage.stripe.com/account
Stripe::setApiKey("sk_test_68YYnDTKPzcxxRZbkxEJtOVq");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = Stripe_Charge::create(array(
"amount" => 1000, // amount in cents, again
"currency" => "usd",
"card" => $token,
"description" => "payinguser#example.com")
);
} catch(Stripe_CardError $e) {
// The card has been declined
}
You can see exactly how they explain it here: https://stripe.com/docs/tutorials/charges
Here is where things go wrong.
1) Where in this code actually pinpoints what card to charge?! I have the card's token ID number in my private dashboard. I now need to charge it, but this code doesn't say anything about the card. The only spot I see is:
$token = $_POST['stripeToken'];
'stripeToken' do I put in the card's ID number here?
2)I've created a simple page to run this with:
<div id="payment">
<form action="charge-cards.php">
<?php require 'Stripe.php';?>
<input type="submit">
</form>
</div><!--end payment-->
"charge-cards.php" is the code at the top provided by Stripe. When I click submit, I get the follow error:
Fatal error: Class 'Stripe' not found in /home/preemin/public_html/fun.dit /testing/charge-cards.php on line 5
Can anyone see what I"m doing wrong? Thanks!
I think it's worthwhile to take a step back and review the basics. First, in order to provide a secure credit card transaction, and to ensure PCI compliance, Stripe has provided a javascript library that encrypts and transmits the sensitive credit card data. They provide an example form
Make careful note of the fact that the form has no submit action. Also pay special attention to the fact that none of the sensitive card fields have a name attribute. This form should never be submitted via any way other than the secure method they have provided. To try to do so opens you up to liability.
When you submit that form, using the js class they have provided (see Step 2), it gives you back a card token, which you say you already have. You can store that card token in your database without any security issues -- it's just an arbitrary number that means nothing to a hacker.
Once you have that token, you have two options:
use it immediately to make a one-time charge, or
store it and create a customer object that you can charge multiple times.
What you need to realize is that Stripe does NOT store that card token! If you lose it, you can't get it back. You have to generate a new one. Also, the only way you can use it for multiple charges is to create a customer object. In other words, UNLESS you store it on a customer object, it's only good for a single charge. So if you charge against it before attaching it to a customer object, it's no longer valid.
Now back to the basics again, as IOIO MAD described, there are two things you must do at the top of any php file that you want to call a Stripe method from:
include the Stripe php library
set the secret key
The only time the public key is used is when you're making that javascript call to submit the card form.
If you want to charge the card immediately, you have to turn right around and make a call back to the server, sending the card hash that you just got back. You might do this with ajax, or by sticking it in a form field that you then post. Step 3 shows you one way you might do this.
But lets assume that you want to do other things before actually charging the card. To expand on your example, lets say I have collected my customer's card on one page, then on my checkout page, I want to submit the charge:
<?php
require('path/to/Stripe.php'); // MUST be done before any Stripe:: call
Stripe::setApiKey("sk_test_mkGsLqEW6SLnZa487HYfJVLf");
// retrieve stored card hash. Could have got it to this page in any number of
// ways, including: stored in cookie, stored in session, stored in database.
// Let's assume stored in session for sake of simplicity of example
$cardHash = $_SESSION['stripeToken'];
?>
<div id="payment">
<form action="charge-cards.php">
<?php require 'Stripe.php';?>
<input name="stripeToken" type="hidden" value="<?= $cardHash ?>" />
<input type="submit">
</form>
</div>
When this form is submitted, charge-cards.php will get the $cardHash from the $_POST variable, whereupon you're going to follow the example given by Stripe:
<?php
require('path/to/Stripe.php'); // MUST be done before any Stripe:: call
Stripe::setApiKey("sk_test_mkGsLqEW6SLnZa487HYfJVLf");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = Stripe_Charge::create(array(
"amount" => 1000, // amount in cents, again
"currency" => "usd",
"card" => $token,
"description" => "payinguser#example.com")
);
} catch(Stripe_CardError $e) {
// The card has been declined
}
?>
If you're still having problems, employ proper debugging skills to check whether or not your $_POST variable contains a card hash. If all else fails, contact Stripe customer support. Their API is top-notch, as is their documentation and support.
EDIT 4/15/13
OP is using the quick checkout method and using custom buttons. Most of the above still applies.
The code outlined in the Custom Buttons section assigns a click handler to the custom button, which returns a callback function that when executed, appends a hidden input to a form, assigns the stripeToken to that field, and submits the form. Just before the form is submitted, console.log or alert the stripeToken to make sure you have a legitimate value:
$('#customButton').click(function(){
var token = function(res){
var $input = $('<input type=hidden name=stripeToken />').val(res.id);
// alert the value of stripeToken
alert('stripeToken = ' + res.id);
$('form').append($input).submit();
};
This would be used in conjunction with this:
<form action="/charge" method="post">
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="pk_test_yourprivatekeyhere"></script>
</form>
So what should happen is after the user presses the checkout button, the form should have a hidden input field named 'stripeToken' which contains the token value. You can get that token from the form and submit it later. Alternatively, you can listen on the 'token' event, which will be bound to your button:
jQuery(function($){
var $button = $('#customButton');
$button.on('token', function(e, token){
$button.after('<hr /><p>Your Stripe token is: <strong>' + token.id + '</strong></p>');
});
});
DISCLAIMER: I haven't used the simple checkout method yet. This code is not tested
i think may be you are missing some "include" , Class 'Stripe' not found means that the PHP File consisting of Class 'Stripe' haven't included before the call#
Note : A PHP >= 5.2 environment is required
Download The Stripe PHP library
Extract it to your HOME!
Let’s create a file called config.php, where we’re going to set up some initial configuration.
<?php
require_once('./lib/Stripe.php');
$stripe = array(
"secret_key" => "sk_test_mkGsLqEW6SLnZa487HYfJVLf",
"publishable_key" => "pk_test_czwzkTp2tactuLOEOqbMTRzG"
);
Stripe::setApiKey($stripe['secret_key']);
?>
Then at your Code file ABOVE (assumes yours.php)
include "config.php";
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
//rest as you go!