Initial Spark Install
This commit is contained in:
41
spark/resources/assets/js/settings/payment-method/redeem-coupon.js
vendored
Normal file
41
spark/resources/assets/js/settings/payment-method/redeem-coupon.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
module.exports = {
|
||||
props: ['user', 'team', 'billableType'],
|
||||
|
||||
/**
|
||||
* The component's data.
|
||||
*/
|
||||
data() {
|
||||
return {
|
||||
form: new SparkForm({
|
||||
coupon: ''
|
||||
})
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
methods: {
|
||||
/**
|
||||
* Redeem the given coupon code.
|
||||
*/
|
||||
redeem() {
|
||||
Spark.post(this.urlForRedemption, this.form)
|
||||
.then(() => {
|
||||
this.form.coupon = '';
|
||||
|
||||
this.$parent.$emit('updateDiscount');
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
computed: {
|
||||
/**
|
||||
* Get the URL for redeeming a coupon.
|
||||
*/
|
||||
urlForRedemption() {
|
||||
return this.billingUser
|
||||
? '/settings/payment-method/coupon'
|
||||
: `/settings/${Spark.pluralTeamString}/${this.team.id}/payment-method/coupon`;
|
||||
}
|
||||
}
|
||||
};
|
104
spark/resources/assets/js/settings/payment-method/update-payment-method-braintree.js
vendored
Normal file
104
spark/resources/assets/js/settings/payment-method/update-payment-method-braintree.js
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
module.exports = {
|
||||
props: ['user', 'team', 'billableType'],
|
||||
|
||||
|
||||
/**
|
||||
* Load mixins for the component.
|
||||
*/
|
||||
mixins: [
|
||||
require('./../../mixins/braintree')
|
||||
],
|
||||
|
||||
|
||||
/**
|
||||
* The component's data.
|
||||
*/
|
||||
data() {
|
||||
return {
|
||||
form: new SparkForm({
|
||||
braintree_type: '',
|
||||
braintree_token: '',
|
||||
})
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the component.
|
||||
*/
|
||||
mounted() {
|
||||
this.braintree(
|
||||
'braintree-payment-method-container',
|
||||
this.braintreeCallback
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
methods: {
|
||||
/**
|
||||
* Update the entity's card information.
|
||||
*/
|
||||
update() {
|
||||
Spark.put(this.urlForUpdate, this.form)
|
||||
.then(() => {
|
||||
Bus.$emit('updateUser');
|
||||
Bus.$emit('updateTeam');
|
||||
|
||||
this.resetBraintree(
|
||||
'braintree-payment-method-container',
|
||||
this.braintreeCallback
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* The Braintree payment method received callback.
|
||||
*/
|
||||
braintreeCallback(response) {
|
||||
this.form.braintree_type = response.type;
|
||||
this.form.braintree_token = response.nonce;
|
||||
|
||||
this.update();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
computed: {
|
||||
/**
|
||||
* Get the URL for the payment method update.
|
||||
*/
|
||||
urlForUpdate() {
|
||||
return this.billingUser
|
||||
? '/settings/payment-method'
|
||||
: `/settings/${Spark.pluralTeamString}/${this.team.id}/payment-method`;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Get the proper brand icon for the customer's credit card.
|
||||
*/
|
||||
cardIcon() {
|
||||
if (! this.billable.card_brand) {
|
||||
return 'fa-credit-card';
|
||||
}
|
||||
|
||||
switch (this.billable.card_brand) {
|
||||
case 'American Express':
|
||||
return 'fa-cc-amex';
|
||||
case 'Diners Club':
|
||||
return 'fa-cc-diners-club';
|
||||
case 'Discover':
|
||||
return 'fa-cc-discover';
|
||||
case 'JCB':
|
||||
return 'fa-cc-jcb';
|
||||
case 'MasterCard':
|
||||
return 'fa-cc-mastercard';
|
||||
case 'Visa':
|
||||
return 'fa-cc-visa';
|
||||
default:
|
||||
return 'fa-credit-card';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
183
spark/resources/assets/js/settings/payment-method/update-payment-method-stripe.js
vendored
Normal file
183
spark/resources/assets/js/settings/payment-method/update-payment-method-stripe.js
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
module.exports = {
|
||||
props: ['user', 'team', 'billableType'],
|
||||
|
||||
/**
|
||||
* The component's data.
|
||||
*/
|
||||
data() {
|
||||
return {
|
||||
form: new SparkForm({
|
||||
stripe_token: '',
|
||||
address: '',
|
||||
address_line_2: '',
|
||||
city: '',
|
||||
state: '',
|
||||
zip: '',
|
||||
country: 'US'
|
||||
}),
|
||||
|
||||
cardForm: new SparkForm({
|
||||
name: '',
|
||||
number: '',
|
||||
cvc: '',
|
||||
month: '',
|
||||
year: ''
|
||||
})
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the component.
|
||||
*/
|
||||
mounted() {
|
||||
Stripe.setPublishableKey(Spark.stripeKey);
|
||||
|
||||
this.initializeBillingAddress();
|
||||
},
|
||||
|
||||
|
||||
methods: {
|
||||
/**
|
||||
* Initialize the billing address form for the billable entity.
|
||||
*/
|
||||
initializeBillingAddress() {
|
||||
if (! Spark.collectsBillingAddress) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.form.address = this.billable.billing_address;
|
||||
this.form.address_line_2 = this.billable.billing_address_line_2;
|
||||
this.form.city = this.billable.billing_city;
|
||||
this.form.state = this.billable.billing_state;
|
||||
this.form.zip = this.billable.billing_zip;
|
||||
this.form.country = this.billable.billing_country || 'US';
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Update the billable's card information.
|
||||
*/
|
||||
update() {
|
||||
this.form.busy = true;
|
||||
this.form.errors.forget();
|
||||
this.form.successful = false;
|
||||
this.cardForm.errors.forget();
|
||||
|
||||
// Here we will build out the payload to send to Stripe to obtain a card token so
|
||||
// we can create the actual subscription. We will build out this data that has
|
||||
// this credit card number, CVC, etc. and exchange it for a secure token ID.
|
||||
const payload = {
|
||||
name: this.cardForm.name,
|
||||
number: this.cardForm.number,
|
||||
cvc: this.cardForm.cvc,
|
||||
exp_month: this.cardForm.month,
|
||||
exp_year: this.cardForm.year,
|
||||
address_line1: this.form.address,
|
||||
address_line2: this.form.address_line_2,
|
||||
address_city: this.form.city,
|
||||
address_state: this.form.state,
|
||||
address_zip: this.form.zip,
|
||||
address_country: this.form.country,
|
||||
};
|
||||
|
||||
// Once we have the Stripe payload we'll send it off to Stripe and obtain a token
|
||||
// which we will send to the server to update this payment method. If there is
|
||||
// an error we will display that back out to the user for their information.
|
||||
Stripe.card.createToken(payload, (status, response) => {
|
||||
if (response.error) {
|
||||
this.cardForm.errors.set({number: [
|
||||
response.error.message
|
||||
]});
|
||||
|
||||
this.form.busy = false;
|
||||
} else {
|
||||
this.sendUpdateToServer(response.id);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Send the credit card update information to the server.
|
||||
*/
|
||||
sendUpdateToServer(token) {
|
||||
this.form.stripe_token = token;
|
||||
|
||||
Spark.put(this.urlForUpdate, this.form)
|
||||
.then(() => {
|
||||
Bus.$emit('updateUser');
|
||||
Bus.$emit('updateTeam');
|
||||
|
||||
this.cardForm.name = '';
|
||||
this.cardForm.number = '';
|
||||
this.cardForm.cvc = '';
|
||||
this.cardForm.month = '';
|
||||
this.cardForm.year = '';
|
||||
|
||||
if ( ! Spark.collectsBillingAddress) {
|
||||
this.form.zip = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
computed: {
|
||||
/**
|
||||
* Get the billable entity's "billable" name.
|
||||
*/
|
||||
billableName() {
|
||||
return this.billingUser ? this.user.name : this.team.owner.name;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Get the URL for the payment method update.
|
||||
*/
|
||||
urlForUpdate() {
|
||||
return this.billingUser
|
||||
? '/settings/payment-method'
|
||||
: `/settings/${Spark.pluralTeamString}/${this.team.id}/payment-method`;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Get the proper brand icon for the customer's credit card.
|
||||
*/
|
||||
cardIcon() {
|
||||
if (! this.billable.card_brand) {
|
||||
return 'fa-cc-stripe';
|
||||
}
|
||||
|
||||
switch (this.billable.card_brand) {
|
||||
case 'American Express':
|
||||
return 'fa-cc-amex';
|
||||
case 'Diners Club':
|
||||
return 'fa-cc-diners-club';
|
||||
case 'Discover':
|
||||
return 'fa-cc-discover';
|
||||
case 'JCB':
|
||||
return 'fa-cc-jcb';
|
||||
case 'MasterCard':
|
||||
return 'fa-cc-mastercard';
|
||||
case 'Visa':
|
||||
return 'fa-cc-visa';
|
||||
default:
|
||||
return 'fa-cc-stripe';
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Get the placeholder for the billable entity's credit card.
|
||||
*/
|
||||
placeholder() {
|
||||
if (this.billable.card_last_four) {
|
||||
return `************${this.billable.card_last_four}`;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
};
|
42
spark/resources/assets/js/settings/payment-method/update-vat-id.js
vendored
Normal file
42
spark/resources/assets/js/settings/payment-method/update-vat-id.js
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
module.exports = {
|
||||
props: ['user', 'team', 'billableType'],
|
||||
|
||||
/**
|
||||
* The component's data.
|
||||
*/
|
||||
data() {
|
||||
return {
|
||||
form: new SparkForm({ vat_id: '' })
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Bootstrap the component.
|
||||
*/
|
||||
mounted() {
|
||||
this.form.vat_id = this.billable.vat_id;
|
||||
},
|
||||
|
||||
|
||||
methods: {
|
||||
/**
|
||||
* Update the customer's VAT ID.
|
||||
*/
|
||||
update() {
|
||||
Spark.put(this.urlForUpdate, this.form);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
computed: {
|
||||
/**
|
||||
* Get the URL for the VAT ID update.
|
||||
*/
|
||||
urlForUpdate() {
|
||||
return this.billingUser
|
||||
? '/settings/payment-method/vat-id'
|
||||
: `/settings/${Spark.pluralTeamString}/${this.team.id}/payment-method/vat-id`;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user