mootaco/moota-php-sdk

1.1.0 2021-10-05 09:14 UTC

This package is auto-updated.

Last update: 2021-10-05 09:20:08 UTC


README

Moota.co ❤️ PHP Native!

PHP version Latest Stable Version Monthly Downloads Total Downloads

68747470733a2f2f6d6f6f74612d6b6f70732d73746174652d73746f72652e73332e61702d736f757468656173742d312e616d617a6f6e6177732e636f6d2f6d6f6f74612d62616e6e65722e6a706567

This is the Official PHP wrapper/library for Moota API V2, that is compatible with Composer. Visit https://moota.co for more information about the product.

Support us Data Trasnfer Object

  • Note: of this package only supports php:^>=7.1

1. Installation

1.a Composer Installation

If you are using Composer, you can install via composer CLI:

composer require moota-co/moota-php-sdk

or

add this require line to your composer.json file:

{
  "require": {
    "moota-co/moota-php-sdk": "1.*"
  }
}

and run composer install on your terminal.

Note: If you are using Laravel framework, in some case you also need to run composer dumpautoload

1.b Manual Instalation

If you are not using Composer, you can clone this repository.

Then you should require/autoload Mutation.php of etc class file on your code.

require __DIR__ . '/../vendor/autoload.php';

// my code goes here

2. How to Use

2.1 General Settings

// Set your API V2 Server Key 
\Moota\Moota\Config\Moota::$ACCESS_TOKEN = '<your server key>';

2.2 Choose Class Method

2.2.1 Authentication

$auth = new \Moota\Moota\Domain\Auth();
try {
    $getSecretToken = $auth->login(
       new \Moota\Moota\DTO\Auth\LoginData([
                'email' => 'user@moota.co',
                'password' => 'password_hash',
                'scopes' => new \Moota\Moota\DTO\Auth\ScopesData([
                    'api' => true
                ])
            ])
    );
    // set to \Moota\Moota\Config::$ACCESS_TOKEN = $getSecretToken['access_token'];
} catch (\Moota\Moota\Exception\MootaException $exception) {
    // handling fail authentication
}

Destroy Auth Token

$getSecretToken = new \Moota\Moota\Domain\Auth();
$getSecretToken->logout();

2.2.2 Bank Account

$bank_account = new \Moota\Moota\Domain\BankAccount();
// store bank account
try {
    $bank_account->storeBankAccount(
        new \Moota\Moota\DTO\BankAccount\BankAccountStoreData([
            "corporate_id" => "",
            "bank_type" => Moota::BANK_TYPES[0], // list of bank type
            "username" => "loream",  //for gojek and ovo fill with mobile phone number
            "password" => "your password",
            "name_holder" => "loream kasma",
            "account_number" => "16899030",
            "is_active" => true
        ])
    );
 } catch (\Moota\Moota\Exception\MootaException $exception) {
    print_r($exception->getPharseErrors());
 }

body parameter storeBankAccount() reference here

// update bank account
try {
    $bank_account->updateBankAccount(
        new \Moota\Moota\DTO\BankAccount\BankAccountUpdateData([
            "bank_id" => "hashing_qwopejs_id",
            "username" => "jhon",  //for gojek and ovo fill with mobile phone number
            "corporate_id" => "",
            "bank_type" => "",
            "password" => "",
            "name_holder" => "",
            "account_number" => "",
        ])
    );
 } catch (\Moota\Moota\Exception\MootaException $exception) {
    print_r($exception->getPharseErrors());
 }

body parameter updateBankAccount() reference here

// get list bank account
try {
    $bank_account->getBankList();
 } catch (\Moota\Moota\Exception\MootaException $exception) {
    print_r($exception->getPharseErrors());
 }
// can't wait for new mutation data use method refresh mutation 
try {
    $bank_account->refreshMutation('<bank_id>');
 } catch (\Moota\Moota\Exception\MootaException $exception) {
    print_r($exception->getPharseErrors());
 }
