diff --git a/.gitignore b/.gitignore index 11e612e..4f4acd3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,19 +1,2 @@ -# Build and Release Folders -bin/ -bin-debug/ -bin-release/ -[Oo]bj/ # FlashDevelop obj -[Bb]in/ # FlashDevelop bin - -# Other files and folders -.settings/ - -# Executables -*.swf -*.air -*.ipa -*.apk - -# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` -# should NOT be excluded as they contain compiler settings and other important -# information for Eclipse / Flash Builder. +vendor/ +composer.lock \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..aebf6fe --- /dev/null +++ b/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "mundipagg/mundiapi": "^3.0", + "guzzlehttp/guzzle": "^6.3" + } +} diff --git a/examples_http/chargeCancel.php b/examples_http/chargeCancel.php new file mode 100644 index 0000000..f920a01 --- /dev/null +++ b/examples_http/chargeCancel.php @@ -0,0 +1,18 @@ +request('DELETE', 'charges/'.$chargeId); + + $result = json_decode($response->getBody()); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_http/chargeCapture.php b/examples_http/chargeCapture.php new file mode 100644 index 0000000..bf7c0c4 --- /dev/null +++ b/examples_http/chargeCapture.php @@ -0,0 +1,18 @@ +request('POST', 'charges/'.$chargeId.'/capture'); + + $result = json_decode($response->getBody()); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_http/chargeCreate.php b/examples_http/chargeCreate.php new file mode 100644 index 0000000..d749859 --- /dev/null +++ b/examples_http/chargeCreate.php @@ -0,0 +1,100 @@ + 'Rua Guilhermina Guinle', + 'number' => '272', + 'complement' => 'Some information', + 'neighborhood' => 'Boatafogo', + 'city' => 'Rio de Janeiro', + 'state' => 'RJ', + 'country' => 'BR', + 'zip_code' => '22270060', + 'metadata' => [ + 'address_attr' => 'data' + ] + ]; + + $homePhone = [ + 'country_code' => '55', + 'area_code' => '21', + 'number' => '55554444' + ]; + + $mobilePhone = [ + 'country_code' => '55', + 'area_code' => '21', + 'number' => '988887777' + ]; + + $phones = [ + 'home_phone' => $homePhone, + 'mobile_phone' => $mobilePhone + ]; + + $customer = [ + 'address' => $address, + 'phones' => $phones, + 'code' => 'CUSTOMER_INTEGRATION_CODE', + 'type' => 'individual', + 'name' => 'Fabiano Couto', + 'email' => 'fabianocouto@domain.com', + 'document' => '34435132630', // Generated by https://www.geradordecpf.org/ + 'gender' => 'male', + 'birthdate' => '1982-06-03', + 'metadata' => [ + 'customer_attr' => 'data' + ] + ]; + + $creditCard = [ + 'number' => '30513940605542', // Generated by https://names.igopaygo.com/credit-card + 'holder_name' => 'Fabiano Couto', + 'exp_month' => '05', + 'exp_year' => '2021', + 'cvv' => '038', + 'metadata' => [ + 'card_attr' => 'data-edt' + ] + ]; + + $creditCardPayment = [ + 'capture' => false, // true for auth and capture + 'installments' => 1, + 'statement_descriptor' => 'Credit Card Payment', + 'card' => $creditCard, + ]; + + $payment = [ + 'payment_method' => 'credit_card', + 'credit_card' => $creditCardPayment, + // 'metadata' => [ + // 'payment_attr' => 'data' + // ] + ]; + + $request = [ + 'code' => 'CHARGE_INTEGRATION_CODE', + 'amount' => '100', // In cents + 'currency' => 'BRL', + 'due_at' => date('Y-m-d H:i:s', time()), + 'customer' => $customer, + 'payment' => $payment, + 'metadata' => [ + 'charge_attr' => 'data' + ] + ]; + + $response = $client->request('POST', 'charges', ['json' => $request]); + + $result = json_decode($response->getBody()); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_http/chargeGet.php b/examples_http/chargeGet.php new file mode 100644 index 0000000..9db759b --- /dev/null +++ b/examples_http/chargeGet.php @@ -0,0 +1,18 @@ +request('GET', 'charges/'.$chargeId); + + $result = json_decode($response->getBody()); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_http/chargeList.php b/examples_http/chargeList.php new file mode 100644 index 0000000..70dba03 --- /dev/null +++ b/examples_http/chargeList.php @@ -0,0 +1,28 @@ + null, // Integration code + 'status' => null, // pending, paid, canceled, processing, failed, overpaid ou underpaid + 'payment_method' => null, // credit_card, boleto, bank_transfer, safetypay ou voucher + 'customer_id' => null, + 'order_id' => null, + 'created_since' => null, // Date or DateTime string + 'created_until' => null, // Date or DateTime string + 'page' => 1, + 'size' => 10, + ]; + + $response = $client->request('GET', 'charges', ['query' => $query]); + + $result = json_decode($response->getBody()); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_http/client.php b/examples_http/client.php new file mode 100644 index 0000000..576cc48 --- /dev/null +++ b/examples_http/client.php @@ -0,0 +1,30 @@ +'; + print json_encode((array) $data); + print ''; +} + +require dirname(__FILE__).'/../vendor/autoload.php'; + +use GuzzleHttp\Promisse; +use GuzzleHttp\Psr7; +use GuzzleHttp\Client; + +$client = new Client([ + 'base_uri' => 'https://api.mundipagg.com/core/v1/', + 'auth' => [BASIC_AUTH_USER, BASIC_AUTH_PASS] +]); \ No newline at end of file diff --git a/examples_sdk/chargeCancel.php b/examples_sdk/chargeCancel.php new file mode 100644 index 0000000..034decd --- /dev/null +++ b/examples_sdk/chargeCancel.php @@ -0,0 +1,16 @@ +getCharges(); + + $result = $charges->cancelCharge('ch_id'); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_sdk/chargeCapture.php b/examples_sdk/chargeCapture.php new file mode 100644 index 0000000..1366282 --- /dev/null +++ b/examples_sdk/chargeCapture.php @@ -0,0 +1,16 @@ +getCharges(); + + $result = $charges->captureCharge('ch_id'); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_sdk/chargeCreate.php b/examples_sdk/chargeCreate.php new file mode 100644 index 0000000..b42084e --- /dev/null +++ b/examples_sdk/chargeCreate.php @@ -0,0 +1,103 @@ +street = 'Rua Guilhermina Guinle'; + $createAddressRequest->number = '272'; + $createAddressRequest->complement = 'Some information'; + $createAddressRequest->neighborhood = 'Boatafogo'; + $createAddressRequest->city = 'Rio de Janeiro'; + $createAddressRequest->state = 'RJ'; + $createAddressRequest->country = 'BR'; + $createAddressRequest->zipCode = '22270060'; + $createAddressRequest->metadata = ['address_attr' => 'data']; + + $createHomePhoneRequest = new MundiAPILib\Models\CreatePhoneRequest(); + $createHomePhoneRequest->countryCode = '55'; + $createHomePhoneRequest->areaCode = '21'; + $createHomePhoneRequest->number = '55554444'; + + $createMobilePhoneRequest = new MundiAPILib\Models\CreatePhoneRequest(); + $createMobilePhoneRequest->countryCode = '55'; + $createMobilePhoneRequest->areaCode = '21'; + $createMobilePhoneRequest->number = '988887777'; + + $createPhonesRequest = new MundiAPILib\Models\CreatePhonesRequest(); + $createPhonesRequest->homePhone = $createHomePhoneRequest; + $createPhonesRequest->mobilePhone = $createMobilePhoneRequest; + + $createCustomerRequest = new MundiAPILib\Models\CreateCustomerRequest(); + $createCustomerRequest->address = $createAddressRequest; + $createCustomerRequest->phones = $createPhonesRequest; + $createCustomerRequest->code = 'CUSTOMER_INTEGRATION_CODE'; + $createCustomerRequest->type = 'individual'; + $createCustomerRequest->name = 'Fabiano Couto'; + $createCustomerRequest->email = 'fabianocouto@domain.com'; + $createCustomerRequest->document = '34435132630'; // Generated by https://www.geradordecpf.org/ + $createCustomerRequest->gender = 'male'; + $createCustomerRequest->birthdate = '1982-06-03'; + $createCustomerRequest->metadata = ['customer_attr' => 'data']; + + // DUE DATE + + $dueDate = new DateTime('now'); + $dueDate->add(new DateInterval('P5D')); // Add 5 days + + // CREDIT CARD + + $createCardRequest = new MundiAPILib\Models\CreateCardRequest(); + $createCardRequest->number = '30513940605542'; // Generated by https://names.igopaygo.com/credit-card + $createCardRequest->holderName = 'Fabiano Couto'; + $createCardRequest->expMonth = '08'; + $createCardRequest->expYear = '2021'; + $createCardRequest->cvv = '038'; + + $createCreditCardPaymentRequest = new MundiAPILib\Models\CreateCreditCardPaymentRequest(); + $createCreditCardPaymentRequest->card = $createCardRequest; + $createCreditCardPaymentRequest->installments = 1; + $createCreditCardPaymentRequest->capture = true; // true for auth and capture + + $createPaymnentRequest = new MundiAPILib\Models\CreatePaymentRequest(); + $createPaymnentRequest->creditCard = $createCreditCardPaymentRequest; + $createPaymnentRequest->paymentMethod = 'credit_card'; + $createPaymnentRequest->metadata = ['payment_attr' => 'data']; + + // BANK SLIP + + // $createSlipPaymentRequest = new MundiAPILib\Models\CreateBoletoPaymentRequest(); + // $createSlipPaymentRequest->bank = '341'; + // $createSlipPaymentRequest->instructions = 'Favor, não receber após o vencimento.'; + // $createSlipPaymentRequest->dueAt = $dueDate; + // $createSlipPaymentRequest->metadata = ['slip_attr' => 'data']; + + // $createPaymnentRequest = new MundiAPILib\Models\CreatePaymentRequest(); + // $createPaymnentRequest->boleto = $createSlipPaymentRequest; + // $createPaymnentRequest->paymentMethod = 'boleto'; + // $createPaymnentRequest->metadata = ['payment_attr' => 'data']; + + // CHARGE + + $createChargeRequest = new MundiAPILib\Models\CreateChargeRequest(); + $createChargeRequest->customer = $createCustomerRequest; + $createChargeRequest->payment = $createPaymnentRequest; + $createChargeRequest->code = 'CHARGE_INTEGRATION_CODE'; // If not informed, a random code is generated + $createChargeRequest->dueAt = $dueDate; + $createChargeRequest->currency = 'BRL'; + $createChargeRequest->amount = 100; // In cents + $createChargeRequest->metadata = ['charge_attr' => 'data']; + + $charges = $client->getCharges(); + + $result = $charges->createCharge($createChargeRequest); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_sdk/chargeGet.php b/examples_sdk/chargeGet.php new file mode 100644 index 0000000..1c230ee --- /dev/null +++ b/examples_sdk/chargeGet.php @@ -0,0 +1,16 @@ +getCharges(); + + $result = $charges->getCharge('ch_id'); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_sdk/chargeList.php b/examples_sdk/chargeList.php new file mode 100644 index 0000000..827ed98 --- /dev/null +++ b/examples_sdk/chargeList.php @@ -0,0 +1,26 @@ +getCharges(); + + $result = $charges->getCharges( + null /* page number */, + null /* page size */, + null /* filter by code (integration code) */, + null /* filter by status */, + null /* filter by payment method */, + null /* filter by customer id */, + null /* filter by order id */, + null /* filter by date from */, + null /* filter by date to */ + ); + + DumpData($result); + +} catch (Exception $e) { + + DumpData($e); +} \ No newline at end of file diff --git a/examples_sdk/client.php b/examples_sdk/client.php new file mode 100644 index 0000000..4b35b3d --- /dev/null +++ b/examples_sdk/client.php @@ -0,0 +1,23 @@ +'; + print json_encode((array) $data); + print ''; +} + +require dirname(__FILE__).'/../vendor/autoload.php'; + +$client = new MundiAPILib\MundiAPIClient(BASIC_AUTH_USER, BASIC_AUTH_PASS); \ No newline at end of file