Assuming you're using Commerce and not Ubercart, I've done this before, and it can be done with the hooks provided.
https://drupalcommerce.org/developer-guide/utilizing-core-apis/writing-payment-method-module
Of course, you can write your own functions inside the .module file, or in an include defined in your .info file, but I would strongly recommend prefacing the function name with the module name so you don't have any naming conflicts. For example, if your module was named foobar, instead of function do_a_thing (), call it foobar_do_a_thing or even _foobar_do_a_thing (). These functions can be called from the hooks to do whatever you need.
Magento 2 is open source if you get the community version...but I very passionately and strongly urge you to not go down that path if you do not have experience with it as the learning curve is a pretty steep one. However it usually has a plugin for anything you could ever need, and you can create your own extensions/plugins/themes if you have the skill and time to learn.
Personally I have not worked with any of these other than Magento but they do seem to come up regularly when I ask questions about Magento.
You can use either Ubercart or Drupal Commerce. They bought have similar features. What you want to do is use the hooks in both modules to tie into your 3rd party site. Both modules have option to create your own payment gateway. The hooks will allow you to submit form details upon checkout to the 3rd party site and based on success/failure your custom payment gateway module would proceed or error out.
Here is an example of Ubercart custom payment gateway that someone did: http://nmc-codes.blogspot.com/2012/07/how-to-create-custom-ubercart-payment.html
Here is a guide on Drupal Commerce custom payment gateway: https://drupalcommerce.org/developer-guide/utilizing-core-apis/writing-payment-method-module
Good luck!
https://www.drupal.org/project/commerce
Essentially you can create products, that contain line items which could be your actual copy and pdf. You can control access with rules. Give users roles when they complete checkout to access content.
You'll want to learn and understand some of those thing by checking out a few of the tutorials/documentation on https://drupalcommerce.org/
Just fyi though, commerce in d8 is still fairly new. They are a solid team and so you'll have support but the module is definitely not an ultra stable release last time I checked. They could have made a ton of progress but I guess I am saying just be on the lookout for weird behavior and read the change logs closely.
Edit: if you check out commerce kickstart, it's a 'starter' distro for newer folks to build out on. They might have an example in there for you to copy. Not really sure but it's worth checking out.
You say the library is about currency conversion, why are you tackling currency formatting then?
The formatting is where your code has the most problems, since it incorrectly assumes that formatting is currency specific and not locale specific. I have an old blog post about this topic if you're curious to know more.
It took the Commerce Guys two years to make Drupal Commerce 2.x, despite experience creating Ubercart, Drupal Commerce 1, and building a zillion or so sites using the platform.
Check out Drupal Commerce. Like item fields will let you allow people to upload photos. Decent intro tutorial to providing customizations: https://drupalcommerce.org/videos/tutorials/customizable-products-pizza-store
We use WooCommerce and are very happy; worth the price. If you want to go completely free, check out Drupal Commerce ( https://drupalcommerce.org/ ) . You can install the Drupal Distribution (meaning it is the entire PHP stack with CMS and all modules) and be up and running in an hour. And it's free!
some tips here: https://drupalcommerce.org/site-builders-guide/paid-content
I haven't looked through it all but I think it's using Content Access Rules and ACL to grant access to protected content on a purchase
I stopped in on the right day! I'm no developer, so insight to this would be awesome! I posted a question on drupalcommerce.org, but I rarely see replies there.
Using 2 different examples, I threw together a simple module to change the commerce product dropdown selection to radios. What should I change to avoid notices and warnings from flooding watchdog on product pages with only one product? (See link for code/warning.)
I am assuming your default email that goes out once an order is completed goes through Mandrill ok?
What and when emails are sent is configured in the rules section (Should be under Configuration->Workflow->Rules). If you check the rules there, you should be able to clone the rule named "Send an order notification e-mail" and change the trigger rules and text for the emails according to what you need.
There is a tutorial on the Commerce Page here: https://drupalcommerce.org/user-guide/checkout-completion-rules
Does that do the trick? Let me know if I can help any further or if I totally misunderstood the question :)
Hmm, confusing. It is 19 months old, but still described as "a year". Looks like that one got no further than committing the .info file, so there is no actual code.
I'm just trying to understand how it all joins together - the commerce core, commerce payments, products etc. I'm guessing this is the site to provide that.
Commerce is very, very 'drupaly' which is why I prefer it to Ubercart, once you start poking around there is very little in commerce that is unique to it (really only carts/checkout widgets/payment). It uses entities for order and products and rules for almost all of it's logic/business rules.
Commerce is really a collection of modules, use commerce kickstart to see them all running in concert. You can also enable and disable them one by one to get an idea of what each does. Sometimes you don't need a cart, sometimes you don't need payment, etc. For the average (read non custom) commerce site you might need to write a rule or two using rules, create a node type for your product displays, populate you store with product entities and add any relevant fields to product or order entities....It's all very Drupal. I also wouldn't get too hung up on line items and stuff for displaying products (unless they work out of the box for you) commerce hooks right into views and you can leverage all of that power directly in this way.
The guys who maintain it have some useful resources https://drupalcommerce.org/developer-guide
Just remember that products and product displays are different things and you will do fine :P
Drupal vs Wordpress is like Android vs iPhone, they are both do essentially the same thing (run a site/cms) but how they go about doing that are very different. Wordpress is easy to use/learn and mostly the same across sites under the hood, just like an iPhone is, where as Drupal is basic, and requires additional plugins/customizations, just like android customization is usually performed by manufacturers of the device, but can also be customized further by the user to fit very specific needs and capabilities needed by more advanced users
bottom line Drupal is a swiss-army knife without any tools, and you decide what tools you want to put in with almost unlimited possibilities/design/combinations, but overall not quick/easy to do. Wordpress is also a swiss-army knife, but comes with all the tools most people need and is quick to setup and works great for simple sites, even more advanced sites (depending)
Want a great example of how powerful Drupal can be with numerous plugins? checkout Drupal Commerce
Drupal took me a long time to learn, but after designing my own CMS/shopping system years ago, it blows Wordpress out of the water in the right situations, I use both of them to this day, many more wordpress than Drupal, but Wordpress would never work for the Drupal sites