|
|
@@ -1,9 +1,11 @@
|
|
|
import { LanguageCode } from '@vendure/common/lib/generated-types';
|
|
|
-import { Logger, PaymentMethodHandler } from '@vendure/core';
|
|
|
+import { Injector, Logger, PaymentMethodHandler } from '@vendure/core';
|
|
|
|
|
|
import { extractMetadataFromTransaction, getGateway } from './braintree-common';
|
|
|
-import { loggerCtx } from './constants';
|
|
|
+import { BRAINTREE_PLUGIN_OPTIONS, loggerCtx } from './constants';
|
|
|
+import { BraintreePluginOptions } from './types';
|
|
|
|
|
|
+let options: BraintreePluginOptions;
|
|
|
/**
|
|
|
* The handler for Braintree payments.
|
|
|
*/
|
|
|
@@ -12,12 +14,14 @@ export const braintreePaymentMethodHandler = new PaymentMethodHandler({
|
|
|
description: [{ languageCode: LanguageCode.en, value: 'Braintree payments' }],
|
|
|
args: {
|
|
|
merchantId: { type: 'string', label: [{ languageCode: LanguageCode.en, value: 'Merchant ID' }] },
|
|
|
- publicKey: { type: 'string', label: [{ languageCode: LanguageCode.en, value: 'Private Key' }] },
|
|
|
- privateKey: { type: 'string', label: [{ languageCode: LanguageCode.en, value: 'Public Key' }] },
|
|
|
+ publicKey: { type: 'string', label: [{ languageCode: LanguageCode.en, value: 'Public Key' }] },
|
|
|
+ privateKey: { type: 'string', label: [{ languageCode: LanguageCode.en, value: 'Private Key' }] },
|
|
|
+ },
|
|
|
+ init(injector: Injector) {
|
|
|
+ options = injector.get<BraintreePluginOptions>(BRAINTREE_PLUGIN_OPTIONS);
|
|
|
},
|
|
|
-
|
|
|
async createPayment(ctx, order, amount, args, metadata) {
|
|
|
- const gateway = getGateway(args);
|
|
|
+ const gateway = getGateway(args, options);
|
|
|
try {
|
|
|
const response = await gateway.transaction.sale({
|
|
|
amount: (amount / 100).toString(10),
|
|
|
@@ -61,7 +65,7 @@ export const braintreePaymentMethodHandler = new PaymentMethodHandler({
|
|
|
},
|
|
|
|
|
|
async createRefund(ctx, input, total, order, payment, args) {
|
|
|
- const gateway = getGateway(args);
|
|
|
+ const gateway = getGateway(args, options);
|
|
|
const response = await gateway.transaction.refund(payment.transactionId, (total / 100).toString(10));
|
|
|
if (!response.success) {
|
|
|
return {
|