// want to remove bank account from moota ?
try {
    $bank_account->destroyBankAccount('<bank_id>');
 } catch (\Moota\Moota\Exception\MootaException $exception) {
    print_r($exception->getPharseErrors());
 }
// want to activate my wallet account ovo or gojek please request otp code first
try {
    $otp_code = $bank_account->bankEwalletRequestOTPCode('<bank_id>');
    
    $bank_account->bankEwalletVerificationOTPCode(
        new \Moota\Moota\DTO\BankAccount\BankAccountEwalletOtpVerification('<bank_id>', '<$otp_code>')
    );
 } catch (\Moota\Moota\Exception\MootaException $exception) {
    print_r($exception->getPharseErrors());
 }

2.2.3 Mutation

$mutation = new \Moota\Moota\Domain\Mutation();
// get my mutation
$my_mutation = $mutation->getMutations(
    new \Moota\Moota\DTO\Mutation\MutationQueryParameterData([
            'bank_id' => 'asdasd',
            'date'    => '2021-09-21',
            'note'    => 'Testing Note Mutation',
            'amount'  => '2000123',
            'type'    => 'CR'
        ])
);

mutation query parameter getMutations() reference here

// Determine dummy mutation for debugging
$my_mutation = $mutation->storeMutation(
    new \Moota\Moota\DTO\Mutation\MutationStoreData(
        // fill mutation value here
    )
);

mutation parameter on storeMutation() reference here

// Add note mutation
$my_mutation = $mutation->addNoteMutation(
    new \Moota\Moota\DTO\Mutation\MutationNoteData([
            'mutation_id' => 'hash_mutation_id',
            'note'    => 'Testing Note Mutation',
        ])
);

mutation parameter on addNoteMutation() reference here

// Debugging | try getting mutation webhook from moota
$my_mutation = $mutation->pushWebhookByMutation('<mutation_id>');
/**
* need to remove mutation data ? 
* method destroy mutation can multiple remove mutation
*/
$my_mutation = $mutation->destroyMutation(
    new \Moota\Moota\DTO\Mutation\MutationDestroyData([
            'mutations' => ["hash_mutation_id", "hash_mutation_id"]
        ])
);

mutation parameter on destroyMutation() reference here

// method attach tagging to mutation 

$my_mutation = $mutation->attachTagMutation(
    new \Moota\Moota\DTO\Mutation\MutationAttachTaggingData([
            "mutation_id" => '8aolk43WJxM',
            "name" => [
                "assurance", "..."
            ]
        ])
);

mutation parameter on attachTagMutation() reference here

// method detach tagging from mutation 

$my_mutation = $mutation->detachTagMutation(
    new \Moota\Moota\DTO\Mutation\MutationDetachTaggingData([
            "mutation_id" => '8aolk43WJxM',
            "name" => [
                "assurance", "..."
            ]
        ])
);

mutation parameter on detachTagMutation() reference here

// method update tagging from mutation 

$my_mutation = $mutation->updateTagMutation(
    new \Moota\Moota\DTO\Mutation\MutationUpdateTaggingData([
            "mutation_id" => '8aolk43WJxM',
            "name" => [
                "assurance", "..."
            ]
        ])
);

mutation parameter on updateTagMutation() reference here

2.2.4 Tagging

$tagging = new \Moota\Moota\Domain\Tagging(); 
$my_tagging = $tagging->getTaggings(
    new \Moota\Moota\DTO\Tagging\TaggingQueryParameterData([
            'tag' => ['assurance', 'cash'] // or leave blank doesn`t have filter
        ])
); 

tagging parameter on getTaggings() reference here

// create first tagging like it
$my_tagging = $tagging->storeTagging(
    new \Moota\Moota\DTO\Tagging\TaggingStoreData([
            'name' => 'assurance'
        ])
); 

tagging parameter on storeTagging() reference here

