{"action":"created","comment":{"url":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/comments/34576327","id":34576327,"diff_hunk":"@@ -27,8 +30,69 @@ class ZuoraService(zuoraApiConfig: ZuoraApiConfig) extends ZuoraApi {\n   override val metrics = new ZuoraMetrics(stage, application)\n   val authTask = ScheduledTask(s\"Zuora ${apiConfig.envName} auth\", Authentication(\"\", \"\"), 0.seconds, 30.minutes)(request(Login(apiConfig)))\n \n-  def createSubscription(memberId: MemberId, data: SubscriptionData, ratePlanId: String, paymentDelay: Option[Period]): Future[SubscribeResult] = {\n-    request(Subscribe(memberId, data, ratePlanId, paymentDelay))\n+  def createSubscription(memberId: MemberId, data: SubscriptionData, paymentDelay: Option[Period]): Future[SubscribeResult] = {\n+    request(Subscribe(memberId, data, paymentDelay))\n   }\n+\n+  private def getProducts(): Future[Seq[SubscriptionProduct]] = {\n+\n+    def productRatePlans: Future[Seq[ProductRatePlan]] =\n+      query[ProductRatePlan](s\"ProductId='$digitalProductId'\")\n+\n+\n+    def productRatePlanCharges(productRatePlans: Seq[ProductRatePlan]): Future[Seq[ProductRatePlanCharge]] = {\n+      Future.traverse(productRatePlans) {  productRatePlan =>\n+          query[ProductRatePlanCharge](s\"ProductRatePlanId='${productRatePlan.id}'\")\n+        }.map(_.flatten)\n+      }\n+\n+\n+    def productRatePlanChargeTiers(productRatePlanCharges: Seq[ProductRatePlanCharge]): Future[Seq[ProductRatePlanChargeTier]] = {\n+      Future.traverse(productRatePlanCharges) { productRatePlanCharge =>\n+        query[ProductRatePlanChargeTier](s\"ProductRatePlanChargeId='${productRatePlanCharge.id}'\")\n+      }.map(_.flatten)\n+\n+    }\n+\n+    for {\n+      productRatePlan <- productRatePlans\n+      productRatePlanCharges <- productRatePlanCharges(productRatePlan)\n+      productRatePlanChargesTier <- productRatePlanChargeTiers(productRatePlanCharges)\n+    } yield {\n+\n+      //filter by GBP rate plans\n+      val productRatePlanChargesTierPounds = productRatePlanChargesTier.filter(_.currency == \"GBP\")\n+\n+      //filter by plans that have a billing frequency we have\n+      val validProductRatePlanCharges = productRatePlanCharges.filter(b => BillingFrequency.all.map(_.lowercase).contains(b.billingPeriod.toLowerCase))\n+\n+      //filter product rate plans by ones that are in date\n+      val validRatePlans = productRatePlan.filter { p =>\n+        p.effectiveStartDate.isBeforeNow && p.effectiveEndDate.isAfterNow\n+      }\n+\n+      //pull all the queries together to make a SubscriptionProduct\n+\n+      val subscriptionProducts = for(ratePlan <- validRatePlans) yield {\n+        val billingFreqProductRatePlan = validProductRatePlanCharges.find(_.productRatePlanId == ratePlan.id)\n+        val productRatePlanChargeTier = billingFreqProductRatePlan.flatMap { p =>\n+          productRatePlanChargesTierPounds.find(_.productRatePlanChargeId == p.id)\n+        }\n+\n+        val billingFreq = billingFreqProductRatePlan.flatMap(a => BillingFrequency.all.find(a.billingPeriod.toLowerCase == _.lowercase))\n+\n+        if (billingFreq.isDefined && productRatePlanChargeTier.isDefined)\n+          SubscriptionProduct(Digital, billingFreq.get, ratePlan.id, productRatePlanChargeTier.get.price)\n+        else throw new ZuoraServiceError(s\"Could not find valid ratePlan details for Digital Pack. Rate plan ID requested ${ratePlan.id}\")\n+      }\n+      subscriptionProducts\n+    }\n+  }\n+\n+  val productsTask = ScheduledTask[Seq[SubscriptionProduct]](\"Loading rate plans\", Nil, 5.seconds, 1.day)(getProducts())","path":"app/services/ZuoraService.scala","position":89,"original_position":89,"commit_id":"8f4508d5c8a90468613d527e3d6378a41bdf6788","original_commit_id":"78914be989fefb062cb88ccc77d0fa35c230bfe1","user":{"login":"tudorraul","id":1492162,"avatar_url":"https://avatars.githubusercontent.com/u/1492162?v=3","gravatar_id":"","url":"https://api.github.com/users/tudorraul","html_url":"https://github.com/tudorraul","followers_url":"https://api.github.com/users/tudorraul/followers","following_url":"https://api.github.com/users/tudorraul/following{/other_user}","gists_url":"https://api.github.com/users/tudorraul/gists{/gist_id}","starred_url":"https://api.github.com/users/tudorraul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tudorraul/subscriptions","organizations_url":"https://api.github.com/users/tudorraul/orgs","repos_url":"https://api.github.com/users/tudorraul/repos","events_url":"https://api.github.com/users/tudorraul/events{/privacy}","received_events_url":"https://api.github.com/users/tudorraul/received_events","type":"User","site_admin":false},"body":"I see two possible issues with setting a delay: 1/ setting this too high will make it likely that the application will start serving requests before this data is available and 2/ if it is too low, the credentials would not have been obtained when this call is attempted which will result in the application failing for a whole day.\r\n\r\nPerhaps it's worthwhile looking into how this could be chained to the retrieval of credentials (that this call depends on). ","created_at":"2015-07-14T14:51:40Z","updated_at":"2015-07-14T14:51:40Z","html_url":"https://github.com/guardian/subscriptions-frontend/pull/92#discussion_r34576327","pull_request_url":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/92","_links":{"self":{"href":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/comments/34576327"},"html":{"href":"https://github.com/guardian/subscriptions-frontend/pull/92#discussion_r34576327"},"pull_request":{"href":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/92"}}},"pull_request":{"url":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/92","id":39587286,"html_url":"https://github.com/guardian/subscriptions-frontend/pull/92","diff_url":"https://github.com/guardian/subscriptions-frontend/pull/92.diff","patch_url":"https://github.com/guardian/subscriptions-frontend/pull/92.patch","issue_url":"https://api.github.com/repos/guardian/subscriptions-frontend/issues/92","number":92,"state":"open","locked":false,"title":"Billing frequencies ","user":{"login":"jennysivapalan","id":944375,"avatar_url":"https://avatars.githubusercontent.com/u/944375?v=3","gravatar_id":"","url":"https://api.github.com/users/jennysivapalan","html_url":"https://github.com/jennysivapalan","followers_url":"https://api.github.com/users/jennysivapalan/followers","following_url":"https://api.github.com/users/jennysivapalan/following{/other_user}","gists_url":"https://api.github.com/users/jennysivapalan/gists{/gist_id}","starred_url":"https://api.github.com/users/jennysivapalan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jennysivapalan/subscriptions","organizations_url":"https://api.github.com/users/jennysivapalan/orgs","repos_url":"https://api.github.com/users/jennysivapalan/repos","events_url":"https://api.github.com/users/jennysivapalan/events{/privacy}","received_events_url":"https://api.github.com/users/jennysivapalan/received_events","type":"User","site_admin":false},"body":"Display option for different billing options and sign user up to appropriate plan based on their choice.\r\n\r\nThis isn't ready to merge as I need to work with someone on the layout. @davidrapson if you have time tomorrow that would be great. Currently I've just added a select drop down but it's needs to display the options as a pop up in the You've chosen section.\r\n\r\n~~I've added as a config the price of each plan. This isn't great as if the prices in Zuora change it won't be reflected here. The other option is to call Zuora to get the pricing on start up of an instance, is it worth doing @rtyley ?~~\r\n\r\nPrices is now loaded in on start up (refresh time is daily). Product plans are restricted to Digital Product, rate plans are restricted to British pounds and billing frequency of monthly, quarterly and annually. I've added a healthcheck to ensure there are products fetched otherwise users will not be able to sign up to a plan.\r\n\r\nFinally the thankyou page needs to display the rate plan choice but I'd prefer to wait for https://github.com/guardian/subscriptions-frontend/pull/82","created_at":"2015-07-09T14:13:12Z","updated_at":"2015-07-14T14:51:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f7be28e85663e4b5af86ced5da6b62d81b279896","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/92/commits","review_comments_url":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/92/comments","review_comment_url":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/comments{/number}","comments_url":"https://api.github.com/repos/guardian/subscriptions-frontend/issues/92/comments","statuses_url":"https://api.github.com/repos/guardian/subscriptions-frontend/statuses/8f4508d5c8a90468613d527e3d6378a41bdf6788","head":{"label":"guardian:billing-freq","ref":"billing-freq","sha":"8f4508d5c8a90468613d527e3d6378a41bdf6788","user":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"repo":{"id":34392023,"name":"subscriptions-frontend","full_name":"guardian/subscriptions-frontend","owner":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/guardian/subscriptions-frontend","description":"","fork":false,"url":"https://api.github.com/repos/guardian/subscriptions-frontend","forks_url":"https://api.github.com/repos/guardian/subscriptions-frontend/forks","keys_url":"https://api.github.com/repos/guardian/subscriptions-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guardian/subscriptions-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guardian/subscriptions-frontend/teams","hooks_url":"https://api.github.com/repos/guardian/subscriptions-frontend/hooks","issue_events_url":"https://api.github.com/repos/guardian/subscriptions-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/guardian/subscriptions-frontend/events","assignees_url":"https://api.github.com/repos/guardian/subscriptions-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/guardian/subscriptions-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/guardian/subscriptions-frontend/tags","blobs_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guardian/subscriptions-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/guardian/subscriptions-frontend/languages","stargazers_url":"https://api.github.com/repos/guardian/subscriptions-frontend/stargazers","contributors_url":"https://api.github.com/repos/guardian/subscriptions-frontend/contributors","subscribers_url":"https://api.github.com/repos/guardian/subscriptions-frontend/subscribers","subscription_url":"https://api.github.com/repos/guardian/subscriptions-frontend/subscription","commits_url":"https://api.github.com/repos/guardian/subscriptions-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/guardian/subscriptions-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/guardian/subscriptions-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/guardian/subscriptions-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/guardian/subscriptions-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guardian/subscriptions-frontend/merges","archive_url":"https://api.github.com/repos/guardian/subscriptions-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guardian/subscriptions-frontend/downloads","issues_url":"https://api.github.com/repos/guardian/subscriptions-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/guardian/subscriptions-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/guardian/subscriptions-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guardian/subscriptions-frontend/labels{/name}","releases_url":"https://api.github.com/repos/guardian/subscriptions-frontend/releases{/id}","created_at":"2015-04-22T13:30:13Z","updated_at":"2015-07-14T10:24:07Z","pushed_at":"2015-07-14T14:50:45Z","git_url":"git://github.com/guardian/subscriptions-frontend.git","ssh_url":"git@github.com:guardian/subscriptions-frontend.git","clone_url":"https://github.com/guardian/subscriptions-frontend.git","svn_url":"https://github.com/guardian/subscriptions-frontend","homepage":"https://sites.google.com/a/guardian.co.uk/guardian-subscriptions/","size":4336,"stargazers_count":2,"watchers_count":2,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":2,"default_branch":"master"}},"base":{"label":"guardian:master","ref":"master","sha":"5966094c4cff3d236436e37926fe0892961ead20","user":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"repo":{"id":34392023,"name":"subscriptions-frontend","full_name":"guardian/subscriptions-frontend","owner":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/guardian/subscriptions-frontend","description":"","fork":false,"url":"https://api.github.com/repos/guardian/subscriptions-frontend","forks_url":"https://api.github.com/repos/guardian/subscriptions-frontend/forks","keys_url":"https://api.github.com/repos/guardian/subscriptions-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guardian/subscriptions-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guardian/subscriptions-frontend/teams","hooks_url":"https://api.github.com/repos/guardian/subscriptions-frontend/hooks","issue_events_url":"https://api.github.com/repos/guardian/subscriptions-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/guardian/subscriptions-frontend/events","assignees_url":"https://api.github.com/repos/guardian/subscriptions-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/guardian/subscriptions-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/guardian/subscriptions-frontend/tags","blobs_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guardian/subscriptions-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/guardian/subscriptions-frontend/languages","stargazers_url":"https://api.github.com/repos/guardian/subscriptions-frontend/stargazers","contributors_url":"https://api.github.com/repos/guardian/subscriptions-frontend/contributors","subscribers_url":"https://api.github.com/repos/guardian/subscriptions-frontend/subscribers","subscription_url":"https://api.github.com/repos/guardian/subscriptions-frontend/subscription","commits_url":"https://api.github.com/repos/guardian/subscriptions-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/guardian/subscriptions-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/guardian/subscriptions-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/guardian/subscriptions-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/guardian/subscriptions-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/guardian/subscriptions-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guardian/subscriptions-frontend/merges","archive_url":"https://api.github.com/repos/guardian/subscriptions-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guardian/subscriptions-frontend/downloads","issues_url":"https://api.github.com/repos/guardian/subscriptions-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/guardian/subscriptions-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/guardian/subscriptions-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guardian/subscriptions-frontend/labels{/name}","releases_url":"https://api.github.com/repos/guardian/subscriptions-frontend/releases{/id}","created_at":"2015-04-22T13:30:13Z","updated_at":"2015-07-14T10:24:07Z","pushed_at":"2015-07-14T14:50:45Z","git_url":"git://github.com/guardian/subscriptions-frontend.git","ssh_url":"git@github.com:guardian/subscriptions-frontend.git","clone_url":"https://github.com/guardian/subscriptions-frontend.git","svn_url":"https://github.com/guardian/subscriptions-frontend","homepage":"https://sites.google.com/a/guardian.co.uk/guardian-subscriptions/","size":4336,"stargazers_count":2,"watchers_count":2,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/92"},"html":{"href":"https://github.com/guardian/subscriptions-frontend/pull/92"},"issue":{"href":"https://api.github.com/repos/guardian/subscriptions-frontend/issues/92"},"comments":{"href":"https://api.github.com/repos/guardian/subscriptions-frontend/issues/92/comments"},"review_comments":{"href":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/92/comments"},"review_comment":{"href":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/guardian/subscriptions-frontend/pulls/92/commits"},"statuses":{"href":"https://api.github.com/repos/guardian/subscriptions-frontend/statuses/8f4508d5c8a90468613d527e3d6378a41bdf6788"}}}}