не может показать транзакцию в Braintree - PullRequest
0 голосов
/ 08 ноября 2019

Пожалуйста, посмотрите мои файлы сервера Checkout_Activity2.java и PHP. Я использую Android-студию в Java для реализации транзакции с использованием Braintree. Тем не менее, он не отражает результат в моем интерфейсе braintree, даже если моя транзакция прошла успешно в моем приложении. Я использую сервер PHP, и все результаты (включая отладку журнала) не отражают никаких ошибок.

Checkout2_activity.java

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.checkout_payment);
        buy = findViewById(R.id.btnBuy);
        TT = findViewById(R.id.TTprice);
        grandT = getIntent().getStringExtra(PASS_TOTAL_AMT);
        TT.setText("Your total is: $" + grandT);

        //new Checkout2_Activity.getToken().execute();
        buy.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                startPayment();
                //onBraintreeSubmitPayment();
            }
        });
    }

    void startPayment(){
        AsyncHttpClient client = new AsyncHttpClient();
        client.get(API_GET_TOKEN, new TextHttpResponseHandler(){
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                Log.d(TAG, "Client Failure: " +  responseString);

            }
            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseToken) {
                Log.d(TAG, "Client token: " + responseToken);
                onBraintreeSubmit(responseToken);
            }
        });
    }

    public void onBraintreeSubmit(String token){
        DropInRequest dropInRequest = new DropInRequest()
                .clientToken(token);
        dropInRequest.collectDeviceData(true);
        Log.d(TAG, "Submiting to BrainTree.. " + token);
        startActivityForResult(dropInRequest.getIntent(this), REQUEST_CODE);
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
                String paymentMethodNonce = result.getPaymentMethodNonce().getNonce();
                Log.d(TAG, "Nonce.. " + paymentMethodNonce); //success
                if(!grandT.isEmpty())
                    submitNonce(paymentMethodNonce);
                else
                    Toast.makeText(Checkout2_Activity.this, "Please Check Your Total Amount", Toast.LENGTH_SHORT).show();
            } else if (resultCode == RESULT_CANCELED) {
                Log.d(TAG, "User return");
            } else {
                // an error occurred, checked the returned exception
                Exception exception = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
                Log.d(TAG, "Error:: " + exception.toString());
            }
        }
    }

    private void submitNonce(String paymentMethodNonce){
        RequestParams params = new RequestParams();
        params.put("amount", grandT);
        params.put("nonce",paymentMethodNonce);
        Log.d(TAG, "Params.. " + params);

        AsyncHttpClient client = new AsyncHttpClient();
        client.post(API_CHECKOUT, params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                System.out.println("SUCCESSFUL_PRINT"); //it prints!
                createDatabase();
                sendNotification();
                Intent finish = new Intent(Checkout2_Activity.this, Checkout3_Activity.class);
                startActivity(finish);
                finish();

            }
            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                Log.d(TAG, "CheckOut Failure.. " + error);
            }
        });

    }

braintree_init.php

<?php
session_start();
require_once("lib/autoload.php");

if(file_exists(__DIR__ . "/../.env")) {
    $dotenv = new Dotenv\Dotenv(__DIR__ . "/../");
    $dotenv->load();
}
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('HIDDEN_XX');
Braintree_Configuration::publicKey('HIDDEN_XX');
Braintree_Configuration::privateKey('HIDDEN_XX'); //I hidden it by purpose
?>

checkout.php

<?php
require_once ("braintree_init.php");
require_once 'lib/Braintree.php';

$nonce = $_POST['nonce'];
$amount = $_POST['amount'];
$result = BrainTree_Transaction::sale([
    'amount' => $amount,
    'paymentMethodNonce' => $nonce,
    'options' => [
        'submitForSettlement' => True
    ]
]);
?>

main.php

<?php
require_once ("braintree_init.php");
require_once 'lib/Braintree.php';
echo ($clientToken = Braintree_ClientToken::generate());
?>

depandency

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation "com.google.android.gms:play-services-base:17.0.0"
    implementation 'com.braintreepayments.api:drop-in:4.4.1'
    implementation 'net.schmizz:sshj:0.10.0'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    components.all {
        allVariants {
            withDependencies { deps ->
                deps.each { dep ->
                    if (dep.group == 'net.minidev' && dep.name =='json-smart') {
                        dep.version {
                            prefer "2.3"
                        }
                        dep.because "resolving dependencies issue"
                    }
                }
            }
        }
    }
    implementation 'com.braintreepayments.api:braintree:3.7.0'
    implementation 'com.braintreepayments.api:google-payment:3.2.0'
    implementation 'com.loopj.android:android-async-http:1.4.10'

}

Наконец, мой Manifast.xml

<!--braintree-->
        <activity
            android:name=".Checkout2_Activity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="${applicationId}.braintree" />
            </intent-filter>
        </activity>

Извините, если это долго. Я могу напечатать "SUCCESSFUL_PRINT", но braintree не отражает ни одного grandT и ничего не делает транзакция, ни успех, ни провал, любая помощь о Braintree была бы полезной.

...