FB.Canvas.Pay

Prompt the user to make a payment using Facebook Payments. This wraps the JS SDK function FB.ui({method: "pay", action: "purchaseitem", ...).

When called in the Unity Editor, a stub function is called instead.

Parameters

public static void FB.Canvas.Pay(
 string product,
 string action = "purchaseitem",
 int quantity = 1,
 int? quantityMin = null,
 int? quantityMax = null,
 string requestId = null,
 string pricepointId = null,
 string testCurrency = null,
 FacebookDelegate<IPayResult> callback = null
)
ParameterTypeDescriptionDefault

action

string

Should always be purchaseitem.

purchaseitem

product

string

The URL of your og:product object that the user is looking to purchase. For a full description on how to construct this product object, please see the Defining Products guide, and the Product Object reference material.

quantity

int

The amount of this item the user is looking to purchase - typically used when implementing a virtual currency purchase.

1

quantityMin

int

The minimum quantity of the item the user is able to purchase. This parameter is important when handling price jumping to maximize the efficiency of the transaction.

quantityMax

int

The maximum quantity of the item the user is able to purchase. This parameter is important when handling price jumping to maximize the efficiency of the transaction.

requestId

string

The developer defined unique identifier for this transaction, which becomes attached to the payment within the Graph API. Learn more.

pricepointId

string

Used to shortcut a mobile payer directly to the mobile purchase flow at a given price point. Full details can be found in the Optimizing for Mobile Payments doc.

testCurrency

string

This parameter can be used during debugging and testing your implementation to force the dialog to use a specific currency rather than the current user's preferred currency. This allows you to rapidly prototype your payment experience for different currencies without having to repeatedly change your personal currency preference settings. This parameter is only available for admins, developers and testers associated with the app, in order to minimize the security risk of a malicious JavaScript injection. Provide the 3 letter currency code of the intended forced currency. The list of supported currency codes is available here

callback

FacebookDelegate <IPayResult>

A delegate which will receive the result of the call, and which you should monitor for errors

null

Examples

Sell two of an item described by the Product Object located at YOUR_PRODUCT_URL, and log the result.

FB.Canvas.Pay(
  product: "YOUR_PRODUCT_URL",
  quantity: 2,
  callback: delegate(IPayResult response) {
    Debug.Log(response.RawResult);
  }
);

On success, the response's Text property will be a JSON string like this:

{
  payment_id: 848929916459082, 
  quantity: "2", 
  status: "completed", 
  signed_request: "7QYHzKqKByA7fjiqJUh2bxFvEdqdvn0n_y1zYiyN6tg.eyJhbGCJxdWFudGl0eSI6IjEiLCJzdGF0dXMiOiJjb21wbGV0ZWQifQ"
}

A failure's Error property will be a string describing the error.

{"code":400,"body":{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}}

See the [Payments Dialog documentation](/docs/payments/reference/paydialog) for more details.

Best Practices

Please see the Payments documentation for details on how to get the most from your implementation.