Last updated 4 minutes ago

PayPal Integration

Corrily saves which price was displayed to a given user for a given product, therefore the PayPal integration consists in retrieving this price, and sending it to PayPal to bill the customer in their local currency.

To retrieve a price use the /prices/get endpoint:

Get Price

user_id
string

Unique user identifier (required if ip is not specified)

ip
string

User IP address (required if country, user_id, or get_ip_from_request is not specified)

country
string

User two-letter country code (ISO 3166 alpha-2; required if ip is not specified)

ab
boolean

If set to true will enfore the ab flag. (If the ab flag is on the base price in the base currency, usually USD, will be returned.)

dev
boolean

Turn developement mode on/off. When set to false nothing will be stored by Corrily.

get_ip_from_request
boolean

For front-end calls, allows you to get the IP of the user from their request.

required
Array of objects (Product)

A list of product objects

The price next needs to be passed to PayPal. Notice how in the example below we overwrite the price of the monthly_plan, this is key for price optimization to be able to test different price points.

paypal.Buttons({
  createSubscription: function(data, actions) {
    return actions.subscription.create({
      "plan_id": "monthly_plan"
      "plan": {
        "billing_cycles": [
            {
                "sequence": 1,
                "total_cycles": 0,
                "pricing_scheme": {
                    "fixed_price": {
                        "value": "13.80",
                        "currency_code": "GBP"
                    }
                }
            }
        ]
    },
      }
    });
  },

  onApprove: function(data, actions) {
    alert('You have successfully created subscription ' + data.subscriptionID);
  }
}).render('#paypal-button-container');

An alternative way of integrating with PayPal is through multiple independent plans which represent different price points.

Copyright © Corrily 2020. All right reserved.