Skip to content

FastSpring/FsprgEmbeddedStoreWin

Repository files navigation

Introduction

FastSpring's embedded store consists of a controller with some integration points and WPF's WebBrowser control. It's thin and very flexible and lets you integrate FastSpring the way that fits best for your application.

To get an idea of how it works the SDK provides an example and a test application. FastSpring provides FsprgEmbeddedStore class library's source code as VisualStudio project. It's straight forward to integrate, eases debugging and gives you a better understanding of what happens behind the scenes. The test application requires Windows XP or higher. All source code is released under the MIT license. It is open to contributions and its use is unrestricted.

FsprgEmbeddedStore Class Library

The FsprgEmbeddedStore class library consists mainly out of the FsprgEmbeddedStore.Controller.

The FsprgEmbeddedStore.Controller controls the connected WebView (WebBrowser control). It provides functionality to load the store, to monitor the page loading progress and to test if the current connection is secure (https).

In addition, it has some integration points defined as events. It gives notification of the initial load of the store, the subsequent page loads and of order completion.

public class Controller : INotifyPropertyChanged {
    public WebBrowser WebView { get; set; };

    public event DidLoadStoreHandler DidLoadStore;
    public event DidLoadPageEventHandler DidLoadPage;
    public event DidReceiveOrderEventHandler DidReceiveOrder;
    public event PropertyChangedEventHandler PropertyChanged;

    public void LoadWithParameters(StoreParameters parameters);
    public void LoadWithContentsOfFile(string path);

    public bool IsLoading { get; };
    public bool IsSecure { get; };
}

How-to embed the class library

  1. Clone or fork our repository.
  2. Add FsprgEmbeddedStore project to your Solution (Add existing project ...)
  3. Add "FsprgEmbeddedStore" as reference (Add Reference ...)
  4. Drag "WebBrowser" control from Toolbox to the panel
  5. Read our Integration Guide to learn how to enable your store for FsprgEmbeddedStore requests.
  6. Code MainWindow.xaml.cs and adjust MainWindow.xaml. Example1 app is providing an example how to implement the MainWindow.xaml.cs in detail.

How-to provide a link to the web-store

Sometimes users prefer to use a web-store instead of an embedded-store. Use FsprgEmbeddedStore.StoreParameters to build the web-store URL and open it inside the default browser by using System.Diagnostics.Process.Start.

private void openInBrowserButton_MouseDown(object sender, MouseButtonEventArgs e) {
    StoreParameters parameters = new StoreParameters();
    parameters.OrderProcessType = OrderProcessType.Detail;
    parameters.StoreId = "your_store";
    parameters.ProductId = "your_product";
    parameters.Mode = Mode.Test;
    parameters.Language = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
    System.Diagnostics.Process.Start(parameters.ToURL.ToString());
}

Order API

The FsprgEmbeddedStore.Model.Order object represents the order confirmation returned via FsprgEmbeddedStore.Controller's DidReceiveOrder event. To spare you plunging through the source files the following sections contain a real-life example and a compressed API documentation of FsprgEmbeddedStore.Model.Order and its referred classes.

Example

Here's an example to show the most common case of grabbing a license number.

private void DidReceiveOrder(object sender, DidReceiveOrderEventArgs args) {
	foreach(OrderItem item in args.Order.OrderItems) {
	    if (item.ProductName.StartsWith("MyItemNamePrefix")) {
	        string name = item.License.LicenseName;
	        string serialNumber = item.License.FirstLicenseCode;
	        if (item.ProductName.ToLower().Contains("upgrade")) {
	            Console.Write("Upgrade purchase:\nName: {0}\nSerial #: {1}", name, serialNumber);
	        } else {
	            Console.Write("Full purchase:\nName: {0}\nSerial #: {1}", name, serialNumber);
	        }
	    }
	}
}

FsprgEmbeddedStore.Model.Order

bool OrderIsTest
string OrderReference
string OrderLanguage
string OrderCurrency
decimal OrderTotal
decimal OrderTotalUSD
string CustomerFirstName
string CustomerLastName
string CustomerCompany
string CustomerEmail

/// <summary>
/// Shortcut for OrderItems[0].
/// </summary>
OrderItem FirstOrderItem

OrderItem[] OrderItems

FsprgEmbeddedStore.Model.OrderItem

string ProductName
string ProductDisplay
decimal Quantity
decimal ItemTotal
decimal ItemTotalUSD

/// <summary>
/// This reference can be used to make calls to FastSpring's Subscription API.
/// See https://support.fastspring.com/entries/236487-api-subscriptions
/// </summary>
string SubscriptionReference

/// <summary>
/// This URL can be presented to the customer to manage their subscription.
/// </summary>
string SubscriptionCustomerURL

Fulfillment Fulfillment

/// <summary>
/// Shortcut for Fulfillment["license"].
/// </summary>
License License

/// <summary>
/// Shortcut for Fulfillment["download"].
/// </summary>
FileDownload FileDownload

FsprgEmbeddedStore.Model.Fulfillment

/// <summary>
/// Information about the fulfillment.
/// </summary>
/// <param name="key">key type of fulfillment (e.g. license, download)</param>
/// <returns>Specific fulfillment information (FsprgLicense, FsprgFileDownload).</returns>
object this[string key]

FsprgEmbeddedStore.Model.License

string LicenseName
string LicenseEmail
string LicenseCompany

/// <summary>
/// Shortcut for LicenseCodes[0].
/// </summary>
string FirstLicenseCode

string[] LicenseCodes
PlistDict LicensePropertyList
Uri LicenseURL

FsprgEmbeddedStore.Model.FileDownload

Uri FileURL

Example1

Example1 presents the FastSpring store in detail mode. After receiving the order a short thank-you-note and a button will appear. The button opens a dialog box containing license information.

Example1 Screenshot

How-to create Example1 application

  • Attach DidLoadStore and DidReceiveOrder event implementations
  • Set WebBrowser control to Controller.WebView
  • Provide Controller as DataContext to bind it inside MainWindow.xaml
  • Bind progress bar to IsLoading (Controller as DataContext) by using BooleanToVisiblityConverter
  • Bind lock image to IsSecure (Controller as DataContext) by using BooleanToVisiblityConverter

Extract from MainWindow.xaml.cs

public partial class MainWindow : Window {
	public MainWindow() {
	    InitializeComponent();

	    // set parameters
	    _parameters = new StoreParameters();
		...

	    // configure controller and provide it as DataContext to
	    // access IsLoading property from XAML
	    _controller = new Controller();
	    _controller.DidLoadStore += DidLoadStore;
	    _controller.DidReceiveOrder += DidReceiveOrder;
	    _controller.WebView = webBrowser;
	    DataContext = _controller;

	    // load store
	    _controller.LoadWithParameters(_parameters);
	}

	private void DidLoadStore(object sender, EventArgs args) {
        _receivedOrder = null;
    	...
	}
    private void DidReceiveOrder(object sender, DidReceiveOrderEventArgs args) {
        _receivedOrder = args.Order;
		...
    }
}

TestApp

The Test application lets you explore FastSpring's parameters and shows you the native order confirmation result (XML plist format).

TestApp Settings Screenshot  TestApp Results Screenshot

You can also store that confirmation result as a plist file and load it by using the FsprgEmbeddedStore.Controller's LoadWithContentsOfFile method. It simplifies the development and testing of the order confirmation view.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages