Installation

To get started using Version 2.x of Clickbank IPN, you will need to go through an initial set-up process.

  1. Install the drupal module in the usual way. See here for more information http://drupal.org/documentation/install/modules-themes
  2. Get a Secret Key from Clickbank by logging into your account and then going to Settings -> My Site, then click Edit on "Advanced Tools".
  3. Enter your Instant Notification URL in the space provided. It should be something like "http://example.com/clickbank/ipn".
  4. Select version 6.0.
  5. On your Drupal site enter your Clickbank Secret Key at admin/config/services/clickbank.
  6. Configure any rules you need in order to react to an incoming clickbank transaction.

Rules Examples

Reaction rule when a particular product is purchased through Clickbank. Note that the product No or SKU is 1 and that the action triggers a rules component.

{ "rules_x_product_purchase" : {
    "LABEL" : "X Product Purchase",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "clickbank" ],
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "clickbank_transaction_insert" ],
    "IF" : [
      { "data_is" : { "data" : [ "clickbank-transaction:lineItemsitemNo" ], "value" : "1" } }
    ],
    "DO" : [
      { "component_rules_calm_package_order_handling" : { "clickbank_transaction" : [ "clickbank_transaction" ] } }
    ]
  }
}

Here is the triggered rules component. Note that this is a rule set with two rules that are run depending on if a drupal user already exists with the email address provided by the Clickbank IPN. This example uses drupal commerce and the commerce_file and commerce_license modules to grant users access to certain files associated with a product. Similar things could be done such as granting roles for subscription access, and more!

{ "rules_calm_package_order_handling" : {
    "LABEL" : "X Product order handling",
    "PLUGIN" : "rule set",
    "TAGS" : [ "clickbank" ],
    "REQUIRES" : [ "commerce", "rules", "commerce_checkout", "infusionsoft" ],
    "USES VARIABLES" : { "clickbank_transaction" : { "label" : "Clickbank Transaction", "type" : "clickbank_transaction" } },
    "RULES" : [
      { "RULE" : {
          "PROVIDE" : {
            "entity_fetched" : { "user" : "User" },
            "entity_created" : { "x_product" : "X Product" }
          },
          "IF" : [
            { "entity_exists" : {
                "type" : "user",
                "property" : "mail",
                "value" : [ "clickbank-transaction:billingemail" ]
              }
            }
          ],
          "DO" : [
            { "entity_query" : {
                "USING" : {
                  "type" : "user",
                  "property" : "mail",
                  "value" : [ "clickbank-transaction:billingemail" ],
                  "limit" : "1"
                },
                "PROVIDE" : { "entity_fetched" : { "user" : "User" } }
              }
            },
            { "send_account_email" : { "account" : [ "user:0" ], "email_type" : "register_admin_created" } },
            { "data_set" : { "data" : [ "clickbank-transaction:uid" ], "value" : [ "user:0:uid" ] } },
            { "entity_create" : {
                "USING" : {
                  "type" : "commerce_license",
                  "param_type" : "file",
                  "param_owner" : [ "user:0" ],
                  "param_product" : "71",
                  "param_status" : "2"
                },
                "PROVIDE" : { "entity_created" : { "x_product" : "X Product" } }
              }
            },
          ],
          "LABEL" : "Existing User"
        }
      },
      { "RULE" : {
          "PROVIDE" : { "entity_created" : {
              "user_created" : "Created user",
              "calm_package" : "Calm Parenting Package"
            }
          },
          "IF" : [
            { "NOT entity_exists" : {
                "type" : "user",
                "property" : "mail",
                "value" : [ "clickbank-transaction:billingemail" ]
              }
            }
          ],
          "DO" : [
            { "entity_create" : {
                "USING" : {
                  "type" : "user",
                  "param_field_first_name" : [ "clickbank-transaction:billingfirstName" ],
                  "param_name" : [ "clickbank-transaction:billingfullName" ],
                  "param_mail" : [ "clickbank-transaction:billingemail" ]
                },
                "PROVIDE" : { "entity_created" : { "user_created" : "Created user" } }
              }
            },
            { "data_set" : {
                "data" : [ "user-created:field-last-name" ],
                "value" : [ "clickbank-transaction:billinglastName" ]
              }
            },
            { "data_set" : { "data" : [ "user-created:status" ], "value" : "1" } },
            { "data_set" : {
                "data" : [ "user-created:roles" ],
                "value" : { "value" : { "7" : "7" } }
              }
            },
            { "entity_save" : { "data" : [ "user-created" ], "immediate" : 1 } },
            { "send_account_email" : {
                "account" : [ "user-created" ],
                "email_type" : "register_pending_approval"
              }
            },
            { "data_set" : {
                "data" : [ "clickbank-transaction:uid" ],
                "value" : [ "user-created:uid" ]
              }
            },
            { "entity_create" : {
                "USING" : {
                  "type" : "commerce_license",
                  "param_type" : "file",
                  "param_owner" : [ "user-created" ],
                  "param_product" : "71",
                  "param_status" : "2"
                },
                "PROVIDE" : { "entity_created" : { "calm_package" : "Calm Parenting Package" } }
              }
            },
          ],
          "LABEL" : "No Existing User"
        }
      }
    ]
  }
}