Created
December 22, 2020 21:14
-
-
Save NandoKstroNet/a19f727c9240586661eedbc54c2a8745 to your computer and use it in GitHub Desktop.
Servico para Adesão de um Plano API PagSeguro Recorrente e Laravel Livewire Curso em http://codeexperts.com.br
This file contains hidden or 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
<?php | |
namespace App\Services\PagSeguro\Subscription; | |
use Illuminate\Support\Facades\Http; | |
class SubscriptionService | |
{ | |
private $data; | |
public function __construct($data) | |
{ | |
$this->data = $data; | |
} | |
public function makeSubscription() | |
{ | |
$email = config('pagseguro.email'); | |
$token = config('pagseguro.token'); | |
$url = "https://ws.sandbox.pagseguro.uol.com.br/pre-approvals?email={$email}&token={$token}"; | |
$response = Http::withHeaders([ | |
'Content-Type' => 'application/json', | |
'Accept' => 'application/vnd.pagseguro.com.br.v3+json;charset=ISO-8859-1' | |
]) | |
->post($url, [ | |
'plan' => $this->data['plan_reference'], | |
'sender' => [ | |
'name' => 'Teste Usuário Sender', | |
'email' => '[email protected]', | |
'hash' => $this->data['senderHash'], | |
'phone' => [ | |
'areaCode' => '98', | |
'number' => '984283432' | |
], | |
'address' => [ | |
'street' => 'Rua Teste', | |
'number' => '29', | |
'complement' => '', | |
'district' => 'São Bernado', | |
'city' => 'São Luis', | |
'state' => 'MA', | |
'country' => 'BRA', | |
'postalCode' => '65056000' | |
], | |
'documents' => [ | |
[ | |
'type' => 'CPF', | |
'value' => '' | |
] | |
] | |
], | |
'paymentMethod' => [ | |
'type' => 'CREDITCARD', | |
'creditCard' => [ | |
'token' => $this->data['token'], | |
'holder' => [ | |
'name' => 'Customer Credit Name', | |
'birthDate' => '30/10/1990', | |
'documents' => [ | |
[ | |
'type' => 'CPF', | |
'value' => '' | |
] | |
], | |
'billingAddress' => [ | |
'street' => 'Rua Teste', | |
'number' => '29', | |
'complement' => '', | |
'district' => 'São Bernado', | |
'city' => 'São Luis', | |
'state' => 'MA', | |
'country' => 'BRA', | |
'postalCode' => '65056000' | |
], | |
'phone' => [ | |
'areaCode' => '98', | |
'number' => '984283432' | |
] | |
] | |
] | |
] | |
]); | |
return $response->json(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment