بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ
پرداخت درون برنامه اعمال طرح قبل از خرید(محصول سکه ای)
مدیریت گفتگو
آخرین تغییر: 11 سال پیش
سلام خسته نباشید.
یه بازی داریم میسازیم که برای خرید سکه هاش پرداخت درون برنامه گذاشتیم. ولی حالا یه مشکلی وجود داره . اینکه قبل از خرید از بازار طرح اعمال میشه و حتی اگر خرید لغو بشه این کار انجام میشه. البته من چندتا محصول دارم همونطور که از شناسه ها مشخصه ولی نمیدونم چطور باید این رو جا داد درو ن کدها. به نظرتون چیکار باید کنم؟
public class PayOnlinePakage extends Activity {
public static final String RSA ="کلید Rsa";
private final String NAMESPACE = "";
//Change IP to your machine IP
private final String URL = "";
private final String SOAP_ACTION = "";
//private String TAG = "PGGURU";
public static String responseJSON = "";
//GSON object
Gson gson = new Gson();
private SharedPreferences spSerialNumber;
private SharedPreferences spPay;
private SharedPreferences spBox;
int counter = 0;
ImageView btnpayonline;
RadioGroup radioGroup1;
RadioButton radioselect;
public static String TypePay = "0";
public static String TypeBox = "0";
private String SerialNumberTell = "";
static final String TAG = "LOG";
static final String SKU_PREMIUM = "gp";
static final String SKU_PREMIUM50_1 = "gp50";
static final String SKU_PREMIUM100 = "gp100i";
static final String SKU_PREMIUM50 = "gp50i";
boolean mIsPremium = false;
static final int RC_REQUEST = 13678;
IabHelper mHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.payonlinepakage);
// You can find it in your Bazaar console, in the Dealers section.
// It is recommended to add more security than just pasting it in your source code;
mHelper = new IabHelper(this, RSA);
final IabHelper.QueryInventoryFinishedListener onQueryInventoryFinished = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
if (result.isFailure()) {
Log.d(TAG, "Failed to query inventory: " + result);
return;
}
else {
Log.d(TAG, "Query inventory was successful.");
// does the user have the premium upgrade?
mIsPremium = inventory.hasPurchase(SKU_PREMIUM);
if (mIsPremium) {
MasrafSeke(inventory.getPurchase(SKU_PREMIUM));
}
// update UI accordingly
Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
}
Log.d(TAG, "Initial inventory query finished; enabling main UI.");
}
};
final IabHelper.OnIabPurchaseFinishedListener onIabPurchaseFinished = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
return;
}
else if (purchase.getSku().equals(SKU_PREMIUM)) {
// give user access to premium content and update the UI
Toast.makeText(PayOnlinePakage.this, "خرید موفق", Toast.LENGTH_SHORT).show();
MasrafSeke(purchase);
}
}
};
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if ( !result.isSuccess()) {
// Oh noes, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
mHelper.queryInventoryAsync(onQueryInventoryFinished);
}
});
////////////////////////////////////////////
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
btnpayonline = (ImageView) findViewById(R.id.btnPayOnline);
final Animation fadeInAnimation2 = AnimationUtils.loadAnimation(this, R.anim.anim12);
btnpayonline.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
btnpayonline.startAnimation(fadeInAnimation2);
spSerialNumber = getApplicationContext().getSharedPreferences("SerialNumberUsers", 0);
SerialNumberTell = spSerialNumber.getString("SNU", "0");
int selectedId1 = radioGroup1.indexOfChild(findViewById(radioGroup1.getCheckedRadioButtonId()));
radioselect = (RadioButton) findViewById(selectedId1);
if (selectedId1 == 0)
{
TypePay = "100";
TypeBox = "1";
mHelper.launchPurchaseFlow(PayOnlinePakage.this, SKU_PREMIUM, 13678, onIabPurchaseFinished, "payload-string");
}
if (selectedId1 == 1)
{
TypePay = "50";
TypeBox = "1";
mHelper.launchPurchaseFlow(PayOnlinePakage.this, SKU_PREMIUM50_1, 13678, onIabPurchaseFinished, "payload-string");
}
if (selectedId1 == 2)
{
TypePay = "100";
TypeBox = "0";
mHelper.launchPurchaseFlow(PayOnlinePakage.this, SKU_PREMIUM100, 13678, onIabPurchaseFinished, "payload-string");
}
if (selectedId1 == 3)
{
TypePay = "50";
TypeBox = "0";
mHelper.launchPurchaseFlow(PayOnlinePakage.this, SKU_PREMIUM50, 13678, onIabPurchaseFinished, "payload-string");
}
spPay = getApplicationContext().getSharedPreferences("payonline", 0);
spBox = getApplicationContext().getSharedPreferences("boxonline", 0);
if ((spPay.getString("pay", "0").equals("0") &&
spPay.getString("box", "0").equals("0")) ||
spPay.getString("box", "0").equals("1"))
{
AsyncCountryWSCall task = new AsyncCountryWSCall();
//Execute the task to set Country list in Country Spinner Control
task.execute();
final Dialog di = new Dialog(PayOnlinePakage.this, R.style.FullHeightDialog);
di.requestWindowFeature(Window.FEATURE_NO_TITLE);
di.setContentView(R.layout.dialog);
ProgressBar img_dialog = (ProgressBar) di.findViewById(R.id.img_dialog);
img_dialog.setIndeterminate(true);
img_dialog.setIndeterminateDrawable(getResources().getDrawable(R.anim.progress_dialog));
di.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
di.show();
final Timer tm = new Timer();
tm.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
counter++;
if (responseJSON.length() == 0)
{
if (counter == 25)
{
di.cancel();
Toast.makeText(getApplicationContext(), "خطا در ارتباط با سرور", Toast.LENGTH_LONG).show();
tm.cancel();
counter = 0;
responseJSON = "";
}
}
else if (responseJSON.length() > 0) {
if (responseJSON.substring(1, responseJSON.length() - 1).equals("ok"))
{
di.cancel();
Toast.makeText(getApplicationContext(), "خرید شما با موفقیت انجام شد", Toast.LENGTH_LONG).show();
tm.cancel();
counter = 0;
responseJSON = "";
//*******************
spPay = getApplicationContext().getSharedPreferences("payonline", 0);
Editor edit = spPay.edit();
edit.putString("pay", TypePay);
edit.commit();
//******************
spBox = getApplicationContext().getSharedPreferences("boxonline", 0);
edit = spPay.edit();
edit.putString("box", TypeBox);
edit.commit();
//ر�?تن به ص�?حه اصلی
finish();
}
else if (responseJSON.substring(1, responseJSON.length() - 1).equals("no"))
{
di.cancel();
Toast.makeText(getApplicationContext(), "خطا، لطفاً دوباره تلاش کنید", Toast.LENGTH_LONG).show();
tm.cancel();
counter = 0;
responseJSON = "";
//*******************
spPay = getApplicationContext().getSharedPreferences("payonline", 0);
Editor edit = spPay.edit();
edit.putString("pay", "0");
edit.commit();
//******************
spBox = getApplicationContext().getSharedPreferences("boxonline", 0);
edit = spPay.edit();
edit.putString("box", "0");
edit.commit();
}
else if (responseJSON.substring(1, responseJSON.length() - 1).equals("off"))
{
di.cancel();
Toast.makeText(getApplicationContext(), "شما بسته دارید و اجازه خرید ندارید", Toast.LENGTH_LONG).show();
tm.cancel();
counter = 0;
responseJSON = "";
}
}
}
});
}
}, 1, 1000);
}
else {
Toast.makeText(getApplicationContext(), "شما بسته دارید و اجازه خرید ندارید", Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
// Pass on the activity result to the helper for handling
if ( !mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null)
mHelper.dispose();
mHelper = null;
}
private void MasrafSeke(Purchase kala) {
mHelper.consumeAsync(kala, new IabHelper.OnConsumeFinishedListener() {
@Override
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess())
Toast.makeText(PayOnlinePakage.this, "مصرف شد", Toast.LENGTH_SHORT).show();
Log.d(TAG, "NATIJE masraf: " + result.getMessage() + result.getResponse());
}
});
}
//AysnTask class to handle Country WS call as separate UI Thread
private class AsyncCountryWSCall extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
invokeJSONWS(SerialNumberTell, TypePay, TypeBox, "PayPackage");
return null;
}
}
//Method which invoke web methods
public void invokeJSONWS(String SerialNumberUser, String TypeBuy, String TypeBox, String methName) {
// Create request
SoapObject request = new SoapObject(NAMESPACE, methName);
// Property which holds input parameters
PropertyInfo paramPI = new PropertyInfo();
// Set Name
paramPI.setName("SerialNumberUser");
// Set Value
paramPI.setValue(SerialNumberUser);
// Set dataType
paramPI.setType(String.class);
// Add the property to request object
request.addProperty(paramPI);
paramPI = new PropertyInfo();
// Set Name
paramPI.setName("TypeBuy");
// Set Value
paramPI.setValue(TypeBuy);
// Set dataType
paramPI.setType(String.class);
// Add the property to request object
request.addProperty(paramPI);
paramPI = new PropertyInfo();
// Set Name
paramPI.setName("TypeBox");
// Set Value
paramPI.setValue(TypeBox);
// Set dataType
paramPI.setType(String.class);
// Add the property to request object
request.addProperty(paramPI);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// web service
androidHttpTransport.call(SOAP_ACTION + methName, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// Assign it to static variable
responseJSON = response.toString();
}
catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onBackPressed() {
finish();
return;
}
}
پاسخها 1
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
ویرایش
پیام
نظرات