Searched for : consolas

You will learn how to create a Payment Method Service, which integrates uCommerce with an online payment processer such as Sage, DIBS, PayPal, Cyber Source, or another processor used during checkout. This information is based onuCommerce 1.0.3.x and 1.0.3.2.

Create Visual Studio Project

Create a new Visual Studio solution and choose Class Library for your project type.

 Project structure - File Explorer

 

Add References to Your Project

uCommerce.dll

uCommerce.Infrastructure.dll

Subsonic.Core.dll

VS add reference select UC assemblies

Import Namespaces

Import the UCommerce.Transactions.Payment and UCommerce.Entities namespaces in you class file

Import namespaces

Implement interface IPaymentMethodService on your class

The IPaymentMethodService interface gives you full control over the behavior of the service. Alternatively you can inherit from AbstractPaymentService, which gives a default implementation for ProcessPaymentRequest, which will give you a properly initialized Payment.

Implement interface 

Implement interface 2

Implement Name property

The name property is used to uniquely identify your Payment Method Service. It is read from configuration and set on your service at runtime.

public class MyPaymentService : IPaymentMethodService
{
    public string Name { get; set; }    
}

Implement RequestPayment(PaymentRequest)

RequestPayment can be used in one of two ways: 1) Either to redirect the customer to the remote server handling payment information there, e.g. credit card information, or 2) to simply send payment information received on your server directly to the provider.

1)

public Payment RequestPayment(PaymentRequest request) 
{ 
    // Package up information for the backend service, 
    // in the form of a http request 
    // Redirect customer to backend service with 
    // the needed information 
    // Payment would be set pending authorization status (the status will have to be added to the uCommerce_PaymentStatus table) 
}

2)

public Payment RequestPayment(PaymentRequest request)
{
    // Processing is happening synchronously so we just
    // call the backend service with ProcessPaymentRequest
    return ProcessPaymentRequest(request);
}

Implement ProcessPaymentRequest(PaymentRequest)

ProcessPaymentRequest is used to handle any processing before or callbacks from the remote server in the case of a payment processing being handled exclusively by a remote party.

1) In the case of a callback scenario you use ProcessPaymentRequest to handle the callback and do any needed processing like updating order status. To receive the callback an endpoint needs to be exposed to the remote party such an http handler or a module. The handler or module will call ProcessPaymentRequest to complete the payment.

public Payment ProcessPaymentRequest(PaymentRequest request)
{
// Update payment according to received status from remote 
// party, e.g. Accepted, Declined
 
// Grab any transaction ids and put them on the payment before 
// returning the Payment
}

2) For a synchronous scenario ProcessPaymentRequest would be used to perform the query to the backing system and create a new Payment according to the result received.

public Payment RequestPayment(PaymentRequest request) 
{ 
    // Package up information for the backend service, 
    // in the form of a http request 
    // Redirect customer to backend service with 
    // the needed information 
    // Payment would be set pending authorization status 
}

Implement AcquirePayment(Payment)

For legal reason you sually can’t withdraw money from the customer until you actually ship their order. AcquirePayment is ment for this very scenario where you first authorize the payment and later withdraw from their account.

AcquirePayment(Payment) is used for capturing the payment from the customer.

public Payment ProcessPaymentRequest(PaymentRequest request)
{
    // Send request to remote party
 
    // Update payment according to received status from remote 
    // party, e.g. Accepted, Declined
 
    // Grab any transaction ids and put them on the payment before 
    // returning the Payment
}

Implement CancelPayment(Payment)

If you wish to cancel af payment with your payment method service you need to implement CancelPayment, and have it reach out the remote payment processor. Typical scenarios for cancelling a payment includes a customer return, cancelled order and typically requires you to handle two scenarios: Payment authorized but not capture and payment authorized and captured.

public Payment CancelPayment(Payment payment)
{
    // Update payment according to received status from remote 
    // party, e.g. Cancelled
 
    // Grab any transaction ids and put them on the payment before 
    // returning the Payment
}

Implement CalculatePaymentFee(PaymentRequest)

If applicable, used for calculating the fee associated with the payment method.

public virtual Money CalculatePaymentFee(PaymentRequest request)
{
    var order = request.PurchaseOrder;
    var paymentMethod = request.PaymentMethod;
 
    var fee = paymentMethod.GetFeeForCurrency(order.BillingCurrency);
 
    if (!order.SubTotal.HasValue)
        return new Money(0, 
new CultureInfo(Globalization.CultureCode), order.BillingCurrency);
 
    return new Money(order.SubTotal.Value 
        * (paymentMethod.FeePercent / 100) 
        + fee.Fee, 
new CultureInfo(Globalization.CultureCode), order.BillingCurrency);
}

