Last active
June 24, 2019 17:33
-
-
Save adamski/7a4fcb91925fd9f73ae849842f918cbb to your computer and use it in GitHub Desktop.
Cross-platform C++ wrapper for the Paddle licensing SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
PaddleSetup.cpp | |
Created: 23 Sep 2017 9:15:20pm | |
Author: Adam Wilson | |
============================================================================== | |
*/ | |
#if defined(_WIN32) || defined(__CYGWIN__) | |
#include "PaddleSetup.h" | |
#include <iostream> | |
PaddleSetup::PaddleSetup (string apiKey, string productId, string vendorId) | |
{ | |
paddle = Paddle::initSharedInstance (apiKey.c_str(), productId.c_str(), vendorId.c_str()); | |
} | |
void PaddleSetup::startLicensing (string productName, string vendorName, float price, int trialLengthInDays, | |
string productImage, bool timeTrialLicense) | |
{ | |
//product name, vendor name, price (USD), trial length (days) | |
paddle->setProductData (productName.c_str(), vendorName.c_str(), (double) price, trialLengthInDays, productImage.c_str()); | |
cout << "setProductData, now startLicensing..."; | |
paddle->startLicencing (timeTrialLicense); | |
} | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
PaddleSetup.h | |
Created: 23 Sep 2017 9:16:38pm | |
Author: Adam Wilson | |
============================================================================== | |
*/ | |
#pragma once | |
#include <string> | |
#ifdef __APPLE__ | |
#include "TargetConditionals.h" | |
#else // Windows | |
typedef wchar_t* LPWSTR, *PWSTR; // Needed if not including Windows.h | |
#include "Paddle.h" | |
using namespace PaddleSDK; | |
#endif | |
using namespace std; | |
class PaddleSetup | |
{ | |
public: | |
PaddleSetup (string apiKey, string productId, string vendorId); | |
#if defined(__APPLE__) && defined(TARGET_OS_MAC) | |
void startLicensing (string productName, string vendorName, float price, int trialLengthInDays, | |
string currency, string imageURL, string trialText, string productImage, void* windowHandle, | |
bool timeTrialLicense = true); | |
#elif defined(_WIN32) || defined(__CYGWIN__) | |
void startLicensing (string productName, string vendorName, float price, int trialLengthInDays, string productImage, | |
bool timeTrialLicense = true); | |
private: | |
Paddle *paddle; | |
#endif | |
private: | |
// | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
PaddleSetup.mm | |
Created: 23 Sep 2017 9:15:20pm | |
Author: Adam Wilson | |
============================================================================== | |
*/ | |
#ifdef __APPLE__ | |
#include "TargetConditionals.h" | |
#if TARGET_OS_MAC && ! TARGET_OS_IPHONE | |
#include "PaddleSetup.h" | |
#import <Paddle/Paddle.h> | |
PaddleSetup::PaddleSetup (string apiKey, string productId, string vendorId) | |
{ | |
Paddle *paddle = [Paddle sharedInstance]; | |
[paddle setApiKey:@(apiKey.c_str())]; | |
[paddle setProductId:@(productId.c_str())]; | |
[paddle setVendorId:@(vendorId.c_str())]; | |
} | |
void PaddleSetup::startLicensing (string productName, | |
string vendorName, | |
float price, | |
int trialLengthInDays, | |
string currency, | |
string imageURL, | |
string trialText, | |
string productImage, | |
void *windowHandle, | |
bool timeTrialLicense) | |
{ | |
NSDictionary *productInfo = @{kPADCurrentPrice: [NSString stringWithFormat:@"%f", price], | |
kPADDevName: @(vendorName.c_str ()), | |
kPADCurrency: @(currency.c_str ()), | |
kPADProductName: @(productName.c_str ()), | |
kPADTrialDuration: [NSString stringWithFormat:@"%u", trialLengthInDays], | |
kPADTrialText: @(trialText.c_str ()), | |
kPADProductImage: @(productImage.c_str ())}; | |
if (!imageURL.empty()) [productInfo setValue:@(imageURL.c_str()) forKey:kPADImage]; | |
NSView* view = (NSView*) windowHandle; | |
[[Paddle sharedInstance] startLicensing:productInfo timeTrial:timeTrialLicense withWindow:view.window]; | |
} | |
#endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment