PHP code example of tmazza / wirecard-subscriptions-sdk

1. Go to this page and download the library: Download tmazza/wirecard-subscriptions-sdk 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/ */

    

tmazza / wirecard-subscriptions-sdk example snippets



use tmazza\WirecardSubscriptions\WirecardApi;

$wirecardApi = new WirecardApi();


# Lista de planos
$plans = $wirecardApi->plans->all();

foreach($plans as $plan) {
    // $plan->code
}

# Criação de usuário
$wirecardApi->customers->create([ ... ]); 

# Criação de assinatura
$wirecardApi->subscriptions->create([ ... ]); 

# Consulta de assinatura
$wirecardApi->subscriptions->get('code');


try {
  
  $wirecardApi = new WirecardApi();
  $wirecardApi->plans->create(['...']);

} catch (ValidationException $e) {

  // status 400 - reporte de erro da API Wirecard
  $e->errors(); 
  $e->alerts();
  $e->firstError();
  $e->firstAlert();

} catch (GuzzleHttp\Exception\ClientException $e) {
  
  // status 401 a 499  

} catch (GuzzleHttp\Exception\ServerException $e) {
  
  // status 500 a 599
  
} 


$plan = $wirecardApi->plans->create([
  "code" => "plan101",
  "name" => "Plano Especial",
  "description" => "Descrição",
  "amount" => 990,
  "setup_fee" => 500,
  "max_qty" => 1,
  "interval" => [
    "length" => 1,
    "unit" => "MONTH"
  ],
  "billing_cycles" => 12,
  "trial" => [
    "days" => 30,
    "enabled" => true,
    "hold_setup_fee" => true
  ],
  "payment_method" => "CREDIT_CARD"
]);

echo $plan->name; // Plano Especial


$plans = $wirecardApi->plans->all();

foreach($plans as $plan) {
    echo $plan->name; // Plano Especial
}


$plan = $wirecardApi->plans->get('plan101');
echo $plan->name; // Plano Especial


$plan = $wirecardApi->plans->activate('plan101');
echo $plan->status; // ACTIVE


$plan = $wirecardApi->plans->inactivate('plan101');
echo $plan->status; // INACTIVE


$plan = $wirecardApi->plans->update([
    'name' => 'Plano Especial Atualizado',
]);
echo $plan->name; // Plano Especial Atualizado



// Criar assinante
$customer = $wirecardApi->customers->create([
  "code" => "cliente01",
  "email" => "[email protected]",
  "fullname" => "Nome Sobrenome",
  "cpf" => "22222222222",
  "phone_area_code" => "11",
  "phone_number" => "934343434",
  "birthdate_day" => "26",
  "birthdate_month" => "04",
  "birthdate_year" => "1980",
  "address" => [
    "street" => "Rua Nome da Rua",
    "number" => "100",
    "complement" => "Casa",
    "district" => "Nome do Bairro",
    "city" => "São Paulo",
    "state" => "SP",
    "country" => "BRA",
    "zipcode" => "05015010"
  ]
]);

// Cadastrar o cartão do assinante
$wirecardApi->customers->setCard(
    $customer->code,
    [
      "holder_name" => "Nome Completo",
      "number" => "4111111111111111",
      "expiration_month" => "06",
      "expiration_year" => "22"
    ]
);

// new_vault pode ser habilitado enableNewVault()
$customer = $wirecardApi->customers
    ->enableNewVault()
    ->create([/*...*/])

// customer e billing_info criados juntos
$customer = $wirecardApi->customers->create([
  "code" => "cliente02",
  "email" => "[email protected]",
  "fullname" => "Nome Sobrenome",
  "cpf" => "22222222222",
  "phone_area_code" => "11",
  "phone_number" => "934343434",
  "birthdate_day" => "26",
  "birthdate_month" => "04",
  "birthdate_year" => "1980",
  "address" => [
    "street" => "Rua Nome da Rua",
    "number" => "100",
    "complement" => "Casa",
    "district" => "Nome do Bairro",
    "city" => "São Paulo",
    "state" => "SP",
    "country" => "BRA",
    "zipcode" => "05015010"
  ],
  "billing_info" => [
    "credit_card" => [
      "holder_name" => "Nome Completo",
      "number" => "4111111111111111",
      "expiration_month" => "06",
      "expiration_year" => "22"
    ]
  ]
]);

echo $customer->code; // cliente02


$customers = $wirecardApi->customers->all();

foreach($customers as $customer) {
  echo $customer->code; // cliente01
}


$customer = $wirecardApi->customers->get('client01');
echo $customer->email; // [email protected]


$customer = $wirecardApi->customers->update([
  'name' => 'Novo nome',
]);
echo $customer->name; // Novo nome 


$customer = $wirecardApi->customers->setCard([
  'holder_name' => 'Nome Completo',
  'number' => '4222222222222222',
  'expiration_month' => '06',
  'expiration_year' => '22'
]);
echo $customer->billing_info->credit_card->number; // 4222222222222222


$subscription = $wirecardApi->subscriptions->create([
  'code' => 'assinatura01',
  'amount' => '9990',
  'payment_method' => 'CREDIT_CARD',
  'plan'  => [
    'code'  => 'plano01'
  ],
  'customer'  => [
   'code'  => 'cliente01'
  ]
]);
echo $subscription->code; // assinatura01


$subscription = $wirecardApi->subscriptions->enableNewUser()->create([
  'code' => 'assinatura01',
  'amount' => '9990',
  'payment_method' => 'CREDIT_CARD',
  'plan'  => [
    'code'  => 'plano01'
  ],
  'customer'  => [
   'code'  => 'novoCLiente'
   // Informações de customer
  ]
]);
echo $subscription->code; // assinatura01


$subscriptions = $wirecardApi->subscriptions->all();

foreach($subscriptions as $subscription) {
  echo $subscription->code; // assinatura01
}


$subscription = $wirecardApi->subscriptions->get('assinatura01');
echo $subscription->amount; // 9990