PHP code example of nguoingulanh / cashier-connect
1. Go to this page and download the library: Download nguoingulanh/cashier-connect library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nguoingulanh / cashier-connect example snippets
use Nguoingulanh\CashierConnect\Concerns\ConnectBillable;
class Shop extends Model
{
use ConnectBillable;
}
use Nguoingulanh\CashierConnect\Facades\CashierConnect;
// With the trait // Without the trait
$shop->createConnectAccount(); CashierConnect::for($shop)->create();
$shop->hasConnectAccount(); CashierConnect::for($shop)->hasAccount();
$shop->connectAccount; CashierConnect::for($shop)->account(); // local model
$shop->asStripeConnectAccount(); CashierConnect::for($shop)->asStripeAccount(); // \Stripe\Account
$shop->updateConnectAccount([...]);
$shop->syncConnectAccount();
$shop->deleteConnectAccount();
$shop->isConnectReady(); // charges and payouts enabled
$shop->connectRequirements(); // currently_due, past_due, disabled_reason...
Route::get('/seller/onboarding', function (Request $request) {
return redirect($request->user()->connectOnboardingUrl(route('seller.dashboard')));
});
$shop->connectUpdateUrl(); // let the seller update their details
$shop->connectDashboardUrl(); // Express dashboard login link
$shop->connectAccountSession(['payments', 'payouts']); // client_secret for embedded components
// One-off charge: $100, the platform keeps $10
$user->charge(10000, $paymentMethod, CashierConnect::destination($shop)->fee(1000)->toArray());
// Percentage fee needs the amount
$user->charge(10000, $paymentMethod, CashierConnect::destination($shop)->feePercent(10)->toArray(10000));
// Checkout
$user->checkout(['price_123' => 1], CashierConnect::destination($shop)->fee(500)->forCheckout());
// Subscriptions: a percentage of every invoice
$user->newSubscription('default', 'price_monthly')
->create($paymentMethod, [], CashierConnect::destination($shop)->feePercent(10)->forSubscription());
// Subscription Checkout
$user->newSubscription('default', 'price_monthly')
->checkout(CashierConnect::destination($shop)->feePercent(10)->forSubscriptionCheckout());
$transfer = $shop->transferToConnect(5000, 'usd', ['transfer_group' => 'ORDER_1']);
$shop->reverseConnectTransfer($transfer->id, 2000);
$shop->connectTransfers();
$shop->connectBalance(); // \Stripe\Balance of the connected account
$shop->connectPayout(5000); // pay out to the seller's bank account
$shop->connectPayouts();
// Destination charge: take the money back from the seller and refund your fee
CashierConnect::refund('pi_123', reverseTransfer: true, refundApplicationFee: true);
// Partial refund of a direct charge (made on the connected account)
CashierConnect::refund('pi_123', amount: 500, onAccount: $shop);