Tag Archives: Adaptive Payments

Unilateral receiver not allowed in chained payment is restricted – Adaptive Payment DotNet SDK

Hey everyone,

Just an error I ran into today while using the Adaptive Payments SDK for C#/.NET:

Unilateral receiver not allowed in chained payment is restricted

Thankfully this one is fairly simple – one of the receivers hasn’t confirmed their account.

http://stackoverflow.com/a/32816078/522859

This type of fee payer x isn’t recognized by our system – PayPal Adaptive Payments SDK

Hey everyone,

Just another Adaptive Payments SDK error I’ve run into.

Error Id: 560027
This type of fee payer x isn’t recognized by our system

This one is fairly self explanatory, valid values are as follows:

SENDER – Sender pays all fees (for personal, implicit simple/parallel payments; do not use for chained or unilateral payments)
PRIMARYRECEIVER – Primary receiver pays all fees (chained payments only)
EACHRECEIVER – Each receiver pays their own fee (default, personal and unilateral payments)
SECONDARYONLY – Secondary receivers pay all fees (use only for chained payments with one secondary receiver)

This parameter is described in the following documentation: https://developer.paypal.com/docs/classic/api/adaptive-payments/Pay_API_Operation/

Cannot parse *.config file – AdaptivePayments SDK (PayPal)

Hey everyone,

Just working on a small project that uses PayPal’s C# AdaptivePayments SDK. I hit an error while attempting to make the following payment:

var service = new AdaptivePaymentsService();
payResponse = service.Pay(payRequest);
“Cannot parse *.config file. Ensure you have configured the ‘paypal’ section correctly.”

at PayPal.Manager.ConfigManager..ctor()
at PayPal.Manager.ConfigManager.get_Instance()
at PayPal.BasePayPalService..ctor()
at PayPal.AdaptivePayments.AdaptivePaymentsService..ctor()

It turns out that you need to add the following entries to your Web.config:

<!-- Under configuration > configSections. Add the following entry -->
<section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK" requirePermission="false"></section>
 
<!-- Under configuration. Add the following entry and modify to suit your app -->
<paypal>    
    <settings>
      <add name="endpoint" value="https://svcs.sandbox.paypal.com/"/>
      <add name="AdaptivePayments" value="https://svcs.sandbox.paypal.com/"/>
      <add name="connectionTimeout" value="360000"/>
      <add name="requestRetries" value="3"/>
      <add name="IPAddress" value="127.0.0.1"/><!-- May need to change this depending on your configuration -->
    </settings>
    <accounts>
      <account apiUsername="xxx" apiPassword="xxx" apiSignature="xxx" applicationId="APP-80W284485P519543T"/>
    </accounts>
  </paypal>

To get the account information you’ll need to do the following:
– Go to developer.paypal.com
– Login to your sandbox account
– Go to the dashboard
– Select accounts (from the list of all your sandbox accounts)
– Create a new one or select an existing business account
– Click profile
– Click API Credentials

Note that the steps required to get this configuration seem to change all the time. Hopefully this will be enough to get you on the right track.

PayPal IPN Response Not Returning a pay_key Value

Hey everyone,

In order to verify that a pay response is legitimate, PayPal provides a unique token for each request. This token can then be matched against payment confirmation requests to ensure that they aren’t being spoofed. The problem I ran into was that even the legitimate IPNs I received did not contain a pay key.

It turns out that PayPal sends two different types of IPNs. The first is configured when making the API request. The second is configured in the PayPal account under “My Account > Profile > Instant PayPal Notification”.

The first type, includes the required PayKey, the second does not. Simply configure your profile details to point to another url and everything should work!

For more info, check out this stackoverflow post: http://stackoverflow.com/a/12031887/522859

Working IPN Handler with Parallel Payments – PayPal Adaptive Payments

Hey everyone,

