Skip to content

Commit

Permalink
Merge pull request #632 from Automattic/add/no-cc-free-trials
Browse files Browse the repository at this point in the history
Upgrades: No Credit Card Free Trials
  • Loading branch information
Tsarpf committed Dec 2, 2015
2 parents 0606c58 + d8a4d43 commit 7fb3afe
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 83 deletions.
23 changes: 17 additions & 6 deletions client/components/plans/plan-actions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var React = require( 'react' ),
*/
var analytics = require( 'analytics' ),
productsValues = require( 'lib/products-values' ),
config = require( 'config' ),
isFreePlan = productsValues.isFreePlan,
isBusiness = productsValues.isBusiness,
isEnterprise = productsValues.isEnterprise,
Expand Down Expand Up @@ -50,15 +51,15 @@ module.exports = React.createClass( {
return null;
}

const canStartTrial = this.props.siteSpecificPlansDetails.can_start_trial;
const canStartTrial = config.isEnabled( 'upgrades/free-trials' ) ? this.props.siteSpecificPlansDetails.can_start_trial : false;

return canStartTrial ? this.newPlanActions() : this.upgradeActions();
},

upgradeActions: function() {
return (
<div>
<button className='button is-primary plan-actions__upgrade-button'
<button className="button is-primary plan-actions__upgrade-button"
onClick={ this.handleAddToCart.bind( null, this.cartItem( { isFreeTrial: false } ), 'button' ) }>
{ this.translate( 'Upgrade Now' ) }
</button>
Expand Down Expand Up @@ -159,9 +160,18 @@ module.exports = React.createClass( {
return (
<div>
<button className="button is-primary plan-actions__upgrade-button"
onClick={ this.handleAddToCart.bind( null, this.cartItem( { isFreeTrial: false } ), 'button' ) }>
{ this.translate( 'Upgrade Now', { context: 'Store action' } ) }
onClick={ this.handleAddToCart.bind( null, this.cartItem( { isFreeTrial: true } ), 'button' ) }>
{ this.translate( 'Start Free Trial', { context: 'Store action' } ) }
</button>

<small className="plan-actions__trial-period">
{ this.translate( 'Try it free for 14 days, no credit card needed, or {{a}}upgrade now{{/a}}.', {
context: 'Store action',
components: {
a: <a href="#"
onClick={ this.handleAddToCart.bind( null, this.cartItem( { isFreeTrial: false } ), 'link' ) } />
} } ) }
</small>
</div>
);
},
Expand Down Expand Up @@ -191,7 +201,7 @@ module.exports = React.createClass( {
},

freePlanExpiration: function() {
if ( ! this.planHasCost() ) {
if ( config.isEnabled( 'upgrades/free-trials' ) && ! this.planHasCost() ) {
return (
<span className="plan-actions__plan-expiration">{ this.translate( 'Never expires', { context: 'Expiration info for free plan in /plans/' } ) }</span>
);
Expand All @@ -210,7 +220,7 @@ module.exports = React.createClass( {
strong: <strong />,
link: <a href='#'
className="plan-actions__trial-upgrade-now"
onClick={ this.recordUpgradeTrialNowClick.bind( null, this.cartItem( { isFreeTrial: false } ), 'link' ) } />
onClick={ this.handleAddToCart.bind( null, this.cartItem( { isFreeTrial: false } ), 'link' ) } />
},
hint;

Expand Down Expand Up @@ -249,6 +259,7 @@ module.exports = React.createClass( {
<div>
<span className="plan-actions__current-plan-label" onClick={ this.recordCurrentPlanClick }>
{ this.translate( 'Your current plan', { context: 'Informing the user of their current plan on /plans/' } ) }</span>
{ this.freePlanExpiration() }
</div>
);
},
Expand Down
7 changes: 6 additions & 1 deletion client/components/plans/plan-actions/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@
text-align: center;
line-height: 16px;
display: block;
padding: 5px 10px;
padding: 5px 10px 0 5px;
color: $gray-dark;
opacity: .8;
}

.plan-actions__plan-expiration,
.plan-actions__trial-period {
height: 40px;
}

.plan-actions.is-placeholder {
.plan-actions__upgrade-button {
@include placeholder( 23% );
Expand Down
3 changes: 1 addition & 2 deletions client/my-sites/upgrades/cart/cart-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ module.exports = React.createClass( {

return (
<span>
{ freeTrialText }<br />
{ renewalPrice }
{ freeTrialText }
</span>
);
},
Expand Down
57 changes: 57 additions & 0 deletions client/my-sites/upgrades/checkout/free-trial-confirmation-box.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

/**
* External dependencies
*/
var React = require( 'react' ),
classNames = require( 'classnames' );

/**
* Internal dependencies
*/
var PayButton = require( './pay-button' ),
PaymentBox = require( './payment-box' ),
TermsOfService = require( './terms-of-service' );

var FreeTrialConfirmationBox = React.createClass( {
content: function() {
return (
<form onSubmit={ this.props.onSubmit }>
<div className="payment-box-section">
<h6>
{
this.translate( 'Get started with %(productName)s', { args: { productName: this.props.cart.products[0].product_name } } )
}
</h6>

<span>
{
this.translate( 'Enjoy your free trial with no strings attached: your site will simply revert to the free plan when the period is over.' )
}
</span>
</div>

<TermsOfService />
<div className="payment-box-actions">
<PayButton
cart={ this.props.cart }
transactionStep={ this.props.transactionStep } />
</div>
</form>
);
},

render: function() {
var classSet = classNames( {
'credits-payment-box': true,
selected: this.props.selected === true
} );

return (
<PaymentBox classSet={ classSet }>
{ this.content() }
</PaymentBox>
);
}
} );

module.exports = FreeTrialConfirmationBox;
9 changes: 8 additions & 1 deletion client/my-sites/upgrades/checkout/pay-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var React = require( 'react' );
*/
var cartValues = require( 'lib/cart-values' ),
cartItems = cartValues.cartItems,
hasFreeTrial = cartItems.hasFreeTrial,
isPaidForFullyInCredits = cartValues.isPaidForFullyInCredits,
SubscriptionText = require( './subscription-text' );

Expand Down Expand Up @@ -112,9 +113,15 @@ var PayButton = React.createClass( {
},

completing: function() {
var text;
if ( hasFreeTrial( this.props.cart ) ) {
text = this.translate( 'Starting your free trial…', { context: 'Loading state on /checkout' } )
} else {
text = this.translate( 'Completing your purchase', { context: 'Loading state on /checkout' } )
}
return {
disabled: true,
text: this.translate( 'Completing your purchase', { context: 'Loading state on /checkout' } )
text: text
};
},

Expand Down
11 changes: 11 additions & 0 deletions client/my-sites/upgrades/checkout/secure-payment-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var React = require( 'react/addons' );
* Internal dependencies
*/
var CreditCardPaymentBox = require( './credit-card-payment-box' ),
FreeTrialConfirmationBox = require( './free-trial-confirmation-box' ),
PayPalPaymentBox = require( './paypal-payment-box' ),
CreditsPaymentBox = require( './credits-payment-box' ),
FreeCartPaymentBox = require( './free-cart-payment-box' ),
Expand All @@ -16,6 +17,7 @@ var CreditCardPaymentBox = require( './credit-card-payment-box' ),
cartValues = require( 'lib/cart-values' ),
isPaidForFullyInCredits = cartValues.isPaidForFullyInCredits,
isFree = cartValues.isFree,
hasFreeTrial = cartValues.cartItems.hasFreeTrial,
countriesList = require( 'lib/countries-list' ).forPayments(),
analytics = require( 'analytics' ),
TransactionStepsMixin = require( './transaction-steps-mixin' ),
Expand Down Expand Up @@ -43,6 +45,8 @@ var SecurePaymentForm = React.createClass( {
return 'credits';
} else if ( isFree( cart ) ) {
return 'free-cart';
} else if ( hasFreeTrial( cart ) ) {
return 'free-trial';
} else if ( this.state && this.state.userSelectedPaymentBox ) {
return this.state.userSelectedPaymentBox;
} else {
Expand Down Expand Up @@ -78,6 +82,12 @@ var SecurePaymentForm = React.createClass( {
onSubmit={ this.handlePaymentBoxSubmit }
transactionStep={ this.props.transaction.step } />

<FreeTrialConfirmationBox
cart={ this.props.cart }
selected={ this.state.visiblePaymentBox === 'free-trial' }
onSubmit={ this.handlePaymentBoxSubmit }
transactionStep={ this.props.transaction.step } />

<FreeCartPaymentBox
cart={ this.props.cart }
selected={ this.state.visiblePaymentBox === 'free-cart' }
Expand Down Expand Up @@ -131,6 +141,7 @@ var SecurePaymentForm = React.createClass( {

switch ( this.state.visiblePaymentBox ) {
case 'credits':
case 'free-trial':
case 'free-cart':
// FIXME: The endpoint doesn't currently support transactions with no
// payment info, so for now we rely on the credits payment method for
Expand Down
28 changes: 12 additions & 16 deletions client/my-sites/upgrades/checkout/supporting-text.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@ var React = require( 'react' );
*/
var cartValues = require( 'lib/cart-values' ),
getRefundPolicy = cartValues.getRefundPolicy,
cartItems = cartValues.cartItems;
cartItems = cartValues.cartItems,
hasFreeTrial = cartItems.hasFreeTrial;

var SupportingText = React.createClass( {

creditCardSupportingText: function() {
var cart = this.props.cart,
title,
var title,
content;

if ( cartItems.hasFreeTrial( cart ) ) {
title = this.translate( 'Why do you need my credit card?' );
content = this.translate( 'You will only be charged at the end of the trial. Cancel any time before then and pay nothing.' );
} else {
title = this.translate( 'Easy Refunds' );
content = this.refundText();
}
title = this.translate( 'Easy Refunds' );
content = this.refundText();

return this.supportingTextBox( 'credit-card-supporting-text', title, content );
},
Expand Down Expand Up @@ -75,12 +70,13 @@ var SupportingText = React.createClass( {
},

render: function() {
return (
<ul className="supporting-text">
{ this.creditCardSupportingText() }
{ this.liveChatSupportingText() }
</ul>
);
return hasFreeTrial( this.props.cart )
? null : (
<ul className="supporting-text">
{ this.creditCardSupportingText() }
{ this.liveChatSupportingText() }
</ul>
);
}

} );
Expand Down
Loading

0 comments on commit 7fb3afe

Please sign in to comment.