How Do I Integrate Paypal, Gravity Forms And Wishlist? - paypal

First off, I'm by no means a programmer so this might be a very simple issue but I'm about to pull my hair out soon.
So, I have a site where I'm selling a book + access to a membership through Wishlist Member. It sells for $99 and now I want to give them a $9 trial for 30 days and then bill them the remaining $90 over 2 installments of $45 each with a month apart.
Now, integrating Wishlist with PP is easy to setup when I'm only sending people straight to PayPal.
It basically only requires 3 steps besides activating IPN and pasting in the PDT.
Add the item/subscription ID of my Wishlist Membership Level to the PayPal button I'm creating.
Make sure the thank you page URL after purchase is:
site.com/members/index.php/register/AOKmfa
Paste the code below in the "Add advanced variables" field:
rm=2
bn=WishListProducts_SP
notify_url=site.com/members/index.php/register/AOKmfa
return=site.com/members/index.php/register/AOKmfa
Now I'm looking to increase the sign up rate so I am creating my own order page with Gravity Forms Paypal-Add on.
In there you have an option to set the thank you page, so in my case I would add "site.com/members/index.php/register/AOKmfa" and then I can also tick a box that says:
"Pass Field Data Via Query String" where I'm apparently suppose to paste in the code:
rm=2
bn=WishListProducts_SP
notify_url=site.com/members/index.php/register/AOKmfa
return=site.com/members/index.php/register/AOKmfa
But, my question is... how can I get this subscription ID involved?!
After speaking to Gravity Form support they said:
To pass additional info to PayPal you can use gform_paypal_query filter. You adapt this code to suit your needs.
add_filter('gform_paypal_query', 'add_more_information', 10, 3);
function add_more_information($query_string, $form, $entry) {
// break the query string into an array
// after removing the initial '&' character
parse_str(ltrim($query_string, '&'), $query);
// add information to query string. These currently exist
/*
[METHOD]
[VERSION]
[PWD]
[USER]
[SIGNATURE]
[BUTTONSOURCE]
[CREDITCARDTYPE]
[ACCT]
[EXPDATE]
[CVV2]
[STREET]
[STREET2]
[CITY]
[STATE]
[ZIP]
[COUNTRYCODE]
[CURRENCYCODE]
[FIRSTNAME]
[LASTNAME]
[EMAIL]
[DESC]
[L_NAME0]
[L_DESC0]
[L_AMT0]
[L_NUMBER0]
[L_QTY0]
[PAYMENTACTION]
[IPADDRESS]
[RETURNFMFDETAILS]
[AMT]
[NOTIFYURL]
*/
// change SHIPTONAME to whatever query string parameter you want to set
// and change the inputs here to whatever field holds your item title.
$query['L_DESC0'] = rgpost("input_6_13");
// put it all back together again
$query_string = '&' . http_build_query($query);
return $query_string;
}
So my question is, how can I adapt that code to actually get this integration to work? They are clearly not interested in pinpointing exactly how I would go about doing it so maybe one of you can?
Do I only need to adapt the code so it somehow adds in that subscription ID? (If so, how?) Or do I also need to add in the redirect url and the advanced variable field?
I truly appreciate any kind of help you can give me and if this should be posted elsewhere please let me know.
Thanks,
Tony

Related

PayPal PDT not returning Custom Message url parameter "cm" properly