Optionally Implement IPaymentFactory Interface on Your Provider

With uCommerce 1.0.3.2 the option for deferred payment requests was introduced meaning that you can create a payment placeholder for the choices made by a user and then later perform the actual payment request to the backend service.

If you need this functionality your PaymentMethodService should implement the interface IPaymentFactory (new for version 1.0.3.2), which will be used for creating the new Payment.

/// <summary>
/// Creates a new payment fully initialized
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public Payment CreatePayment(PaymentRequest request)
{
    PurchaseOrder order = request.PurchaseOrder;
 
    var payment = new Payment
    {
        TransactionId = Guid.NewGuid().ToString(),
        OrderId = order.OrderId,
        PaymentMethodName = GetPaymentName(request.PaymentMethod),
        Created = DateTime.Now,
        PaymentMethodId = request.PaymentMethod.PaymentMethodId,
        Fee = CalculatePaymentFee(request).Value,
        FeePercentage = request.PaymentMethod.FeePercent,
        PaymentStatusId = 1, // Status new
        Amount = request.Amount.Value
    };
 
    return payment;
}

Copy Your Assembly to Your Umbraco Site

Copy MyUCommerceApp.Library.dll to the /bin folder of your Umbraco site.

Add Your Payment Method Service to web.config

Configure your new Payment Method Service in web.config of your Umbraco site. In the <paymentMethodServices> element of you web.config add the following xml:

<add name="MyPaymentMethodService" type="MyUCommerceApp.Library.MyPaymentMethodService, MyUCommerceApp.Library" />

image 

Configure Payment Method to Use Your Service

Configure Payment Method to use your new service in uCommerce Backoffice.

Configure Payment Method to use PaymentMethodService - 2 

Execute Your Payment Method Service from Commerce XSLT Library

You have two options when you need to carry out your payment request: Either create and request a payment in one go by or do a two step request whereby you create a payment, but defer the actual request of the payment to backend service to a later time.

Please note that the two-step request is only available with uCommerce 1.0.3.2 or newer.

Typically the two step approach is used when you’re dealing with a redirect scenario in which part of the payment authorization happens on a remote server.

For a single step request, you'll use this XSLT extension:

<xsl:variable name="result" select="CommerceLibrary:CreatePayment($paymentMethodId, -1, true(), true())"></xsl:variable>

or the version with no amount argument, which will default to the SubTotal of the PurchaseOrder, i.e. use this if you only accept one payment per purchase order.

If you need the two step version you’ll use a couple of extensions. First the one which creates a payment for you and second an extension, which performs the request. Please note that your PaymentMethodService must implemention IPaymentFactory for this to work.

// -1 is a convenience which will tell uCommerce to grab the total of the order for the payment
// The first bool parameter indicates whether to perform the payment request
// The second bool parameter will overwrite existing payments if set to true (a way to avoid duplicates)
<xsl:variable name="result" select="CommerceLibrary:CreatePayment($paymentMethodId, -1, false(), true())"/>

The uCommerce Store executes CreatePayment in the macro called UpdatePayment[XSLT].

To perform the payment request you’ll execute:

// Perform request payment for all payments associated with the basket
<xsl:variable name="paymentResult" select="CommerceLibrary:RequestPayments()"/>
 
- or -
 
// Perform request payment for a single payment
<xsl:variable name="paymentResult" select="CommerceLibrary:RequestPayment(paymentId)"/>

Execute Your Payment Method Service from .NET

To execute your Payment Service directly from .NET code you use the following snippet:

public void ExecutePaymentMethodService(PaymentMethod paymentMethod, 
    PurchaseOrder purchaseOrder, decimal amount)
{
 
    var cultureInfo = new CultureInfo(Globalization.CultureCode);
 
    // Create a new payment request to 
    var paymentRequest = new PaymentRequest(
                purchaseOrder,
                paymentMethod,
                new Money(
                    amount,
                    cultureInfo,
                    purchaseOrder.BillingCurrency)
                             );
 
    Payment payment = paymentMethod
                    .GetPaymentMethodService()
                    .RequestPayment(paymentRequest);
}
posted on Wednesday, 19 May 2010 12:52:18 (Romance Daylight Time, UTC+02:00)  #    Comments [0] Trackback

