android stripe源码,Stripe integration in android and create token

follow this code and also import stripe library.

public class StripePaymentActivity extends FragmentActivity {

/*

* Change this to your publishable key.

*

* You can get your key here: https://manage.stripe.com/account/apikeys

*/

// public static final String PUBLISHABLE_KEY =

// "pk_test_Tw0HyQcWAVM9R5dBdiiS90X9"; Client Key

public static final String PUBLISHABLE_KEY = "your key";

private ProgressDialogFragment progressFragment;

String[] id, memberId, userEmail, endDate;

Dialog dialog;

@SuppressLint("NewApi")

@TargetApi(Build.VERSION_CODES.GINGERBREAD)

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.payment_activity);

dialog = new Dialog(StripePaymentActivity.this);

if (android.os.Build.VERSION.SDK_INT > 9) {

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()

.permitAll().build();

StrictMode.setThreadPolicy(policy);

}

progressFragment = ProgressDialogFragment

.newInstance(R.string.progressMessage);

}

public void saveCreditCard(PaymentForm form) {

Card card = new Card(form.getCardNumber(), form.getExpMonth(),

form.getExpYear(), form.getCvc());

Log.e("card ", "27th March ::- " + card);

boolean validation = card.validateCard();

Log.e("Validation", "27th March::-" + validation);

if (validation) {

startProgress();

new Stripe().createToken(card, PUBLISHABLE_KEY,

new TokenCallback() {

public void onSuccess(Token token) {

try {

// getTokenList().addToList(token);

Log.e("Token Json", "27th March::-" + token);

final Map chargeParams = new HashMap();

chargeParams.put("amount", 999);

chargeParams.put("currency", "usd");

chargeParams.put("card", token.getId());

// chargeParams.put("captured", false);

com.stripe.Stripe.apiKey = "sk.. your key";

// Charge charge = Charge.create(chargeParams);

// Charge ch = Charge.retrieve(charge.getId());

// // Used it here for demonstration

// ch.capture();

// Charge.create(chargeParams);

new AsyncTask() {

Charge charge;

@Override

protected Void doInBackground(

Void... params) {

try {

com.stripe.Stripe.apiKey = "sk_your key";

charge = Charge

.create(chargeParams);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

// showAlert("Exception while charging the card!",

// e.getLocalizedMessage());

}

return null;

}

protected void onPostExecute(Void result) {

Toast.makeText(

StripePaymentActivity.this,

"Card Charged : "

+ charge.getCreated()

+ "\nPaid : "

+ charge.getPaid(),

Toast.LENGTH_LONG).show();

};

}.execute();

final Map chargeParams1 = new HashMap();

chargeParams1.put("amount", 999);

chargeParams1.put("currency", "usd");

chargeParams1.put("card", token.getId());

chargeParams1.put("captured", false);

com.stripe.Stripe.apiKey = "sk_your key";

Charge charge1 = Charge.create(chargeParams1);

com.stripe.Stripe.apiKey = "sk_your key";

Charge ch2 = Charge.retrieve(charge1.getId()); // Use

// saved

// charged

// Id

// instead

// of

// charge.getId()

// Used

// it

// here

// for

// demonstration

ch2.capture();

com.stripe.Stripe.apiKey = "sk_your key";

// Customer Parameters HashMap

Map customerParams = new HashMap();

customerParams

.put("description",

com.essexpass.Global

.getPreferenceString(

getApplicationContext(),

"email", ""));

customerParams.put("card", token.getId()); // Obtained

// in

// onSuccess()

// method

// of

// TokenCallback

// while

// creating

// token

// above

// Create a Customer

Customer cust = Customer.create(customerParams);

com.stripe.Stripe.apiKey = "sk_your key";

// Retrieve saved customer ID from database

// String cust_id = getSavedCustomerId();

// //getSavedCustomerId() method should retrieve

// saved customer Id from db

// Charge Parameters HashMap

final Map chargeParams2 = new HashMap();

chargeParams2.put("amount", 999);

chargeParams2.put("currency", "usd");

chargeParams2.put(

"customer",

com.essexpass.Global

.getPreferenceString(

getApplicationContext(),

"email", "")); // Use

// customer

// instead

// of

// card

Charge.create(chargeParams2);

} catch (AuthenticationException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InvalidRequestException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (APIConnectionException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (CardException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (APIException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finishProgress();

// Now Call The Services for the and generate New

// Member Id

GetUserPassDeal();

}

public void onError(Exception error) {

handleError(error.getLocalizedMessage());

finishProgress();

}

});

} else if (!card.validateNumber()) {

handleError("The card number that you entered is invalid");

} else if (!card.validateExpiryDate()) {

handleError("The expiration date that you entered is invalid");

} else if (!card.validateCVC()) {

handleError("The CVC code that you entered is invalid");

} else {

handleError("The card details that you entered are invalid");

}

}

private void startProgress() {

progressFragment.show(getSupportFragmentManager(), "progress");

}

private void finishProgress() {

progressFragment.dismiss();

}

private void handleError(String error) {

ErrorDialogFragment fragment = ErrorDialogFragment.newInstance(

R.string.validationErrors, error);

fragment.show(getFragmentManager(), "error");

}

i have use this code in my application.

Thanks.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Ceph中,stripe是一种将数据分片存储的概念。当进行文件读取操作时,需要通过一系列的计算来确定数据所在的具体位置。本文以CephFS的文件读取流程为例进行分析。 首先,在文件读取过程中,Ceph会将文件划分为若干个条带(stripe),每个条带由多个对象分片(stripe unit)组成。条带可以看作是逻辑上连续的一维地址空间。 接下来,通过file_to_extent函数将一维坐标转化为三维坐标(objectset,stripeno,stripepos),来确定具体的位置。其中,objectset表示所在的对象集,stripeno表示条带号,stripepos表示条带内的偏移位置。 具体的计算过程如下:假设需要读取的数据的偏移量为offset,每个对象分片的大小为su(stripe unit),每个条带中包含的对象分片数为stripe_count。 首先,计算块号blockno = offset / su,表示数据所在的分片号。 然后,计算条带号stripeno = blockno / stripe_count,表示数据所在的条带号。 接着,计算条带内偏移stripepos = blockno % stripe_count,表示数据在条带内的偏移位置。 接下来,计算对象集号objectsetno = stripeno / stripes_per_object,表示数据所在的对象集号。 最后,计算对象号objectno = objectsetno * stripe_count + stripepos,表示数据所在的对象号。 通过以上计算,可以确定数据在Ceph中的具体位置,从而完成文件读取操作。 需要注意的是,以上分析是基于Ceph版本10.2.2(jewel)进行的,尽管版本跨度较大,但是该部分代码在12.2.10(luminous)版本中仍然比较稳定,基本的框架没有发生变化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值