I have multiple websites that use PayPal Buy Now buttons and have PDT enabled.
All of the existing customer websites are working, in that after the user makes a purchase, they are redirected back to their site by PayPal with a return URL that includes the 'cm' parameter as specified here.
I have a new client with a brand new Merchant Account who has their PDT configured correctly (I have checked it multiple times to be sure). However, upon return from PayPal payment, we are missing the 'cm' parameter that is necessary to do validation/updates on our website.
I have never seen this before where some of the variables are getting sent back, but not all as defined in the PayPal documentation above.
Here is an example of a working return URL - (some values edited for privacy purposes only)
.../paypal/pdt?redirect=https://journals.myclient.com/view/journals/cssm/4/1/article-p14.xml?PFTxId=4435&offerProvider=DEFAULT&amt=9.95&cc=USD&cm=mJ5v4sm1PUcD0E9vbii0pm6e1ql5GRs/lv+aQuNuves=%7CaccountId=XXXXX%7COffer ID=7|mc_gross=9.95&item_name=ITEM NAME Dilemma&item_number=/journals/cssm/4/1/article-p14.xml&st=Completed&tx=XXXXXXXXXXXX
Here is the example of the newly created Merchant Account where this is not working
.../paypal/pdt?redirect=https://www.nonworkingclient.org/view/journals/tpmd/s1-1/6/article-p331.xml?PFTxId=40&offerProvider=DEFAULT&PayerID=RPUJELM94HEYU&st=Completed&tx=XXXXXXXXXX&cc=USD&amt=0.01
Here you can see in the comparison, PayPal is returning the 'tx' and 'cc' variables in both examples, but 'cm' is missing from the bottom example.
Has anyone else experienced this lately?
Does anyone know of anything more than the PDT setup that needs to be checked to see why this is failing in the Merchant Account?
Thank you for any assistance.
I have an account that has been set up and working for 3+ years. PDT always returned a "cm" parameter which I pass in as "custom". In the last couple weeks it is hit or miss whether I get "cm" back (can't say exactly when it stopped working as the site has not been used since Spring 2020). About 10% of the time it works but the other 90% no "cm". The response is a bit different in the success and failure cases. Here is an example of a successful return with "cm" (the output is the GET array parameters and values)
(
[feepaid] => Y
[amt] => 75.00
[cc] => USD
[cm] => 586
[item_name] => IW***** Fee
[item_number] => g**5
[st] => Completed
[tx] => 9J5******81R
)
and an example of a failure case (no "cm")
(
[feepaid] => Y
[PayerID] => 9J*******YG
[st] => Completed
[tx] => 3D2*****2457
[cc] => USD
[amt] => 75.00
)
The failure has "PayerID" which does not appear as a valid variable in PDT or IPN spec. Success case has no PayerID but has item_name and item_number (which are fixed in the button definition on PayPal merchant account).
Same here! Paypal no longer return cm paramater for some users

Paypal REST SDK - Billing Plans no longer retrievable after being made ACTIVE

So I'm using the Paypal PHP SDK on Github, http://paypal.github.io/PayPal-PHP-SDK/ . Some strange behavior I've noticed which I'm not sure what's going on.
So let's say I create a billing plan, but don't touch it after creation, so that the state is simple CREATED. Everything is good, I can retrieve it from the list of plans. However, the moment I change the state to ACTIVE via a patch, I can see that it is in fact active, but only just once. Any subsequent attempts to see the list of plans no longer shows that plan. What's going on? I'm literally copy pasting the example source they give.
Edit - just to expand, I know the plan still exists, because I can subscribe users to it. Weirdly the paypal page where you click ok to subscribe is extremely non verbose... doesn't even say what the price is, just to approve paying my store. And yet the Agreement object that is returned by PayPal, which includes the approval url, has all this info. Weird.
If you are using the PayPal-PHP-SDK, you could assign more parameters to Plan::all() method.
As shown in the List Plan sample code, you could pass parameter 'status' as :
try {
// Get the list of all plans
// You can modify different params to change the return list.
// The explanation about each pagination information could be found here
// at https://developer.paypal.com/webapps/developer/docs/api/#list-plans
$params = array('page_size' => '20', 'page' => '98', 'status' => 'ACTIVE');
$planList = Plan::all($params, $apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("List of Plans", "Plan", null, $params, $ex);
exit(1);
}
As in the case, you could change the status, and page along with page_size. This will help you get the active list of plans.
Actually, by default the list plan status is defaulted to CREATED.

Modifying email templates for Navision 5.0

I've been asked to help do some much needed updates to Microsoft Dynamics NAV 5.0 (yes its old) and they want me to update some of their email templates for sales orders, etc. One of the things they want me to do is update the 'From' field to be a group email box instead of the current user, which I didn't think about be too difficult, but figuring out how NAV creates emails has been less than simple.
This article had some information, but didn't get me all the way there:
http://www.dynamics101.com/2014/02/sending-customized-emails-dynamics-nav/
I've found the Sales Header table which has lots of fields...none of which include "From". I found one field called "Assigned User" which points to the User Setup.
Do you mean the mails that are sent on the event of sales order approval / rejection or that small 'New Mail Message' button in the Customer card? Libraries that are used in these cases are different, and they rely on different automation objects to create e-mail messages.
Anyway, in both cases there is no setup to change the 'From' field - you'll have to customize it a bit.
First of all, you'll need a new field in a setup table to store the e-mail address. Table 'User Setup' is probably the best place, but it depends on the task, of course. Suppose, it is Uset Setup, and you call the new field 'FromAddress'
When you click on the e-mail button in the Customer card, 'Create Mail' wizard is run (Form 5148 'Create Mail'). It calls the function 'NewMessage' in codeunit 397. So, codeunit 397 'Mail', is what you are looking for. To change the 'From' address you need to set the property 'SentOnBehalfOfName' in the OSendMail object.
UserSetup.GET(USERID);
OSendMail.SentOnBehalfOfName(UserSetup.FromAddress);
If the message you want to change is the document approval notification, e-mail message is created in the codeunit 400 'SMTP Mail', but all fields are set up in the codeunit 440 'Approvals Mgt Notification', functions SetTemplate and GetEmailAddress. It is GetEmailAddress that sets the sender address. You need to replace this line of code:
SenderAddress := UserSetup."E-Mail";
with the new one
SenderAddress := UserSetup.FromAddress;
But be careful - this change will affect all templates and all users. If you need to change some templates while leaving other untouched, it is safer to redefine the value of this variable in a function responsible for the particular template. But again, it's all in codeunit 440.

do i need to validate select/option in drupal 7 form

I am creating my first drupal form and i am wondering if its needed to validate the select options? here is the form element
$form['page1']['color']=array(
'#type'=>'select',
'#title'=>t('Select Transmission'),
'#empty_value' => '',
'#options' => $color_options,
'#required'=>TRUE,
'#default_value' => !empty($form_state['values']['color']) ? $form_state['values']['color'] : '',
);
so since drupal have the hidden fields for security can i trust that this form is always sent unaltered from my website?
thanks
Michael
You don't need to validate the select options. Drupal will take care of it for you. If a user tries to alter the value of a option (that is not one of a key or your $color_options array) with Firebug (or whatever), he will get the message "An illegal choice has been detected. Please contact the site administrator." from Drupal.
Furthermore, you don't need to set a value from "$form_state" for the "#default_value" key. Just put one of the key of the "$color_options" for instance or don't use the key at all if you don't need a default value.

Paypal IPN currency & response

I am using a paypal ipn script i found here
http://coderzone.org/library/PHP-PayPal-Instant-Payment-Notification-IPN_1099.htm
I am aware that I can send information to paypal and get a response. It states I can get the information back using $_POST . My query is how do I specify the UK currency?
Also wanted to clarify a minor point. Am I correct that this is how i can confirm it was a success.
if ($_POST['payment_status'] == 'completed')
// Received Payment!
// $_POST['custom'] is order id and has been paid for.
}
This might be a little late for you sorry, but just in case - I currently use "currencyCode" = > "AUD" and it is working in the sandbox.
There's a full list of the currency codes available at PayPal
For yours, I'm guessing it would be:
$p->add_field('currencyCode', 'GBP');
As for your question about the IPN itself, it looks like you're on the right track. It will depend on the data you're getting back and whether you're interested in the individual transactions (if using adaptive payments) or if you're reversing them all on error etc. The easiest way to determine what you'll need to do is to simply display or log all the post data so you can see how it's constructed.
You'll also need to set it up so that the script is accessible by PayPal. You'll then pass the full URL of this script to the "notify_url" parameter and send it off to PayPal. Once the payment has completed PayPal will send a bunch of information to your script so that you can process it.
Unfortunately I'm not from a PHP background so I can't give you the exact code you'll need. Also note that there are a lot of security issues that you'll want to look into before going to a production environment. Not sure if you already intend to do this with that validateIPN function, but you need to ensure that you can tell whether it comes from PayPal and not a malicious user. One way would be to pass a value using the custom attribute and have PayPal pass this back to you, however you'd be much better off using the API certificates etc.
If you haven't already, it may be worth checking out a few of the sample applications PayPal has done up, there seem to be quite a few PHP ones.
Let me know if you need anything else,
Use this, it works for me
$p->add_field('currency_code', 'GBP');
You need to use PayPal Adaptive Payments, IPN wouldn't help.
PayPal Adaptive Payments
Using PayPal PHP library then it could look like this:
// Create an instance, you'll make all the necessary requests through this
// object, if you digged through the code, you'll notice an AdaptivePaymentsProxy class
// wich has in it all of the classes corresponding to every object mentioned on the
// documentation of the API
$ap = new AdaptivePayments();
// Our request envelope
$requestEnvelope = new RequestEnvelope();
$requestEnvelope->detailLevel = 0;
$requestEnvelope->errorLanguage = 'en_GB';
// Our base amount, in other words the currency we want to convert to
// other currency type. It's very straighforward, just have a public
// prop. to hold de amount and the current code.
$baseAmountList = new CurrencyList();
$baseAmountList->currency = array( 'amount' => $this->amount, 'code' => 'GBP' );
// Our target currency type. Given that I'm from Mexico I would like to
// see it in mexican pesos. Again, just need to provide the code of the
// currency. On the docs you'll have access to the complete list of codes
$convertToCurrencyListUSD = new CurrencyCodeList();
$convertToCurrencyListUSD->currencyCode = 'USD';
// Now create a instance of the ConvertCurrencyRequest object, which is
// the one necessary to handle this request.
// This object takes as parameters the ones we previously created, which
// are our base currency, our target currency, and the req. envelop
$ccReq = new ConvertCurrencyRequest();
$ccReq->baseAmountList = $baseAmountList;
$ccReq->convertToCurrencyList = $convertToCurrencyListUSD;
$ccReq->requestEnvelope = $requestEnvelope;
// And finally we call the ConvertCurrency method on our AdaptivePayment object,
// and assign whatever result we get to our variable
$resultUSD = $ap->ConvertCurrency($ccReq);
$convertToCurrencyListUSD->currencyCode = 'EUR';
$resultEUR = $ap->ConvertCurrency($ccReq);
// Given that our result should be a ConvertCurrencyResponse object, we can
// look into its properties for further display/processing purposes
$resultingCurrencyListUSD = $resultUSD->estimatedAmountTable->currencyConversionList;
$resultingCurrencyListEUR = $resultEUR->estimatedAmountTable->currencyConversionList;