en-us/Get-Paid_with_Stripe.walkthru.help.txt

<#
 
[Stripe](http://stripe.com) is a great payment processing service. It lets you handle credit cards quickly, cheerfully, and nicely.
 
 
Pipeworks processes payments with Stripe with the cmdlet Get-Paid. This example processes a test payment transaction with Stripe.
#>
Get-Paid -StripeKey sk_test_aElHsSizhc8XC0uESpNC1t64 -Currency usd -Amount 4 -CardNumber 4242424242424242 -ExpirationMonth 12 -ExpirationYear 2014
 
 
 
<#
 
Since you can [Pick up the Phone with Pipeworks](/Pick up the Phone with Pipeworks/), it's pretty simple to build an over-the-phone payment processor.
 
#>
 
 
 
 # Create a folder for the module
New-Item -Path "$home\Documents\WindowsPowerShell\Modules\PayByPhone" -ItemType Directory -ErrorAction SilentlyContinue -Force |
   Out-Null
 
 # Create a very minimal Pipeworks manifest
@'
@{
    SecureSetting = 'MyStripeKey'
    WebCommand = @{
        "Receive-PhonePayment" = @{
            Hidden = $true
        }
    }
}
'@ |
    Set-Content "$home\Documents\WindowsPowerShell\Modules\PayByPhone\PayByPhone.Pipeworks.psd1"
 
@'
@{
    ModuleVersion = 0.1
    ModuleToProcess = 'PayByPhone.psm1'
}
'@ |
    Set-Content "$home\Documents\WindowsPowerShell\Modules\PayByPhone\PayByPhone.psd1"
 
@'
. $psScriptRoot\Receive-PhonePayment.ps1
'@ |
    Set-Content "$home\Documents\WindowsPowerShell\Modules\PayByPhone\PayByPhone.psm1"
 
 
{
function Receive-PhonePayment
{
    <#
    .Synopsis
        Receives payments over the phone
    .Description
        Thank you for making a payment.
    #>
 
 
    param(
    # How much would you like to pay?
    [Parameter(Mandatory=$true,Position=0)]
    [Double]
    $Amount,
 
 
    # What is the card number?
    [Parameter(Mandatory=$true,Position=0)]
    [Uint32]
    $CardNumber,
 
    # What is the number of the expiration month?
    [Parameter(Mandatory=$true,Position=1)]
    [Uint32]
    $ExpirationMonth,
 
    # What is the number of the expiration year?
    [Parameter(Mandatory=$true,Position=2)]
    [Uint32]
    $ExpirationYear,
 
    # What is the card verification code?
    [Parameter(Mandatory=$true,Position=2)]
    [Uint32]
    $CardVerficationCode
    )
    process {
         
          
 
        $paymentInfo = Get-Paid @PSBoundParameters -StripeKeySetting MyStripeKey -Currency usd -ErrorAction SilentlyContinue -ErrorVariable ProblemsHaveHappened
 
        if (-not $paymentInfo) {
            "I'm sorry, your payment cannot be processed."
        } else {
            "Thank you for your payment."
        }
    }
}
} |
    Set-Content "$home\Documents\WindowsPowerShell\Modules\PayByPhone\Receive-PhonePayment.ps1"
 
 
Import-Module PayByPhone -Force -PassThru | ConvertTo-ModuleService -Force -Do "/Receive-PhonePayment/?CallSid=123&AccountSid=abc&From=12065551212&To=12065551212" -AsIntranetSite -Port 2121
 
 
<#
 
 
[ShowUI](http://www.show-ui.com) is another tool Start-Automating makes to help power UI over PowerShell. You can download Pipeworks, ShowUI, and more when you download [IsePackV2](http://powershellise.com).
 
 
With ShowUI and Pipeworks, you can create a WPF credit card terminal in 55 lines of code.
 
#>
New-Grid -Name StripePaymentProcessor -On_Loaded {
    Import-Module Pipeworks -Global -Force # Import Pipeworks on load
    # (change this to your stripe key, or the setting that points to it)
    $stripeKey = Get-SecureSetting -Name StripeTestKey -ValueOnly
     
    if (-not $stripeKey) {
        $ErrorArea.Text = "Stripe Key not found"
        $ErrorArea | Set-Property @{"Foreground" = "DarkRed"}
    } else {
        $this.Resources.StripeKey = $stripeKey
    }
     
    $window.TopMost = $true
} -Rows (@('Auto') * 11 ) -Columns 2 -Children {
    $defaultStyle = @{
        FontSize = 22
        FontFamily = 'Segoe UI'
        Margin = 4
    }
    New-TextBlock -FontWeight DemiBold -Text "Amount" -ColumnSpan 2 @defaultStyle
    New-TextBox -Row 1 -Name CreditCardAmount -ColumnSpan 2 @defaultStyle
 
    New-TextBlock -FontWeight DemiBold -Text "Card Number" @defaultStyle -ColumnSpan 2 -Row 2
    New-PasswordBox -Name CreditCardNumber -ColumnSpan 2 -Row 3 @defaultStyle -MaxLength 25
 
    New-TextBlock -FontWeight DemiBold -Text "Expiration" -ColumnSpan 2 -Row 4 @defaultStyle
    New-TextBlock -FontWeight Light -Text "Month" -Margin 4 -Row 5 -FontFamily 'Segoe UI' -FontSize 19
    New-TextBlock -FontWeight Light -Text "Year" -Margin 4 -Row 5 -FontFamily 'Segoe UI' -Column 1 -FontSize 19
 
    New-TextBox @defaultStyle -Row 6 -Name CreditCardExpirationMonth -MaxLength 2
    New-TextBox @defaultStyle -Row 6 -Column 1 -Name CreditCardExpirationYear -MaxLength 4
 
    New-TextBlock -Name ErrorArea -Foreground 'DarkRed' @defaultStyle -Row 7 -RowSpan 2 -VerticalAlignment Center
 
    New-TextBlock -Text "CCV" -Column 1 @defaultStyle -Row 8
    New-TextBox -Name "CCV" -Column 1 @defaultStyle -Row 9 -MaxLength 4
     
    New-Button -Content "Charge Card" @defaultStyle -Row 10 -ColumnSpan 2 -On_Click {
        $ccAmount = "$($CreditCardAmount.Text)".Replace('$','').Trim()
        $ccNumber = "$($CreditCardNumber.Password)".Replace('-','').Trim()
        $ErrorArea.Text= ""
        $errorOrResult =
            try {
                Get-Paid -StripeKey $stripeKey -CardNumber $ccNumber -Currency usd -ExpirationMonth $creditCardExpirationMonth.Text -ExpirationYear $creditCardExpirationYear.Text -CardVerficationCode $CCV.Text -Amount $ccAmount
            } catch {
                $_
            }
     
        if ($errorOrResult -is [Management.Automation.ErrorRecord]) {
            $ErrorArea.Text = "$errorOrResult"
            $ErrorArea | Set-Property @{"Foreground" = "DarkRed"}
        } else {
            $ErrorArea.Text = "Card Charged"
            $ErrorArea | Set-Property @{"Foreground" = "DarkGreen"}
        }
    }
} -Show