Just a dummy implementation of a Parallel Payment and an accompanying IPN Handler using the C#/.NET SDK. Feel free to use it however you like.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//Handles PayPal IPN
        public String IPN()
        {
            //Post back to either sandbox or live
            string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            //string strLive = "https://www.paypal.com/cgi-bin/webscr";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
 
            ////Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(Request.ContentLength);
            string strRequest = Encoding.ASCII.GetString(param);
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;
 
            //Send the request to PayPal and get the response
            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
 
            if (strResponse == "VERIFIED")
            {
                //check the payment_status is Completed
                //check that txn_id has not been previously processed
                //check that receiver_email is your Primary PayPal email
                //check that payment_amount/payment_currency are correct
                //process payment
            }
            else if (strResponse == "INVALID")
            {
                //log for manual investigation
            }
            else
            {
                //log response/ipn data for manual investigation
            }
 
 
            return "";
        }
 
        //Pay for an order
        public void Pay(int OrderId)
        {
            RequestEnvelope envelopeRequest = new RequestEnvelope();
            envelopeRequest.errorLanguage = "en_US";
            PaySample paySample = new PaySample();
 
            List<Receiver> listReceiver = new List<Receiver>();
            // Amount to be credited to the receiver's account
            Receiver receiverA = new Receiver(Convert.ToDecimal("4.00"));
 
            // A receiver's email address
            receiverA.email = "test_buyer1@learnerlessons.com.au";
            listReceiver.Add(receiverA);
 
            // Amount to be credited to the receiver's account
            Receiver receiverB = new Receiver(Convert.ToDecimal("2.00"));
 
            // A receiver's email address
            receiverB.email = "test_buyer2@learnerlessons.com.au";
            listReceiver.Add(receiverB);
 
            ReceiverList receiverList = new ReceiverList(listReceiver);
 
            PayRequest requestPay = new PayRequest(envelopeRequest, "PAY", "http://localhost:53034/orders/cancel", "AUD", receiverList, "http://localhost:53034/orders/return");
            requestPay.reverseAllParallelPaymentsOnError = true;
            requestPay.ipnNotificationUrl = "http://123.123.123.123/Orders/IPN";
 
            //Send request to paypal, retrieve payKey
            PayResponse payResponse = paySample.PayAPIOperations(requestPay);
 
            Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=" + payResponse.payKey);
        }

Configuring Custom Settings – PayPal C# SDK

Hey everyone,

I’ve been mucking around with the C# SDK for PayPal Adaptive Payments. Unfortunately the docs aren’t too great and the samples are a little confusing until you get your head around them.

One of the main issues I’ve had is working out how to configure payment request settings i.e. reverseAllparallelPaymentsOnError.

To do this, simple utilise the PayRequest class:

1
2
PayRequest requestPay = new PayRequest(envelopeRequest, "PAY", "http://localhost:53034/orders/cancel", "AUD", receiverList, "http://localhost:53034/orders/return");
requestPay.reverseAllParallelPaymentsOnError = true;

Application ID – PayPal Sandbox

Hey everyone,

Just setting up an app that using the .NET Adaptive Payments SDK. Looking through the sandbox I was able to find the api signature, password and username but not the application ID (My Account > Overview > Account Information > API Access).

It turns out that ALL sandbox apps share the same ID:

Application ID: APP-80W284485P519543T

Paypal_Adaptive IPN Verification: INVALID – Ruby on Rails

Hey everyone,

I’ve been working with the PayPal_Adaptive gem recently and unfortunately I’ve run into a few issues. The latest of these has been that that my IPN verification was returning an INVALID response from Paypal.

I had made a few modifications to the provided payment_notification.rb file in order to accommodate for a few app specific requirements. This left me having to pass the original data attribute params. Unfortunately this wasn’t identical to the response that PayPal expected, I actually needed to use the following:

 
#Incorrect usage
verify_ipn(params)
 
#Correct usage
verify_ipn(request.raw_post)

I realised this error after reading Tanel’s post about securing your IPN interactions so make sure you check out his blog if you run into any more problems!

Thanks,
Chris

Paypal Platform Ruby SDK – Adaptive Payments

Hey everyone,

This is the SDK for PayPal adaptive payments. I’ve just uploaded it to *hopefully* make it a little easier to find. Please note that it has not been updated recently and that there are a few changes to be made. The StackOverflow post below provides a few examples:

StackOverflow Post:
Adaptive Payments with Ruby

I’ll try to list any others as I come across them, but if you’ve got some of your own please let me know and I’ll try to keep the post up to date.

Download SDK here:
Paypal Platform SDK


Error #1:

Internal Server Error
 
undefined method `debug_rjs=' for ActionView::Base:Class

Remove the following line from your development.rb config file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
PayPalPlatformRubySDK::Application.configure do
  # Settings specified here will take precedence over those in config/environment.rb
 
  # In the development environment your application's code is reloaded on
  # every request.  This slows down response time but is perfect for development
  # since you don't have to restart the webserver when you make code changes.
  config.cache_classes = false
 
  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true
 
  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  #config.action_view.debug_rjs             = true <---- Comment this line out (no longer supported)
  config.action_controller.perform_caching = false
 
  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = false
 
  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log
 
  # Only use best-standards-support built into browsers
  config.action_dispatch.best_standards_support = :builtin
end

Paypal IPN History:
For some reason the IPN history button often won’t appear in the sandbox, use the following link to view it:
https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_display-ipns-history

IPN Notifications:
Just a warning for anyone else setting up payments with PayPal, the sandbox IPN is extremely flaky. It has gone down twice in the last six months for weeks at a time, with no warning or error messages. If you’re not receiving the IPN check out the forums to make sure it’s not down.