/**
  * This method creates and assigns a subscription plan to a customer
  *
  * @param FinancialTransactionInterface $transaction
  * @param bool $retry
  * @throws \JMS\Payment\CoreBundle\Plugin\Exception\FinancialException
  */
 public function initializeRecurring(FinancialTransactionInterface $transaction, $retry)
 {
     $data = $transaction->getExtendedData();
     $opts = $data->has('checkout_params') ? $data->get('checkout_params') : array();
     $cardToken = $this->findOrCreateCardId($transaction);
     $planId = $this->findOrCreatePlan($transaction);
     // create customer and assign card and plan
     $response = $this->client->createCustomerRequest($cardToken, $planId, $opts);
     $this->throwUnlessSuccessResponse($response, $transaction);
     // complete the transaction
     $transaction->getExtendedData()->set('customer_id', $response->getResponse()->id);
     $transaction->getExtendedData()->set('subscription_id', $response->getResponse()->subscription->id);
     $transaction->setReferenceNumber($response->getResponse()->subscription->id);
     $transaction->setProcessedAmount($transaction->getRequestedAmount());
     $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
     $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
 }