Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Hitch Hiker's Guide to Android Pay

Tomoaki Imai
November 22, 2016

The Hitch Hiker's Guide to Android Pay

[Japanese] This slide is a guide for implementing Android Pay

Tomoaki Imai

November 22, 2016
Tweet

More Decks by Tomoaki Imai

Other Decks in Programming

Transcript

  1. Android Pay ֓ཁ • Google Accountʹܾࡁ৘ใΛඥ෇͚ • ొ࿥ޙ͸جຊతʹϫϯλοϓͰߪೖ ׬ྃͰ͖Δ •

    ܾࡁ৘ใΛ୺຤ʹอ࣋͠ͳ͍(Apple Pay͸ϩʔΧϧʹ҉߸Խͯ͠อଘ) • (ݱঢ়USͷΈ) ళฮܾࡁ΍Ϋʔϙϯػ ೳ౳΋ରԠ • Android OS 4.4Ҏ্
  2. ಋೖཁ݅ • Processor(ܾࡁ୅ߦձࣾ)͕ରԠ͍ͯ͠Δ • Mercariͷ৔߹͸Braintreeͱ͍͏Processorͱఏܞ͍ͯ͠Δ • play service SDK 9.0.0Ҏ্(9.0.0ҎԼͰ΋ରԠ͍ͯ͠Δ͕ɺProcessor͕ఏڙͯ͠

    ͍ΔSDKͱ੔߹ੑ͕औΕͳ͘ͳΔՄೳੑ͕͋Δ) compile “com.google.android.gms:play-services-base:9.0.0"
 compile "com.google.android.gms:play-services-wallet:9.0.0"
  3. Android Pay ಋೖεέδϡʔϧ • ։ൃ։࢝~ϩʔϯν·Ͱ໿3िؒ • ࣮૷ΑΓ΋UIݕ౼, ϑΟʔυόοΫରԠ͕͔͔࣌ؒͬͨ • αʔόʔαΠυʹ͍ͭͯ͸ɺApple

    Pay ͷ࢓૊Έ͕ྲྀ༻Ͱ͖ͨͷͰରԠͳ͠ "OESPJE1BZ"1*Λ࢖ͬͯ ࣮ࡍʹΞϓϦΛ࡞Δ%BZ )BDLBUIPO ͜͜ͰϓϩτλΠϓ࡞੒ Android Pay Hackathon week1 week2 Launch ࣮૷࣌ͷෆ໌఺͸(PPHMFࣾ ʹ໰͍߹Θͤ  "QLΛૹ෇  σβΠϯ͕ΨΠυϥΠϯʹ Ԋ͍ͬͯΔ͔  ڍಈʹ໰୊͸ͳ͍͔ ϓϩτλΠϓ ࢓༷σβΠϯ ࣮૷ςετ (PPHMFϨϏϡʔϑΟʔυόοΫରԠ ঎༻؀ڥͰͷ ར༻ͷղআ
  4. Android Pay ͷ࢓૊Έ ୺຤͕"OESPJE1BZʹରԠ͍ͯ͠Δ͔νΣοΫ 8BMMFU1BZNFOUTJT3FBEZ5P1BZ ܾࡁΛ͢Δͷʹඞཁͳ5PLFOΛ1SPDFTTPSʹϦΫΤετ AndroidPay.getTokenizationParameters(braintreeFragment, (parameters, allowedCardNetworks) ->

    {…}); 5PLFOΛݩʹ.BTLFE8BMMFUΛੜ੒ ॅॴ৘ใɺӅṭ͞ΕͨΫϨΧ৘ใ౳ؚ͕·ΕΔ Wallet.Payments.loadMaskedWallet(googleApiClient, maskedWalletRequest, requestCode); .BTLFE8BMMFU͔Β'VMM8BMMFUΛੜ੒ ΫϨΧܾࡁͷͨΊʹඞཁͳτʔΫϯ৘ใ͕͋Δ Wallet.Payments.loadFullWallet(googleApiClient, fullWalletRequest, REQUEST_FULL_WALLET); τʔΫϯ৘ใΛݩʹܾࡁΛߦ͏ AndroidPay.tokenize(braintreeFragment, fullWallet); Processor Google Server Client
  5. Masked Wallet? Full Wallet? • MaskedWallet, Full Walletͷ໾ׂ • MaskedWallet͸ܾࡁલʹϢʔβʔఏࣔʹඞཁͳ৘ใ(ActivityؒͰ࢖͍·Θ͠OK)

    • FullWallet͸ܾࡁ࣌ʹඞཁͳ৘ใ(Ұ౓͖Γɺຖ౓MaskedWallet͔Βੜ੒) public MaskedWalletRequest createMaskedWalletRequest(PaymentMethodTokenizationParameters parameters,
 Collection<Integer> allowedCardNetworks, int finalPaymentPrice){
 Cart cart = Cart.newBuilder().setCurrencyCode(Const.CURRENCY_USD)
 .setTotalPrice(finalPaymentPrice).build(); /
 return MaskedWalletRequest.newBuilder()
 .setPaymentMethodTokenizationParameters(parameters)
 .addAllowedCardNetworks(allowedCardNetworks)
 .setMerchantName(Const.MERCHANT_NAME)
 .setCurrencyCode(Const.CURRENCY_USD)
 .setEstimatedTotalPrice(cart.getTotalPrice())
 .setCart(cart)
 .setShippingAddressRequired(true)
 .build();
 } • Ͳ͏͍͏৘ใΛͦΕͧΕͷλΠϛϯάͰGoogleଆʹૹΕ͹ྑ͍͔Θ͔Βͳ͍ • ౎౓ૹΕ͹ྑ͍৘ใΛ֬ೝ
  6. ݕূ͕େม • ରԠ͢ΔΫϨδοτΧʔυ͕खݩʹඞཁ ‣ ProcessorʹΑͬͯ͸ςετΧʔυ͕ར༻Ͱ͖ͳ͍ ‣ ࣗલͷΧʔυ࢖͏ -> ొ࿥੍ݶʹҾ͔͔ͬͬͯΧʔυఀࢭ •

    ঎༻؀ڥͰͷݕূ͸GoogleͷApproveΛड͚͔ͯΒ(ͭ·Γϩʔϯν௚લ) • PreAuthorize(Ұ౓ར༻ͨ͠৔߹ʹͦͷೝূΛ࠶ར༻ग़དྷΔػೳ)Λoffʹ͢Δ৔ ߹ʹ͸ app ͷstorekeyΛม͑Δඞཁ͕͋Δ
  7. ProcessorʹΑ࣮ͬͯ૷ҟͳΔ • Processor֤ࣾʹΑ࣮ͬͯ૷ͷํ๏͕ҟͳΔ • Processor͕มΘΔͱશͯมΘΔՄೳੑ͕͋Δ mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) .enableAutoManage(fragmentActivity,

    this /* onConnectionFailedListener */) .setAccountName(accountName) // optional .addApi(Wallet.API, new Wallet.WalletOptions.Builder() .setEnvironment(Constants.WALLET_ENVIRONMENT) .setTheme(WalletConstants.THEME_LIGHT) .build()) .build(); Wallet.Payments.loadFullWallet(mGoogleApiClient, fullWalletRequest, REQUEST_CODE_RESOLVE_LOAD_FULL_WALLET); braintreeFragment.getGoogleApiClient(googleApiClient ->
 Wallet.Payments.loadFullWallet(googleApiClient, fullWalletRequest, REQUEST_FULL_WALLET)); Braintree Stripe