【发布时间】:2017-07-12 15:30:45
【问题描述】:
我对所有这些东西有点困惑,我是一名 Android 开发人员,现在我需要在我的应用程序中集成支付,所以我使用了 paypal 网关,但我需要一个服务器,所以我使用 firebase 告诉我我需要使用node.js。我不知道,但我仍然尝试做我在网上找到的东西,这是我的代码,如果有人可以向我解释我错在哪里或者是否有最简单的方法!?谢谢!
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
});
如果缺少某些文件或代码,请告诉我,以及如何从我的 android 代码调用 index.js 文件中的函数? 谢谢!
【问题讨论】:
-
应该发生什么以及发生了什么?
标签: javascript android node.js firebase