anchor.diff:  }
   ----
   
  -* Like the other methods, the `purchasePayment` method accepts  `Iterable<PluginProperty> properties` as a parameter. 
  -
  -* In addition, it also accepts parameters corresponding to `amount` (specifies the amount to charge the customer) and `currency` (specifies the currency to be used).
  -
   * If you recall, the `addPaymentMethod` stores the *mandate id* in the Kill Bill database. This is first retrieved and assigned to `mandate`.
   
   * Next, the `idempotencyKey` is retrieved from the `properties` passed in. The  `idempotencyKey` is a GoCardless specific value. As per the GoCardless documentation, their API will ensure this payment is only ever created once per `idempotencyKey`. So a client application could specify `kbPaymentId` as the `idempotencyKey` to ensure at most a single payment is created per `kbPaymentId`.
   
   *  The `currency` object passed in is of type `org.killbill.billing.catalog.api.Currency`. This is then converted to a *GoCardless Currency object* (of type `com.gocardless.services.PaymentService.PaymentCreateRequest.Currency`). Most payment plugins have code similar to this to convert Kill Bill objects to compatible objects in the plugin's client library.
   
  -* Finally, the `client.payments().create()` is invoked with the `idempotencyKey`,`amount` and `currency` values. This returns a `Payment` object which contains a `paymentId`. Additionally, the `kbPaymentId` and `kbTransactionId` are sent as *metadata* to GoCardless in this call. GoCardless *metadata* allows an application to send custom key value pairs to GoCardless. These can then be retrieved later on as required.  In our case, the `kbPaymentId` and `kbTransactionId` are required for the `getPaymentInfo` call which will be explained further. 
  -
  -* The `purchasePayment` method returns a `PaymentTransactionInfoPlugin` object.  The <<PaymentTransactionInfoPlugin, PaymentTransactionInfoPlugin>> section above explains this interface in detail. We have already created a https://github.com/killbill/killbill-gocardless-example-plugin/blob/9522498ecde5849c940574c598ceb5ce088d32a7/src/main/java/org/killbill/billing/plugin/gocardless/GoCardlessPaymentTransactionInfoPlugin.java[GoCardlessPaymentTransactionInfoPlugin] class above.
  +* Finally, the `client.payments().create()` is invoked with the `idempotencyKey`, `amount` and `currency` values. This returns a `Payment` object which contains a `paymentId`. Additionally, the `kbPaymentId` and `kbTransactionId` are sent as *metadata* to GoCardless in this call. GoCardless *metadata* allows an application to send custom key value pairs to GoCardless. These can then be retrieved later on as required.  In our case, the `kbPaymentId` and `kbTransactionId` are required retrieving the payment information as explained in the <<getPaymentInfo, "getPaymentInfo">> section. 
  +
  +* The `purchasePayment` method returns a <<PaymentTransactionInfoPlugin, "PaymentTransactionInfoPlugin">>  object.  We have already created a <<GoCardlessPaymentTransactionInfoPlugin, "GoCardlessPaymentTransactionInfoPlugin">> class above.
   
   * If the payment is successful, the `GoCardlessPaymentTransactionInfoPlugin` object is created with the following values:
   
  
positive.code: 
  * The `GoCardlessPaymentPluginApi` implements the `PaymentPluginApi` interface.
  * It declares the following fields:
  ** `killbillAPI` - This is of type https://github.com/killbill/killbill-platform/blob/617d4b626ddd7c081d2927355c6f8cfe2cbd4bd5/osgi-bundles/libs/killbill/src/main/java/org/killbill/billing/osgi/libs/killbill/OSGIKillbillAPI.java[OSGIKillbillAPI]. The `OSGIKillBillAPI` is a Kill Bill class which exposes all of Kill Bill’s internal APIs. 
  ** `GC_ACCESS_TOKEN_PROPERTY` - This is a String field that is required for accessing the GoCardless access token
  ** `clock` - This is of type https://github.com/killbill/killbill-commons/blob/aa83708f56377aabff8391c3ddc197817ad19ec2/clock/src/main/java/org/killbill/clock/Clock.java[Clock]. This is part of Kill Bill's clock library.
  
  ** `client` This is of type http://gocardless.github.io/gocardless-pro-java/com/gocardless/GoCardlessClient.html[GoCardlessClient]. This is a GoCardless specific class that can be used to access the GoCardless API
  
  * The constructor simply initializes the fields with the values passed in. In addition, it also creates a GoCardless client and initializes the `client` field.
  
  Within this class, we need to implement the `buildFormDescriptor`, `addPaymentMethod` and `purchasePayment` as explained in the <<using_gocardless_from_killbill, "Using GoCardless from Kill Bill">> section above. 
  
  ==== Step 3 - Creating GoCardlessPaymentTransactionInfoPlugin
  
  As explained earlier, most of the `PaymentPluginApi` methods return a <<PaymentTransactionInfoPlugin, _PaymentTransactionInfoPlugin_>> object. Let us take a look at the https://github.com/killbill/killbill-gocardless-example-plugin/blob/9522498ecde5849c940574c598ceb5ce088d32a7/src/main/java/org/killbill/billing/plugin/gocardless/GoCardlessPaymentTransactionInfoPlugin.java[_GoCardlessPaymentTransactionInfoPlugin.java_] class. 
  
negative.code: 
  * Finally, the *mandateId* is stored in the Kill Bill database. Normally, each plugin has its own plugin specific tables. However, since we are not creating a full-fledged GoCardless plugin, we are storing the *mandateId* in the *custom_fields* table.  The  *custom_fields* table can be used to store arbitrary key/value pairs in the Kill Bill database.
  
  * In case an error occurs in any of the steps, the code throws a https://github.com/killbill/killbill-plugin-api/blob/d9eca5af0e37541069b1c608f95e100dbe13b301/payment/src/main/java/org/killbill/billing/payment/plugin/api/PaymentPluginApiException.java[_PaymentPluginApiException_].
  
  [[purchase_payment]]
  ==== Step 6 - Implementing GoCardlessPaymentPluginApi#purchasePayment
  
  The `purchasePayment` method is used to charge a customer against a payment method. It is invoked when:
  
  * An automatic payment is triggered by Kill Bill.
  * A https://killbill.github.io/slate/#account-trigger-a-payment-authorization-purchase-or-credit[_direct payment api_] is invoked.
  
  In the case of Gocardless, it is used to trigger payments against a *mandateId*. Thus, it is implemented as follows (See https://github.com/killbill/killbill-gocardless-example-plugin/blob/9522498ecde5849c940574c598ceb5ce088d32a7/src/main/java/org/killbill/billing/plugin/gocardless/GoCardlessPaymentPluginApi.java#L94[_GoCardlessPaymentPluginApi#purchasePayment_]):
  
  