これが私が尋ねている質問への序曲です: 私は自分の会社のために Python でゲートウェイに依存しない支払い API を構築することにしました。現時点では、Authorize.net をサポートするためのコードしか書いていないので、API 設計の明確さについて、私よりも少し経験が豊富な Python プログラマーからのフィードバックを求めていました。
存在する他のパッケージは後付けのように感じたり、Authorize.net 固有のものだったりするため、私は独自のパッケージを作成することを選択しました (よりクリーンなインターフェイスを備えたより一般的なパッケージを作成したいと考えています)。特にパッケージ ( pythorize ) からインスピレーションを得ましたが、それらの API は好きではありませんでした。
私が何をしているのかを説明する前に、パッケージの bitbucket のパブリック リポジトリへのリンクを次に示します: paypy (使用したい人への注意: コードは安定していますが、ドキュメントが大幅に不足しています)。
私の現在の戦略は、ネストされた辞書を使用し、それを支払い方法クラスのコンストラクターに渡すことです。Authorize.net CIM API で新しいユーザー プロファイルを作成する例:
>>> options = {'tran_key' : 'test_tran_key',
... 'login' : 'developer_login',
... 'testing' : True,
... 'validation': 'testMode',
... 'customer': {'description': 'Some description of the customer profile',
... 'id' : 22,
... 'email' : 'johnny_doe@gmail.com'},
... 'billing': [{'type': 'individual',
... 'profile': {'city' : 'Carlsbad',
... 'state' : 'California',
... 'zip' : '92009',
... 'firstname' : 'John',
... 'address' : '12 Alicante Rd. Suite 9',
... 'lastname' : 'Doe',
... 'country' : 'USA',
... 'phone' : '(858) 557-2674'},
... 'payment': {'card': {'ccv' : '524',
... 'number' : '4111111111111111',
... 'expiration' : '2014-04'}}},
... {'type' : 'individual',
... 'profile' : {'city' : 'Las Vegas',
... 'state' : 'Nevada',
... 'zip' : '79112',
... 'firstname' : 'John',
... 'address' : '78 Cloud Front',
... 'lastname' : 'Doe',
... 'country' : 'USA',
... 'phone' : '(858) 557-2674'},
... 'payment': {'card': {'ccv' : '499',
... 'number' : '4111111111111111',
... 'expiration' : '2012-11'}}},
... {'profile': {'city' : 'Carlsbad',
... 'state' : 'California',
... 'zip' : '92009',
... 'firstname' : 'John',
... 'address' : '12 Alicante Rd. Suite 9',
... 'lastname' : 'Doe',
... 'company' : 'Xmarks',
... 'country' : 'USA',
... 'phone' : '(858) 557-2674'},
... 'payment': {'bank': {'name_on_account' : 'John Doe',
... 'account' : '829330184383',
... 'type' : 'checking',
... 'name' : 'Bank of America',
... 'routing' : '122400724'}}}],
... 'shipping': [{'city' : 'Carlsbad',
... 'state' : 'California',
... 'zip' : '92009',
... 'firstname' : 'John',
... 'address' : '12 Alicante Rd. Suite 9',
... 'lastname' : 'Doe',
... 'country' : 'USA',
... 'phone' : '(858) 557-2674'}]}
>>> profile = Profile(options)
>>> result = profile.create()
>>> result.code
'I00001'
>>> print 'Customer Profile ID:' + str(result)
Customer Profile ID: 2758851
>>> print 'Customer Payment Profile IDs:' + repr(result.payment_ids)
Customer Payment Profile IDs: ['2380878', '2380879', '2380880']
>>> print 'Customer Shipping Profile IDs:' + repr(result.shipping_ids)
Customer Shipping Profile IDs: ['2427568']
>>>
>>>
>>> options = {'id' : str(result),
... 'tran_key' : '86U5pvA9TcxZ5b8D',
... 'testing' : True,
... 'login' : '5b3PhGX68'}
>>> profile = Profile(options)
>>> result = profile.remove()
>>> result.code
'I00001'
>>> ^D
結果オブジェクトにいくつかの魔法のメソッド ( strなど)を使用していることに気付くでしょう。私はその辞書戦略を AIM および ARB メソッドにも使用し、「オプション」を支払い API に伝える最も簡単な方法であると考えました。ある時点で、GoogleCheckout、Paypal などのアダプターがあるためです...
もう 1 つの考えは、辞書の代わりに記述子とオブジェクトを使用して、オプション データをアダプターに伝えることでした。
すべての支払いゲートウェイ API (特に PayPal と Authorize.net) と同様に、インターフェイスは少し乱雑になる傾向があり、標準化されていないため、ゲートウェイに依存するいくつかのオプションを避けるのは困難です。