我對所有這些東西有點困惑,我是一名android開發人員,現在我需要在我的應用中集成付款,所以我使用了貝寶網關,但我需要一個服務器,所以我用firebase告訴我,我需要使用node.js.我不知道,但我仍然試圖做我在網上找到的東西,這裏是我的代碼,如果有人能向我解釋我錯在哪裏,或者有最簡單的方法!謝謝!Android客戶端到服務器Node.js通過Firebase付款
public class MainActivity extends AppCompatActivity {
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;
private static final String CONFIG_CLIENT_ID =
"Here there is my actual client id";
private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
private static final int REQUEST_CODE_PROFILE_SHARING = 3;
private static final String TAG = MainActivity.class.getSimpleName();
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
.merchantName("Example Merchant")
.merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.buyItBtn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal("0.01"), "USD", "sample item",
PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(MainActivity.this, PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}
});
findViewById(R.id.futurePaymentBtn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, PayPalFuturePaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
}
});
findViewById(R.id.profileSharingBtn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, PayPalProfileSharingActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PayPalProfileSharingActivity.EXTRA_REQUESTED_SCOPES, getOauthScopes());
startActivityForResult(intent, REQUEST_CODE_PROFILE_SHARING);
}
});
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);
}
private PayPalOAuthScopes getOauthScopes() {
Set scopes = new HashSet(Arrays.asList(PayPalOAuthScopes.PAYPAL_SCOPE_EMAIL, PayPalOAuthScopes.PAYPAL_SCOPE_ADDRESS));
return new PayPalOAuthScopes(scopes);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT && resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i(TAG, confirm.toJSONObject().toString(4));
Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));
//TODO: envoyer 'confirm' et si possible confirm.getPayment() à votre server pour la vérification
Toast.makeText(getApplicationContext(), "PaymentConfirmation info received from PayPal", Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Log.e(TAG, "an extremely unlikely failure occurred: ", e);
}
}
} else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT && resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth =
data.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
String authorization_code = auth.getAuthorizationCode();
sendAuthorizationToServer(authorization_code);
}
} else if (requestCode == REQUEST_CODE_PROFILE_SHARING && resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data.getParcelableExtra(PayPalProfileSharingActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
String authorization_code = auth.getAuthorizationCode();
sendAuthorizationToServer(authorization_code);
}
}
}
private void sendAuthorizationToServer(String auth) {
}
}
這是我的代碼在我的index.js在我的文件夾功能:
var braintree = require("braintree");
var express = require('express'),
app = express();
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "actual merchand id",
publicKey: "actual publicKey",
privateKey: "actual privateKey"
});
var gateway = braintree.connect({
accessToken: "actual accesstoken"
});
app.get("/client_token", function (req, res) {
gateway.clientToken.generate({}, function (err, response) {
res.send(response.clientToken);
});
});
app.get("/checkout", function (req, res) {
var nonce = req.body.payment_method_nonce;
// Use payment method nonce here
});
告訴我,如果某些文件或代碼丟失,還我怎麼調用一個函數在我的index.js文件從我的android代碼?? 謝謝!
什麼應該發生的和正在發生的事情? –