-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6b10087
Showing
11 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/dist | ||
/.idea | ||
/vendor | ||
/node_modules | ||
package-lock.json | ||
composer.phar | ||
composer.lock | ||
phpunit.xml | ||
.phpunit.result.cache | ||
.DS_Store | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "depsimon/nova-stripe-payment-field", | ||
"description": "A Laravel Nova field that shows a Stripe Checkout Button.", | ||
"keywords": [ | ||
"laravel", | ||
"nova" | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=7.1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Depsimon\\NovaStripePaymentField\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Depsimon\\NovaStripePaymentField\\FieldServiceProvider" | ||
] | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"/dist/js/field.js": "/dist/js/field.js", | ||
"/dist/css/field.css": "/dist/css/field.css" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"dev": "npm run development", | ||
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", | ||
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", | ||
"watch-poll": "npm run watch -- --watch-poll", | ||
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", | ||
"prod": "npm run production", | ||
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" | ||
}, | ||
"devDependencies": { | ||
"cross-env": "^5.0.0", | ||
"laravel-mix": "^1.0", | ||
"laravel-nova": "^1.0" | ||
}, | ||
"dependencies": { | ||
"vue": "^2.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<template> | ||
<default-field :field="field"> | ||
<template slot="field"> | ||
<button v-if="! value" @click.prevent="checkout" class="btn btn-default btn-primary"> | ||
<span v-html="field.label"></span> | ||
</button> | ||
<button v-else @click.prevent="cancel" class="btn btn-default btn-danger flex items-center justify-center"> | ||
<icon type="delete" class="text-white" style="margin-right: 7px" /> | ||
<span v-html="field.cancelLabel"></span></button> | ||
</template> | ||
</default-field> | ||
</template> | ||
|
||
<script> | ||
import { FormField } from 'laravel-nova' | ||
export default { | ||
mixins: [FormField], | ||
props: ['resourceName', 'resourceId', 'field'], | ||
data () { | ||
return { | ||
$checkout: null | ||
} | ||
}, | ||
mounted () { | ||
this.initStripe() | ||
}, | ||
methods: { | ||
cancel() { | ||
this.handleChange(null) | ||
}, | ||
initStripe() { | ||
this.$checkout = StripeCheckout.configure({ | ||
key: this.field.key, | ||
locale: this.field.locale, | ||
name: this.field.company, | ||
description: this.field.description, | ||
amount: this.field.amount, | ||
currency: this.field.currency, | ||
token: (token) => { | ||
this.handleChange(token.id) | ||
} | ||
}) | ||
}, | ||
checkout() { | ||
this.$checkout.open() | ||
}, | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Nova.booting((Vue, router) => { | ||
Vue.component('form-nova-stripe-payment-field', require('./components/FormField')); | ||
|
||
const script = document.createElement('script'); | ||
script.src = 'https://checkout.stripe.com/checkout.js'; | ||
document.getElementsByTagName('head')[0].appendChild(script); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Nova Tool CSS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Depsimon\NovaStripePaymentField; | ||
|
||
use Laravel\Nova\Nova; | ||
use Laravel\Nova\Events\ServingNova; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class FieldServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap any application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
Nova::serving(function (ServingNova $event) { | ||
Nova::script('nova-stripe-payment-field', __DIR__.'/../dist/js/field.js'); | ||
Nova::style('nova-stripe-payment-field', __DIR__.'/../dist/css/field.css'); | ||
}); | ||
} | ||
|
||
/** | ||
* Register any application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
namespace Depsimon\NovaStripePaymentField; | ||
|
||
use Laravel\Nova\Fields\Field; | ||
|
||
class NovaStripePaymentField extends Field | ||
{ | ||
/** | ||
* The field's component. | ||
* | ||
* @var string | ||
*/ | ||
public $component = 'nova-stripe-payment-field'; | ||
|
||
/** | ||
* Create a new field. | ||
* | ||
* @param string $name | ||
* @param string|null $attribute | ||
* @param mixed|null $resolveCallback | ||
* @return void | ||
*/ | ||
public function __construct($name, $attribute = null, $resolveCallback = null) | ||
{ | ||
parent::__construct($name, $attribute, $resolveCallback); | ||
|
||
$this->key(config('services.stripe.key')) | ||
->company(config('app.name')) | ||
->locale('auto') | ||
->label('Checkout') | ||
->cancelLabel('Cancel'); | ||
} | ||
|
||
/** | ||
* Set the Stripe API key. | ||
* | ||
* @param string $key | ||
* @return $this | ||
*/ | ||
public function key($key) | ||
{ | ||
return $this->withMeta(['key' => $key]); | ||
} | ||
|
||
/** | ||
* Set the relative or absolute URL pointing to a square image of your brand or product. | ||
* The recommended minimum size is 128x128px.The supported image types are: .gif, .jpeg, and .png. | ||
* | ||
* @param string $image | ||
* @return $this | ||
*/ | ||
public function image($image) | ||
{ | ||
return $this->withMeta(['image' => $image]); | ||
} | ||
|
||
/** | ||
* Set the name of your company or website. | ||
* | ||
* @param string $company | ||
* @return $this | ||
*/ | ||
public function company($company) | ||
{ | ||
return $this->withMeta(['company' => $company]); | ||
} | ||
|
||
/** | ||
* Set the description of the product or service being purchased. | ||
* | ||
* @param string $description | ||
* @return $this | ||
*/ | ||
public function description($description) | ||
{ | ||
return $this->withMeta(['description' => $description]); | ||
} | ||
|
||
/** | ||
* Set the amount (in cents) that's shown to the user. | ||
* Note that you will still have to explicitly include the amount when you create a charge using the API. | ||
* (You will also need to provide Checkout with a data-currency value to change the default of USD.) | ||
* | ||
* @param string $amount | ||
* @return $this | ||
*/ | ||
public function amount($amount) | ||
{ | ||
return $this->withMeta(['amount' => $amount]); | ||
} | ||
|
||
/** | ||
* Set the currency. | ||
* | ||
* @param string $currency | ||
* @return $this | ||
*/ | ||
public function currency($currency) | ||
{ | ||
return $this->withMeta(['currency' => $currency]); | ||
} | ||
|
||
/** | ||
* Set the locale. | ||
* | ||
* @param string $locale | ||
* @return $this | ||
*/ | ||
public function locale($locale) | ||
{ | ||
return $this->withMeta(['locale' => $locale]); | ||
} | ||
|
||
/** | ||
* Set the label of the checkout button. | ||
* | ||
* @param string $label | ||
* @return $this | ||
*/ | ||
public function label($label) | ||
{ | ||
return $this->withMeta(['label' => $label]); | ||
} | ||
|
||
/** | ||
* Set the label of the cancel button. | ||
* | ||
* @param string $cancelLabel | ||
* @return $this | ||
*/ | ||
public function cancelLabel($cancelLabel) | ||
{ | ||
return $this->withMeta(['cancelLabel' => $cancelLabel]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
let mix = require('laravel-mix') | ||
|
||
mix.js('resources/js/field.js', 'dist/js') | ||
.sass('resources/sass/field.scss', 'dist/css') | ||
.webpackConfig({ | ||
resolve: { | ||
symlinks: false | ||
} | ||
}) |