Эх сурвалжийг харах

change plan shows price including tax

Henry Oswald 11 жил өмнө
parent
commit
7030d5f822

+ 2 - 3
services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee

@@ -130,6 +130,7 @@ module.exports = RecurlyWrapper =
 						logger.err err:err, "could not get accoutns"
 						callback(err)
 					allAccounts = allAccounts.concat(data.accounts)
+					logger.log "got another #{data.accounts.length}, total now #{allAccounts.length}"
 					cursor = response.headers.link?.match(/cursor=([0-9]+)&/)?[1]
 					if cursor?
 						getPageOfAccounts(cursor)
@@ -188,7 +189,7 @@ module.exports = RecurlyWrapper =
 				<applies_to_all_plans>false</applies_to_all_plans>
 			</coupon>
 		"""
-		# logger.log coupon_code:coupon_code, requestBody:requestBody, "creating coupon"
+		logger.log coupon_code:coupon_code, requestBody:requestBody, "creating coupon"
 		@apiRequest({
 			url    : "coupons"
 			method : "post"
@@ -247,8 +248,6 @@ module.exports = RecurlyWrapper =
 
 
 	_parseSubscriptionXml: (xml, callback) ->
-		console.log xml, "_parseAccountXml"
-
 		@_parseXml xml, (error, data) ->
 			return callback(error) if error?
 			if data? and data.subscription?

+ 1 - 0
services/web/app/coffee/Features/Subscription/SubscriptionViewModelBuilder.coffee

@@ -25,6 +25,7 @@ module.exports =
 							price: SubscriptionFormatters.formatPrice (recurlySubscription?.unit_amount_in_cents + tax), recurlySubscription?.currency
 							planCode: subscription.planCode
 							currency:recurlySubscription?.currency
+							taxRate:parseFloat(recurlySubscription?.tax_rate?._)
 							groupPlan: subscription.groupPlan
 						}, memberSubscriptions
 				else

+ 10 - 2
services/web/app/views/subscriptions/dashboard.jade

@@ -1,7 +1,14 @@
 extends ../layout
 block scripts
+	script(src="https://js.recurly.com/v3/recurly.js")
 	script(type='text/javascript').
+
 		window.recomendedCurrency = '#{recomendedCurrency}'
+		window.recurlyApiKey = "!{settings.apis.recurly.publicKey}"
+		window.taxRate = #{subscription.taxRate}
+
+
+
 
 mixin printPlan(plan)
 	-if (!plan.hideFromUsers)
@@ -9,10 +16,11 @@ mixin printPlan(plan)
 			td(ng-init="plan=#{JSON.stringify(plan)}")
 				strong #{plan.name}
 			td
+				{{refreshPrice(plan.planCode)}}
 				-if (plan.annual)
-					| {{plans[currencyCode][plan.planCode.replace("-annual","")]['annual']}} / #{translate("year")}
+					| {{prices[plan.planCode]}} / #{translate("year")}
 				-else
-					| {{plans[currencyCode][plan.planCode]['monthly']}} / #{translate("month")}
+					| {{prices[plan.planCode]}} / #{translate("month")}
 			td
 				-if (subscription.state == "free-trial")
 					a(href="/user/subscription/new?planCode=#{plan.planCode}").btn.btn-success #{translate("subscribe_to_this_plan")}

+ 15 - 2
services/web/public/coffee/main/subscription-dashboard.coffee

@@ -2,9 +2,9 @@ define [
 	"base"
 ], (App)->
 	SUBSCRIPTION_URL = "/user/subscription/update"
+	recurly.configure window.recurlyApiKey
 
-
-	App.controller "CurrenyDropdownController", ($scope, MultiCurrencyPricing)->
+	App.controller "CurrenyDropdownController", ($scope, MultiCurrencyPricing, $q)->
 
 		$scope.plans = MultiCurrencyPricing.plans
 		$scope.currencyCode = MultiCurrencyPricing.currencyCode
@@ -15,6 +15,9 @@ define [
 
 	App.controller "ChangePlanFormController", ($scope, $modal, MultiCurrencyPricing)->
 
+		
+		taxRate = window.taxRate
+
 		$scope.changePlan = ->
 			$modal.open(
 				templateUrl: "confirmChangePlanModalTemplate"
@@ -27,9 +30,19 @@ define [
 
 		$scope.pricing = MultiCurrencyPricing
 		$scope.plans = MultiCurrencyPricing.plans
+		$scope.currencySymbol = MultiCurrencyPricing.plans[MultiCurrencyPricing.currencyCode].symbol
 
 		$scope.currencyCode = MultiCurrencyPricing.currencyCode
 
+		$scope.prices = {}
+		$scope.refreshPrice = (planCode)->
+			if $scope.prices[planCode]?
+				return
+			pricing = recurly.Pricing()
+			pricing.plan(planCode, { quantity: 1 }).done (price)->
+				totalPriceExTax = parseFloat(price.next.total)
+				$scope.prices[planCode] = $scope.currencySymbol + (totalPriceExTax + (totalPriceExTax * taxRate))
+			price = ""