// update tagging like it
$my_tagging = $tagging->updateTagging(
    new \Moota\Moota\DTO\Tagging\TaggingUpdateData([
            'tag_id' => 'VLagzqBj42Ds',
            'name' => 'assurance-car'
        ])
); 

tagging parameter on updateTagging() reference here

// update tagging like it
$my_tagging = $tagging->destroyTagging('<tag_id>'); 

2.2.5 Topup

you can add bank account and getting mutation from bank account must be have point please TOPUP Point First!

$topup = new \Moota\Moota\Domain\Topup(); 
// Get list payment method | targeting bank account topup point
$payment_method = $topup->getPaymentMethod();
// Get List Amounts Point | minimum and maximum point can topup
$amounts = $topup->getListAmountPoint();
// get my topup 
$my_topup = $topup->getListTopupPoint();
// create topup point
$my_topup = $topup->createTopupPoint(
    new \Moota\Moota\DTO\Topup\CreateTopupData([
            'amount' => 100000,
            'payment_method' => 'bca'
        ])
);

topup parameter on createTopupPoint() reference here

// have a voucher code ?
$my_topup = $topup->redeemVoucher(
    new \Moota\Moota\DTO\Topup\VoucherRedeemData([
            'code' => 'abcd'
        ])
);

topup parameter on redeemVoucher() reference here

2.2.6 Transaction

you can get history transaction of point here

$transaction = new \Moota\Moota\Domain\Transaction();  

$history = $transaction->getHistoryTransactionPoint(
    new \Moota\Moota\DTO\Transaction\TransactionHistoryData([
            'page' => 1,
            'start_date' => '',
            'end_date' => ''
        ])
);

transaction parameter on getHistoryTransactionPoint() reference here

2.2.7 User

you can get profile information here

$user = new \Moota\Moota\Domain\User();  

$my_profile = $transaction->getProfile();

$my_profile = $transaction->updateProfile(
    new \Moota\Moota\DTO\User\UserUpdateData([
            'name' => 'moota',
            'email' => 'email@moota.co',
            'no_ktp' => '12312312123123',
            'alamat' => 'Jl. street no 1'
        ])
);

User parameter on updateProfile() reference here

2.2.8 Webhook

$webhook = new \Moota\Moota\Domain\Webhook();  
$response = $webhook->getListWebhooks(
    new \Moota\Moota\DTO\Webhook\WebhookQueryParameterData([
        'url' => '',
        'bank_account_id' => '',
        'page' => 1,
        'per_page' => 20
    ])
);
try {
    $response = $webhook->storeWebhook(
        new \Moota\Moota\DTO\Webhook\WebhookStoreData([
                'url' => 'https://app.moota.co/endpoint/webhook',
                'secret_token' => 'akjsdkj3',
                'start_unique_code' => 1,
                'end_unique_code' => 999,
                'kinds' => 'credit',
                'bank_account_id' => '', // leave blank webhook can set for all banks account
            ])
    );
 } catch (\Moota\Moota\Exception\MootaException $exception) {
    print_r($exception->getPharseErrors());
 }
$response = $webhook->removeWebhook('<webhook_id>');
$response = $webhook->getWebhookHistory('<webhook_id>');

Retrieve webhook response like it

$webhook = new \Moota\Moota\Domain\Webhook('<secret_token>');  

try {
    $response_payload_json = file_get_contents("php://input");
    $get_signature_from_header = getallheaders()['Signature'];
    
    $webhooks = $webhook->getResponse($get_signature_from_header, $response_payload_json);
    
    foreach ($webhooks as $webhook) {
        // code store to database 
    }
} catch (\Moota\Moota\Exception\Webhook\WebhookValidateException $exception) {
    // code handling when incoming webhook fail validation signature 
    print_r($exception->getMessage()) 
}

Unit Test

All Test

./vendor/bin/phpunit

Specific Test

./vendor/bin/phpunit --filter methodname

Contributing

Questions?

If you have any questions please open an issue.