PHP code example of potelo / mo-payment
1. Go to this page and download the library: Download potelo/mo-payment 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/ */
potelo / mo-payment example snippets
Potelo\MoPayment\MoPaymentServiceProvider::class,
use Potelo\MoPayment\MoPaymentTrait;
class User extends Authenticatable
{
use MoPaymentTrait;
}
'moip' => [
'model' => App\User::class,
'webhook_authorization' => env('MOIP_WEBHOOK_AUTHORIZATION'),
'token' => env('MOIP_APITOKEN'),
'key' => env('MOIP_APIKEY'),
'signature_table' => env('MOPAYMENT_SIGNATURE_TABLE'),
'env' => env('MOIP_ENV'),
'model_foreign_key' => env('MOIP_MODEL_FOREIGN_KEY'),
'subscription_model_id_column' => env('MOIP_SUBSCRIPTION_MODEL_ID_COLUMN'),
'subscription_model_plan_column' => env('MOIP_SUBSCRIPTION_MODEL_PLAN_COLUMN'),
],
$user = User::find(1);
$user->newSubscription('main',
'plan_code',
'CREDIT_CARD'
)->create();
$user = User::find(1);
$user->newSubscription('main',
'plan_code',
'CREDIT_CARD'
)->amount(2090)
->create();
$user = User::find(1);
$user->newSubscription('main',
'plan_code',
'CREDIT_CARD'
)->coupon('codigo_cupom')
->create();
if ($user->subscribed('main')) {
//
}
if ($user->subscription('main')->onTrial()) {
//
}
if ($user->subscription('main')->suspended()) {
//
}
if ($user->subscription('main')->onGracePeriod()) {
//
}
$user->subscription('main')->suspend();
$user->subscription('main')->resume();
$invoices = $user->invoices('subscription_code');
$options = [
'fullname' => 'Joao Silva',
'email' => '[email protected] ',
'phone_area_code' => '11',
'phone_number' => '999887766',
'cpf' => '01234567891',
'birthdate_day' => '2',
'birthdate_month' => '2',
'birthdate_year' => '2000',
'address' => [
'street' => 'Rua de Cima',
'number' => '1000',
'complement' => 'Casa',
'district' => 'Bairro Azul',
'city' => 'São Paulo',
'state' => 'SP',
'country' => 'BRA',
'zipcode' => '05015010',
],
'billing_info' => [
'credit_card' => [
'holder_name' => 'Joao Silva',
'number' => '4111111111111111',
'expiration_month' => '08',
'expiration_year' => '20'
]
]
];
// Criar assinante no Moip
$user->createAsMoipCustomer($options);
Route::post('webhook', '\Potelo\MoPayment\Http\Controllers\WebhookController@handleWebhook');
protected $except = [
'webhook',
];
Route::post('webhook', 'MeuWebhookController@handleWebhook');
namespace App\Http\Controllers;
use Potelo\GuPayment\Http\Controllers\WebhookController;
class MeuWebhookController extends WebhookController {
public function handleInvoiceCreated(array $payload)
{
return 'Fatura criada: ' . $payload['resource']['id'];
}
}
php artisan vendor:publish --tag=migrations