Testing Payments

Best way to test implementation

Once you have your payments system in place, follow these steps to thoroughly test your implementation.

Payment Testers

To test your payment implementation, assign specific users of your app to be payment testers in the Canvas Payments section of your App Dashboard. Payment testers can make transactions as normal within your app, but their payment instrument won't be charged and the transaction won't appear in the payments reporting API.

When a payment tester invokes the payment dialog in your app, they'll be presented with a test flow instead of the regular payment flow. This can be used to test purchase functionality without performing real transactions.

Figure 1. Canvas Payments section of the App Dashboard.

Credit Cards

For testing purposes, use one of the mock credit cards in the following table. Users that have been added as a payment tester must use one of these mock credit cards and will be prohibited from using real credit cards.

NumberBrandDateCVCZIP CodeBilling Country

5555555555554444

Master Card

Any future date

Any 3 Digits

Any valid ZIP

United States

5454543112674402

Master Card

Any future date

Any 3 Digits

Any valid ZIP

United States

4444448713788708

Visa

Any future date

Any 3 Digits

Any valid ZIP

United States

4242424242424242

Visa

Any future date

Any 3 Digits

Any valid ZIP

United States

6011111111111117

Discover

Any future date

Any 3 Digits

Any valid ZIP

United States

Payment dialogs will indicate that you are in a testing environment by displaying a "You're currently testing this feature" banner and updating the button text, as shown in the following image.

Figure 2. Using a mock credit card for testing.

Order Fulfillment

For order fulfillment, test payments behave in the same way as real payments. The JavaScript callback, Webhooks, and Payment Graph API perform consistently, regardless of whether the payment was made by a test user.

The only difference between real payments and test payments is that test payments don't appear in the user's Purchase History or any payment reporting.

Payment Info

When querying the Graph API for payment info on a test transaction with a payment_id, an extra test field will be added to the Graph API return data and set to 1, signaling that it was a test transaction which you won't be paid out for.

{
  "id": "370408446422594", 
  "user": {
    "name": "Marco Alvarez", 
    "id": "500535225"
  }, 
  "application": {
    "name": "Friend Smash!", 
    "namespace": "friendsmash", 
    "id": "24143148..."
  }, 
  "actions": [
    {
      "type": "charge", 
      "status": "completed", 
      "currency": "USD", 
      "amount": "0.90", 
      "time_created": "2013-10-23T22:24:41+0000", 
      "time_updated": "2013-10-23T22:25:18+0000"
    }
  ], 
  "refundable_amount": {
    "currency": "USD", 
    "amount": "0.00"
  }, 
  "items": [
    {
      "type": "IN_APP_PURCHASE", 
      "product": "https://friendsmash.com/og/coin.html", 
      "quantity": 9
    }
  ], 
  "country": "US", 
  "request_id": "5D81tgIWTBrfYG36ohftTci3KVU8M6dAg2NPmJwXcpk65ABVlkp5vtE2y43YYpWI", 
  "created_time": "2013-10-23T22:24:41+0000", 
  "test": 1, 
  "payout_foreign_exchange_rate": 1
}

Testing Transaction Disputes

You can test the Webhooks for disputes and refunds by appending the env=external parameter to the URLs of the relevant pages. For example, to list test transactions for your app navigate to https://secure.facebook.com/facebook_pay/payment_history&env=external.

Testing Multiple Currencies

To test purchases in multiple currencies, change your preferred currency in the payments settings.

A/B Testing API

We've made it easy to A/B test your Facebook payments implementation by creating a simple API that segments users into ten groups. This allows you to try different pricing strategies, product offerings, or promotions in a controlled environment. The segmentation is random and generates reliable results with no payment bias across the base of the ecosystem.

Query the segmentation API as shown in the following example to check which test_group a specific user is in. This call will return an integer between 1 and 10 and will remain stable for a specific user.

GET https://graph.facebook.com/USER_ID?fields=test_group&access_token=ACCESS_TOKEN

Testing Subscriptions

Testing Payments in the Subscription Environment

All payment testers are automatically set up to test subscription payments. This will allow you to quickly test your workflows for both valid and invalid payment instruments. Subscriptions that are created using the testing flow won't be displayed in the subscription management interface under Account Settings > Payments; this interface displays only legitimate subscriptions.

Testing Recurring Payments Using the Server-Side API

Use the server-side API's subscription management interface to test your system's ability to handle the end of a billing period and the start of a new one. To do this, set the next_bill_time property to a date and time near the current time.

Testing Free Trials Using Test Users

Because there isn't a way to undo the expiration of a free trial for a user, create multiple test users to repeatedly test your free trial functionality.