Stripe: Difference between revisions
Line 94: | Line 94: | ||
== Events == | == Events == | ||
The following events are supported: | |||
{| class = "wikitable" | {| class = "wikitable" | ||
|- | |- | ||
| onApprovalReceived(response || Called when Stripe approves (or does not approve) the transaction. | | onSetup || Optional. Called when Stripe control is clicked. Use it to set any values the Stripe dialog box needs. | ||
|- | |||
| onSalesTax || Optional. Called after the user has entered his address and card, but before the card is actually charged. Can be used for Sales Tax, which may change based on the address entered. | |||
|- | |||
| onApprovalReceived(response || Recommended. Called when Stripe approves (or does not approve) the transaction. | |||
|} | |} | ||
Revision as of 19:49, 5 March 2016
This page is about a feature which is still in development. It has not been released.
Description
Using Stripe, AppStudio developers can integrate payment processing into their websites without having to register and maintain a merchant account. Stripe accepts all major credit cards, plus BitCoin and AliPay.
The Stripe control makes it easy to collect payment from your customers directly within your app.
Start by setting up a Stripe account for yourself. You'll need to enter information about your company, including bank account information (so Stripe can transfer to you).
The following properties can be set up in the IDE. They can also be changed at runtime, by reference them as [controlname].data.[property]:
Stripe1.data.amount = 1000
When the user clicks on the Stripe button, a popup appears. The appearance of the popup depends on the properties. Here's a minimal popup:
When the user fills in the information and click on the Pay button, the information is sent to a PGP script. This script needs to be saved on the same server as your app is loaded from for security reasons. Put the path to the script into the chargeScript property.
The PHP script is quite simple - it reads the information sent from your app and calls Stripe for authorization.
//include the Stripe libraries for PHP require_once '/usr/home/nsbasic/stripe-php-3.9.0/init.php'; //Supply the private key. Issued by Stripe \Stripe\Stripe::setApiKey("••••••••••••••••••••••••••"); // Create the charge on Stripe's servers - this will charge the user's card try { $stripe = $charge = \Stripe\Charge::create(array( "amount" => $_POST['amount'], "currency" => $_POST['currency'], "source" => $_POST['stripeToken'], "description" => $_POST['description'], "metadata" => $_POST['metadata'] )); } catch(\Stripe\Error\Card $e) { echo "Declined."; break; }
The PHP script requires the Stripe libraries be installed on your server. Instructions for doing this are here: https://github.com/stripe/stripe-php#manual-installation
When the script completes, it returns a response object in the controls data. You can test if it was successful as follows:
If Stripe1.data.response.status = "succeeded" Then
Properties
alipay | Accept Alipay? |
alipayReusable | Reusable access to customer's Alipay account needed? |
allowRememberMe | Reusable access to customer's Alipay account needed? |
amount | Reusable access to customer's Alipay account needed? |
billingAddress | Should Stripe prompt for the billing address? |
bitcoin | Accept BitCoin? |
chargeScript | The name of the PHP script on your server which calls Stripe for authorization. |
currency | Currency of transaction. 3 letter ISO code. |
description | Description of what is being sold. Displayed on Stripe popup. |
Customer's email. Displayed on Stripe popup. If empty, Stripe popup will request it. | |
image | 128x128 icon to display on Stripe popup. gif, jpg or png. Do not add files to /nsb. |
key | Your public key. Issued by Stripe. |
locale | Specify auto to display Checkout in the user's preferred language, if available. English will be used by default. |
metadata | Additional data of your own, in object format. Example: {tax: 0, country: 'USA'} |
name | Your company name. |
panelLabel | Additional label to show on green button on Stripe popup. |
response | This object is available only at runtime. It is added to the control's data after Stripe is called. |
shippingAddress | Should Stripe prompt for the shipping address? |
zipCode | Should Stripe validate the billing ZIP code? |
Events
The following events are supported:
onSetup | Optional. Called when Stripe control is clicked. Use it to set any values the Stripe dialog box needs. |
onSalesTax | Optional. Called after the user has entered his address and card, but before the card is actually charged. Can be used for Sales Tax, which may change based on the address entered. |
onApprovalReceived(response | Recommended. Called when Stripe approves (or does not approve) the transaction. |
Testing
Stripe supplies a number of credit card numbers which can be used to test different types of cards and transaction failures. See them here: https://stripe.com/docs/testing
Example
Function Stripe1_onApprovalReceived(response) If response.status = "approved" Then MsgBox "Transaction approved." Else MsgBox "Transaction declined." End If End Function