我对脚本非常陌生,而且我在完成申请时遇到了问题。
我在Android应用程序中使用Stripe进行信用卡付款。 我使用以下方式发送客户信息:
public class MainActivity extends AppCompatActivity {
private CombinedChart combinedChart;
protected String[] mMonths = new String[] {
"Jan", "Feb", "Mar", "Apr", "May", "June"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
combinedChart = (CombinedChart) findViewById(R.id.combinedChart);
combinedChart.getDescription().setEnabled(false);
combinedChart.setBackgroundColor(Color.WHITE);
combinedChart.setDrawGridBackground(false);
combinedChart.setDrawBarShadow(false);
combinedChart.setHighlightFullBarEnabled(false);
Legend l = combinedChart.getLegend();
l.setWordWrapEnabled(true);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
YAxis rightAxis = combinedChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
YAxis leftAxis = combinedChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
XAxis xAxis = combinedChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return mMonths[(int) value % mMonths.length];
}
});
CombinedData data = new CombinedData();
data.setData(generateBarData());
combinedChart.setData(data);
combinedChart.invalidate();
}
private ArrayList<BarEntry> getBar1Enteries(ArrayList<BarEntry> entries){
entries.add(new BarEntry(1, 25));
entries.add(new BarEntry(2, 30));
entries.add(new BarEntry(3, 38));
entries.add(new BarEntry(4, 10));
entries.add(new BarEntry(5, 15));
return entries;
}
private ArrayList<BarEntry> getBar2Enteries(ArrayList<BarEntry> entries){
entries.add(new BarEntry(1, 20));
entries.add(new BarEntry(2, 25));
entries.add(new BarEntry(3, 33));
entries.add(new BarEntry(4, 5));
entries.add(new BarEntry(5, 10));
return entries;
}
private BarData generateBarData() {
ArrayList<BarEntry> entries1 = new ArrayList<BarEntry>();
ArrayList<BarEntry> entries2 = new ArrayList<BarEntry>();
// for (int index = 0; index < 12; index++) {
// entries1.add(new BarEntry(0, getRandom(25, 25)));
//
// // stacked
// entries2.add(new BarEntry(0, new float[]{getRandom(13, 12), getRandom(13, 12)}));
// }
BarDataSet set1 = new BarDataSet(getBar1Enteries(entries1), "Bar 1");
set1.setColor(Color.rgb(60, 220, 78));
set1.setValueTextColor(Color.rgb(60, 220, 78));
set1.setValueTextSize(10f);
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
BarDataSet set2 = new BarDataSet(getBar2Enteries(entries2), "");
set2.setStackLabels(new String[]{"Stack 1", "Stack 2"});
set2.setColors(new int[]{Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)});
set2.setValueTextColor(Color.rgb(61, 165, 255));
set2.setValueTextSize(10f);
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
float groupSpace = 0.06f;
float barSpace = 0.02f; // x2 dataset
float barWidth = 0.45f; // x2 dataset
// (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group"
BarData d = new BarData(set1, set2);
d.setBarWidth(barWidth);
// make this BarData object grouped
d.groupBars(0, groupSpace, barSpace); // start at x = 0
return d;
}
}
此代码处理令牌,但是, 如果收费失败或拒绝,它不会让我知道。 如果收费完成,如何查看应用程序?
正确或错误输入卡片信息后,一切正常。
我想我要问的是:
如何从我的服务器获取收费结果到我的应用程序?
我的服务器使用ruby。
答案 0 :(得分:0)
如果您正在使用结账,您将从条带中获取身份验证令牌或条带令牌。将其发送给控制器并创建客户并使用充电电话向他收取费用。您可以使用创建费用后提供的参考代码验证交易。
您可以查看此链接以供参考。所有的文档都在这里。 This is for checkout
以下是快速结账的示例代码。
def new
end
def create
# Amount in cents
@amount = 500
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Rails Stripe customer',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end