心动优惠到谷歌钱包

心动优惠到谷歌钱包

本文介绍了心动优惠到谷歌钱包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在我的应用程序,我需要实现从我的应用程序,以谷歌钱包一个心动优惠。我发现这个教程:的 ,但是当我试图实现它,我遇到了一个问题。有code从页面:

In my app, I need to implement a saving offer from my app to Google Wallet. I found this tutorial: https://developers.google.com/wallet/objects/savetowalletnative#4_create_an_object , but when I tried to implement it, I encountered a problem. There is code from page:

OfferWalletObject wob = OfferWalletObject
        .newBuilder()...

但我的环境说,类没有这个方法。有没有在这个页面写这个方法:的

有人可以帮助解决这个问题,或者说关于其他方法来保存报价在谷歌钱包。

Can someone help to solve this problem or say about other method to save offer in Google wallet.

推荐答案

我有成功的整合谷歌钱包,从这个视频。链接

I have successful integrate Google Wallet, from this Video.Link

  public class MainActivity extends ActionBarActivity implements  GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{


private GoogleApiClient mGoogleApiClient;
private SupportWalletFragment mWalletFregment;
private SupportWalletFragment mXmlWalletFregment;

private MaskedWallet mMaskedWallet;
private FullWallet mFullWallet;

public static final int MASKED_WALLET_REQUEST_CODE=888;
public static final int FULL_WALLET_REQUEST_CODE=889;
public static final String WALLET_FRAGMENT_ID="wallet_fragment";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    mWalletFregment=(SupportWalletFragment) getSupportFragmentManager()
            .findFragmentByTag(WALLET_FRAGMENT_ID);

    WalletFragmentInitParams startParams;
    WalletFragmentInitParams.Builder startParamsBuilder=WalletFragmentInitParams.newBuilder()
            .setMaskedWalletRequest(generateMaskedwalletRequest())
            .setMaskedWalletRequestCode(MASKED_WALLET_REQUEST_CODE);

    startParams=startParamsBuilder.build();

    Log.e("FREGMENT",""+mWalletFregment);
    if(mWalletFregment==null){
        WalletFragmentStyle walletFragmentStyle=new WalletFragmentStyle()
                .setBuyButtonText(BuyButtonText.BUY_WITH_GOOGLE)
                .setBuyButtonWidth(Dimension.MATCH_PARENT);

        WalletFragmentOptions walletFragmentOptions=WalletFragmentOptions.newBuilder()
                .setEnvironment(WalletConstants.ENVIRONMENT_SANDBOX)
                .setFragmentStyle(walletFragmentStyle)
                .setTheme(WalletConstants.THEME_HOLO_LIGHT)
                .setMode(WalletFragmentMode.BUY_BUTTON)
                .build();

        mWalletFregment=SupportWalletFragment.newInstance(walletFragmentOptions);
        mWalletFregment.initialize(startParams);

    }
    Log.e("FREGMENT",""+mWalletFregment);
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.wallet_button_holder,mWalletFregment,WALLET_FRAGMENT_ID)
            .commit();

    mGoogleApiClient=new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Wallet.API,new Wallet.WalletOptions.Builder()
                        .setEnvironment(WalletConstants.ENVIRONMENT_SANDBOX)
                        .setTheme(WalletConstants.THEME_HOLO_LIGHT)
                        .build())
            .build();

    setContentView(R.layout.activity_main);
}


@Override
protected void onStart() {
    mGoogleApiClient.connect();
    super.onStart();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode){
        case MASKED_WALLET_REQUEST_CODE :
            switch (resultCode){
                case Activity.RESULT_OK :
                    mMaskedWallet=data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);
                    break;
                case Activity.RESULT_CANCELED :
                    break;
                default:
                    Toast.makeText(this,"An Error Occured",Toast.LENGTH_LONG).show();
                    break;
            }
            break;
        case FULL_WALLET_REQUEST_CODE :
            switch (resultCode){
                case Activity.RESULT_OK :
                    mFullWallet= data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET);
                    Toast.makeText(this,mFullWallet.getProxyCard().getPan().toString(),Toast.LENGTH_LONG).show();
                    Wallet.Payments.notifyTransactionStatus(mGoogleApiClient,
                            generateNotifyTransactionStatusrequest(mFullWallet.getGoogleTransactionId(),
                                    NotifyTransactionStatusRequest.Status.SUCCESS));
                    break;
                default:
                    Toast.makeText(this,"An Error Occured",Toast.LENGTH_LONG).show();
                    break;

            }
            break;
        case WalletConstants.RESULT_ERROR:
            Toast.makeText(this,"An Error Occured",Toast.LENGTH_LONG).show();
            break;
    }

}


public static NotifyTransactionStatusRequest generateNotifyTransactionStatusrequest(
        String googleTransactionId,int status ){

    return NotifyTransactionStatusRequest.newBuilder()
            .setGoogleTransactionId(googleTransactionId)
            .setStatus(status)
            .build();
}

private MaskedWalletRequest generateMaskedwalletRequest(){
    MaskedWalletRequest maskWalletRequest=MaskedWalletRequest.newBuilder()
            .setMerchantName("Google I/O CoadeLab")
            .setPhoneNumberRequired(true)
            .setShippingAddressRequired(true)
            .setCurrencyCode("INR")
            .setEstimatedTotalPrice("10.00")
            .setCart(Cart.newBuilder()
                      .setCurrencyCode("INR")
                      .setTotalPrice("10.00")
                      .addLineItem(LineItem.newBuilder().setCurrencyCode("INR")
                                      .setQuantity("1")
                                      .setUnitPrice("10.00")
                                       .setTotalPrice("10.00")
                                       .build() )
                      .build())
            .build();
    return maskWalletRequest;
}


private FullWalletRequest generateFullWalletRequest(String googleTransactionId){
     FullWalletRequest fullWalletRequest=FullWalletRequest.newBuilder()
             .setCart(Cart.newBuilder()
                      .setCurrencyCode("INR")
                       .setTotalPrice("10.10")
                        .addLineItem(LineItem.newBuilder()
                                .setCurrencyCode("INR")
                                .setQuantity("1")
                                .setUnitPrice("10.00")
                                .setTotalPrice("10.00")
                                .build())
                     .addLineItem(LineItem.newBuilder()
                             .setCurrencyCode("INR")
                             .setDescription("Tax")
                             .setRole(LineItem.Role.TAX)
                             .setTotalPrice(".10")
                             .build())
                     .build())
             .build();
    return fullWalletRequest;
}


public void requestFullWallet(View view){
       if(mGoogleApiClient.isConnected()){
           Wallet.Payments.loadFullWallet(mGoogleApiClient,
                   generateFullWalletRequest(mMaskedWallet.getGoogleTransactionId()),
                   FULL_WALLET_REQUEST_CODE);
       }
}

@Override
public void onConnected(Bundle bundle) {

}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

}
}

希望这是使用全给你。

Hope this is use full for you.

这篇关于心动优惠到谷歌钱包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:02