evil-insideWhen first I saw the var keyword in C# 3.0 I was excited, my body tingling with excitement for the possibilities this keyword would bring to the world of many a .NET developer: Productivity, clarity, fame, and fortune. Unfortunately now that C# 3.0 has been with us for a while I feel that I must warn the public of the evil that is the var keyword. Productivity, clarity, fame, and fortune have succumbed to mind boggling spaghetti code, confusion, and lets be honest fame and fortune were never really on the table to begin with :)

What then is this evil of which I speak? Massive overuse of the var keyword. Observe the following hot dish of spaghetti bolognese:

   1:  public void SpaghettiBolognese()
   2:  {
   3:      var calculator = new Calculator();
   4:      var taxLevel = GetTaxLevels();
   5:      var person = GetPerson();
   6:      var tax = calculator.CalculateTaxLevel(person, taxLevel);
   7:   
   8:      person.Tax = tax;
   9:  }

All kidding aside this piece of code breaks one of my most fundamental rules when reading and writing code: Don't make me think. Grokking a piece of code is though enough as it is having to keep types and varibles in memory (read: the developer brain) will slow down the process of code reviewing or debugging a piece of code.

For now I'm using a couple of rules to keep the var silliness at manageable levels.

1) Always use proper types for variables which are set from a method or property. It makes the code so much more readable.

   1:  Tax tax = calculator.CalculateTaxLevel(person, taxLevel);

2) Do use the var keyword when there is no question about which type it will be inferred to.

   1:  var calculator = new Calculator();
   2:  var i = 100;
   3:  var s = "Søren";

While the var keyword does offer a nice productivity gain it's important to realize when to use and more importantly when not to use it. Also it would seem that the var keyword is in cahoots with the good folks at Jetbrains as ReSharper is very eager to convert perfectly well formed type declarations to implicitly typed ones. As I started out by saying be wary of the var keyword - it's one sneaky bastard :)

Var-keywords-is-a-sneaky-bastard

posted on Monday, 08 September 2008 21:57:14 (Romance Daylight Time, UTC+02:00)  #    Comments [10] Trackback

Inspired by Scott Hanselman I bring you my own list of software I absolutely positively cannot live without. This list of software has taken years to compile: I didn’t start out with a list of software as a goal, I simply needed to get a job done. Every single time I need to get a new job done I go out and select the top ten pieces of software which solve a given problem. This list is narrowed down until I’m left with a single piece which will go into my tool box. I refine my tool box continually but some of the piece of software has lived in my tool box for many years, EditPlus is one such piece of software, WinRAR is another. Some categories are left out entirely as time moves on, examples of these would be FTP and IRC which I used religiously previously but have no need for recently.

My quest for an ever increasing level of quality in my tool box has even taken me so far as to consider an different platform than Windows altogether. I’ve yet to explore the Apple platform but I do find that some very interesting pieces of software live on that particular platform. Maybe in the future, for now I’m bound to the Windows platform.

Usability

Launchy
Launchy
Provides fast access to your start menu by popping up a window in which you type the name or part of the name of the program you wish to launch. No need to click on the start menu ever again. My thoughts on Launchy.

TweakUI
Powertoys
Allows for customization of a lot of Windows XP settings. I primarily use this tool to change the location of the “My” folders pointing to locations outside of the Documents and Settings folder in order to facilitate easy backup and faster access. I usually keep my folders on a separate drive than the Windows drive in a folder called Users. Also I point the My Documents folder to the root of my user folder instead of the documents folder which gives me quick access to all my files from the start menu,

Office

Firefox

Firefox-logo

Firefox needs no further introduction. I debated long and hard whether to include it or not. Since I use this browser pretty intensively I figured that I’d better put it on my list as it is usually the first piece of software to get installed. I like Internet Explorer 7 and I think that the user interface of that particular browser is better than what we get with Firefox, but Firefox brings lots and lots of plugins to the table which enables us to customize to our heart’s content. Specifically I enjoy TabMix Plus as it allows me to configure my tabs exactly the way I want them.

FeedDemon 2

FeedDemonLogo

The easy-to-use interface makes it a snap to stay informed with the latest news and information. You can completely customize the way feeds are organized and displayed and set up custom news watches based on keywords. You can even download podcasts and audio files and have them show up on your portable audio device. In addition, FeedDemon now synchronizes with NewsGator Online and the rest of the NewsGator RSS Suite. The software is pre-configured with dozens of feeds, so you can unleash the power of RSS right away. My thoughts on FeedDemon 2.

FeedDemon 2 replaces Omea Reader as my RSS reader recommendation due to persisting bugs in the Omea product.

BlogJet

Bjlogo4

BlogJet is a weblog client for Windows that allows you to manage your blog(s) without opening a browser. Those who are seriously concerned with blogging, cannot imagine their work without using this wonderful tool with elegant interface.

