mootaco/moota-php-sdk

2.0.1 2022-03-18 08:59 UTC

This package is auto-updated.

Last update: 2024-11-18 15:03:29 UTC


README

Moota.co ❤️ PHP Native!

PHP version Latest Stable Version Monthly Downloads Total Downloads

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 Transfer Object

  • of this package only supports php:^>=8
  • need old version php:^=<8 click here

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(
                'user@moota.co',
                'password_hash',
                new \Moota\Moota\DTO\Auth\ScopesData(  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(
            "",
            Moota::BANK_TYPES[0], // list of bank type
            "loream",  //for gojek and ovo fill with mobile phone number
            "your password",
            "loream kasma",
            "16899030",
            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(
           "hashing_qwopejs_id",
            "jhon",  //for gojek and ovo fill with mobile phone 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(
            'asdasd',
            '2021-09-21',
            'Testing Note Mutation',
            '2000123',
            '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(
            'hash_mutation_id',
            '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(
           ["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(
            '8aolk43WJxM',
            [
                "assurance", "..."
            ]
        )
);

mutation parameter on attachTagMutation() reference here

// method detach tagging from mutation 

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

mutation parameter on detachTagMutation() reference here

// method update tagging from mutation 

$my_mutation = $mutation->updateTagMutation(
    new \Moota\Moota\DTO\Mutation\MutationUpdateTaggingData([
            '8aolk43WJxM',
            [
                "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(
            ['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(
            'assurance'
        )
); 

tagging parameter on storeTagging() reference here

// update tagging like it
$my_tagging = $tagging->updateTagging(
    new \Moota\Moota\DTO\Tagging\TaggingUpdateData(
           'VLagzqBj42Ds',
            '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(
            100000,
            'bca'
        )
);

topup parameter on createTopupPoint() reference here

// have a voucher code ?
$my_topup = $topup->redeemVoucher(
    new \Moota\Moota\DTO\Topup\VoucherRedeemData(
          '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(
             1,
             '',
            ''
        )
);

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(
            'moota',
            'email@moota.co',
            '12312312123123',
            '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(
        '',
        '',
         1,
        20
    )
);
try {
    $response = $webhook->storeWebhook(
        new \Moota\Moota\DTO\Webhook\WebhookStoreData(
                'https://app.moota.co/endpoint/webhook',
               'akjsdkj3',
                1,
               999,
                'credit',
                '', // 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.