EditPlus
Editplus
Notepad replacement supporting multiple documents in the same window. Automatically colors code with support for many languages.

FoxItPdfReader
FoxItReader
A faster less cluttered PDF reader.

Nero 6

Nero6logo

For burning CDROMs and DVDs. I’m not too fond of the latest version of this software so I may end up finding something better. If you have a suggestion please feel free to mail it me.

PureText

PureText is basically equivalent to opening Notepad, doing a PASTE, followed by a SELECT-ALL, and then a COPY.  The benefit of PureText is performing all these actions with a single Hot-Key and having the result pasted into the current window automatically. I use this tool all the time when copying snippets from sources around the web.

Programming

WinMerge
Winmerge
A visual text file differencing and merging tool. It is highly useful for determining what has changed between project versions, and then merging changes between versions.

Resharper
Resharper
JetBrains ReSharper is a Visual Studio .NET add-in that brings intelligent C# code editing and coding assistance features to VS.NET. By intelligent features we mean usage search, powerful refactorings, smart type completion, using assistant and more. In brief, ReSharper truly understands C# code. My thoughts on Resharper.

Consolas Font
The Microsoft Consolas Font Family is a set of highly legible fonts designed for ClearType. It is intended for use in programming environments and other circumstances where a monospaced font is specified. This installation package will set the default font for Visual Studio to Consolas. My thoughts on the Consolas Font.

CopySourceAsHTML
An add-in for Microsoft Visual Studio 2005 that allows you to copy source code, syntax highlighting, and line numbers as HTML. CSAH uses Visual Studio's syntax highlighting and font and color settings automatically. If Visual Studio can highlight it, CSAH can copy it, and your source should look the same in your browser as it does in your editor.

Cool Commands for Visual Studio 2005
Adds a couple of useful features to Visual Studio 2005: Open Containing Folder for Files,Copy Reference, Add Projects from Folder are the ones I use the most. My thoughts on Cool Commands.

Imaging

Paint.NET
Paintnetlogo
An image and photo manipulation software It supports layers, unlimited undo, special effects, and a wide variety of useful and powerful tools. Covers the basic image editing needs. My thoughts on Paint.NET.

Picasa
Picasa
Picasa is a photo management tool from Google which provides a very nice interface for browsing your photos. Also includes basic photo editing tools such as red eye removal.

Cropper
Cropper
Cropper is a screen capture utility. It makes it fast and easy to grab parts of your screen. Use it to easily crop out sections of vector graphic files such as Fireworks without having to flatten the files or open in a new editor. Use it to easily capture parts of a web site, including text and images. It's also great for writing documentation that needs images of your application or web site. My thoughts on Cropper.

GetCanon!
Image downloader for Canon digital cameras. It's small, quick and simple. It can download images, rotate them automatically and delete them from camera. If you hate the "designer" interface of Canon utilities and hate Windows messing with image filenames, this is the right tool for you.

Music

iTunes
Itunes
iTunes doesn’t really need an introduction. I use this guy because of the very nice integration with the iPod and the sleek podcasting support.

AirFoil
Airfoil
Send any audio to the AirPort Express. My thoughts on AirFoil.

System

WinRAR

Archiver with support for almost all the archive formats out there. I use this one to avoid having multiple archivers installed and because it integrates nicely into the Windows shell.

Daemon Tools ISO Mounter

DaemonToolsLogo

A tool for mounting ISO images as CDROM drives.

FolderShare

FolderShare

FolderShare is a service that allows you to securely keep files synchronized between your devices, share files with friends or colleagues, and remotely download your files from any web browser. I use this tool for both remote backup and synchronization between work and home.

µTorrent

Bittorrent is becoming a pervasive means of distribution on the internet and this client brings a whole lot of features to the table making it on par with clients such as Azureus and BitComet but at the same time being smaller and more importantly not a Java based piece of software

posted on Sunday, 09 July 2006 15:44:52 (Romance Daylight Time, UTC+02:00)  #    Comments [4] Trackback

Visualstudio_logoMicrosoft was kind enough to release the Consoles font from Vista for VS 2005. I hadn’t noticed the first time around how nice this font is but it does actually make a difference when reading coding although it did take some getting used to before I was convinced. Give it day before you decide.

I highly recommend downloading and installing it.

Both Scott Hanselman with Consolas Font Family now available for download and guidmaster with Consolas Font Pack tuned me in to this one. Thanks.

posted on Thursday, 11 May 2006 15:03:54 (Romance Daylight Time, UTC+02:00)  #    Comments [0] Trackback